Skip to content

Commit

Permalink
Fix tests and update to rules_proto 6.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed May 8, 2024
1 parent a6056ef commit 84547b5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 104 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
18 changes: 9 additions & 9 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand All @@ -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")
Expand All @@ -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")
Expand Down
48 changes: 3 additions & 45 deletions tests/core/cross/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
Expand Down
69 changes: 20 additions & 49 deletions tests/core/transition/hermeticity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
`,
})
}
Expand All @@ -174,28 +133,33 @@ 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) {
assertDependsCleanlyOnWithFlags(
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",
Expand All @@ -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...)...)
Expand All @@ -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 {
Expand Down

0 comments on commit 84547b5

Please sign in to comment.