From 84547b541f321e932c91b93324d9e7c0d7bd769e Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Tue, 7 May 2024 14:08:43 +0200 Subject: [PATCH] Fix tests and update to rules_proto 6.0.0 --- MODULE.bazel | 2 +- WORKSPACE | 18 +++--- tests/core/cross/proto_test.go | 48 +--------------- tests/core/transition/hermeticity_test.go | 69 +++++++---------------- 4 files changed, 33 insertions(+), 104 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index b1df1e69c..34e72c7f3 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -10,7 +10,7 @@ module( bazel_dep(name = "bazel_features", version = "1.9.1", repo_name = "io_bazel_rules_go_bazel_features") bazel_dep(name = "bazel_skylib", version = "1.2.0") bazel_dep(name = "platforms", version = "0.0.4") -bazel_dep(name = "rules_proto", version = "6.0.0-rc2") +bazel_dep(name = "rules_proto", version = "6.0.0") bazel_dep(name = "protobuf", version = "3.19.2", repo_name = "com_google_protobuf") go_sdk = use_extension("//go:extensions.bzl", "go_sdk") diff --git a/WORKSPACE b/WORKSPACE index 2729c5678..67f537e59 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -6,10 +6,10 @@ load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_depe # Required by toolchains_protoc. http_archive( name = "platforms", - sha256 = "5eda539c841265031c2f82d8ae7a3a6490bd62176e0c038fc469eabf91f6149b", + sha256 = "218efe8ee736d26a3572663b374a253c012b716d8af0c07e842e82f238a0a7ee", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.9/platforms-0.0.9.tar.gz", - "https://github.com/bazelbuild/platforms/releases/download/0.0.9/platforms-0.0.9.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", + "https://github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", ], ) @@ -31,9 +31,9 @@ go_register_toolchains(version = "1.21.8") http_archive( name = "rules_proto", - sha256 = "71fdbed00a0709521ad212058c60d13997b922a5d01dbfd997f0d57d689e7b67", - strip_prefix = "rules_proto-6.0.0-rc2", - url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.0-rc2/rules_proto-6.0.0-rc2.tar.gz", + sha256 = "303e86e722a520f6f326a50b41cfc16b98fe6d1955ce46642a5b7a67c11c0f5d", + strip_prefix = "rules_proto-6.0.0", + url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.0/rules_proto-6.0.0.tar.gz", ) load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies") @@ -46,9 +46,9 @@ rules_proto_toolchains() http_archive( name = "toolchains_protoc", - sha256 = "b312e6de6485e01f753cb87fa09b4193f1762593141790dd0a90abf5e520b1d7", - strip_prefix = "toolchains_protoc-0.2.1", - url = "https://github.com/alexeagle/toolchains_protoc/releases/download/v0.2.1/toolchains_protoc-v0.2.1.tar.gz", + sha256 = "1f3cd768bbb92164952301228bac5e5079743843488598f2b17fecd41163cadb", + strip_prefix = "toolchains_protoc-0.2.4", + url = "https://github.com/aspect-build/toolchains_protoc/releases/download/v0.2.4/toolchains_protoc-v0.2.4.tar.gz", ) load("@toolchains_protoc//protoc:toolchain.bzl", "protoc_toolchains") diff --git a/tests/core/cross/proto_test.go b/tests/core/cross/proto_test.go index a9899e317..45c4410f9 100644 --- a/tests/core/cross/proto_test.go +++ b/tests/core/cross/proto_test.go @@ -21,51 +21,9 @@ import ( ) var testArgs = bazel_testing.Args{ - WorkspacePrefix: ` -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -# The non-polyfill version of this is needed by rules_proto below. -http_archive( - name = "bazel_features", - sha256 = "d7787da289a7fb497352211ad200ec9f698822a9e0757a4976fd9f713ff372b3", - strip_prefix = "bazel_features-1.9.1", - url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.9.1/bazel_features-v1.9.1.tar.gz", -) - -load("@bazel_features//:deps.bzl", "bazel_features_deps") - -bazel_features_deps() -`, - WorkspaceSuffix: ` -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "com_google_protobuf", - sha256 = "75be42bd736f4df6d702a0e4e4d30de9ee40eac024c4b845d17ae4cc831fe4ae", - strip_prefix = "protobuf-21.7", - # latest available in BCR, as of 2022-09-30 - urls = [ - "https://github.com/protocolbuffers/protobuf/archive/v21.7.tar.gz", - "https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v21.7.tar.gz", - ], -) - -load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") - -protobuf_deps() - -http_archive( - name = "rules_proto", - sha256 = "71fdbed00a0709521ad212058c60d13997b922a5d01dbfd997f0d57d689e7b67", - strip_prefix = "rules_proto-6.0.0-rc2", - url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.0-rc2/rules_proto-6.0.0-rc2.tar.gz", -) - -load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies") -rules_proto_dependencies() - -load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains") -rules_proto_toolchains() + ModuleFileSuffix: ` +bazel_dep(name = "rules_proto", version = "6.0.0") +bazel_dep(name = "toolchains_protoc", version = "0.2.4") `, Main: ` -- BUILD.bazel -- diff --git a/tests/core/transition/hermeticity_test.go b/tests/core/transition/hermeticity_test.go index a0ca186fd..b4194e37c 100644 --- a/tests/core/transition/hermeticity_test.go +++ b/tests/core/transition/hermeticity_test.go @@ -121,51 +121,10 @@ message Foo { int64 value = 1; } `, - WorkspacePrefix: ` -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -# The non-polyfill version of this is needed by rules_proto below. -http_archive( - name = "bazel_features", - sha256 = "d7787da289a7fb497352211ad200ec9f698822a9e0757a4976fd9f713ff372b3", - strip_prefix = "bazel_features-1.9.1", - url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.9.1/bazel_features-v1.9.1.tar.gz", -) - -load("@bazel_features//:deps.bzl", "bazel_features_deps") - -bazel_features_deps() -`, - WorkspaceSuffix: ` -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "com_google_protobuf", - sha256 = "75be42bd736f4df6d702a0e4e4d30de9ee40eac024c4b845d17ae4cc831fe4ae", - strip_prefix = "protobuf-21.7", - # latest available in BCR, as of 2022-09-30 - urls = [ - "https://github.com/protocolbuffers/protobuf/archive/v21.7.tar.gz", - "https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v21.7.tar.gz", - ], -) - -load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") - -protobuf_deps() - -http_archive( - name = "rules_proto", - sha256 = "71fdbed00a0709521ad212058c60d13997b922a5d01dbfd997f0d57d689e7b67", - strip_prefix = "rules_proto-6.0.0-rc2", - url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.0-rc2/rules_proto-6.0.0-rc2.tar.gz", -) - -load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies") -rules_proto_dependencies() - -load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains") -rules_proto_toolchains() + ModuleFileSuffix: ` +bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf") +bazel_dep(name = "rules_proto", version = "6.0.0") +bazel_dep(name = "toolchains_protoc", version = "0.2.4") `, }) } @@ -174,21 +133,24 @@ func TestGoBinaryNonGoAttrsAreReset(t *testing.T) { assertDependsCleanlyOnWithFlags( t, "//:main", - "//:helper") + "//:helper", + false) } func TestGoLibraryNonGoAttrsAreReset(t *testing.T) { assertDependsCleanlyOnWithFlags( t, "//:main", - "//:indirect_helper") + "//:indirect_helper", + false) } func TestGoTestNonGoAttrsAreReset(t *testing.T) { assertDependsCleanlyOnWithFlags( t, "//:main_test", - "//:helper") + "//:helper", + false) } func TestGoProtoLibraryToolAttrsAreReset(t *testing.T) { @@ -196,6 +158,8 @@ func TestGoProtoLibraryToolAttrsAreReset(t *testing.T) { t, "//:foo_go_proto", "@com_google_protobuf//:protoc", + // No dep with --incompatible_enable_proto_toolchain_resolution. + true, "--@io_bazel_rules_go//go/config:static", "--@io_bazel_rules_go//go/config:msan", "--@io_bazel_rules_go//go/config:race", @@ -207,11 +171,12 @@ func TestGoProtoLibraryToolAttrsAreReset(t *testing.T) { t, "//:foo_go_proto", "@com_google_protobuf//:protoc", + true, "--@io_bazel_rules_go//go/config:pure", ) } -func assertDependsCleanlyOnWithFlags(t *testing.T, targetA, targetB string, flags ...string) { +func assertDependsCleanlyOnWithFlags(t *testing.T, targetA, targetB string, allowNoDep bool, flags ...string) { // Analyze the targets to ensure that MODULE.bazel.lock has been created, otherwise bazel config // will fail after the cquery command due to the Skyframe invalidation caused by a changed file. err := bazel_testing.RunBazel(append([]string{"build", targetA, targetB, "--nobuild"}, flags...)...) @@ -234,6 +199,12 @@ func assertDependsCleanlyOnWithFlags(t *testing.T, targetA, targetB string, flag } cqueryOut := bytes.TrimSpace(out) configHashes := extractConfigHashes(t, cqueryOut) + if len(configHashes) == 0 { + if allowNoDep { + return + } + t.Fatalf("%s does not depend on %s", targetA, targetB) + } if len(configHashes) != 1 { differingGoOptions := getGoOptions(t, configHashes...) if len(differingGoOptions) != 0 {