Skip to content

Commit a78c49d

Browse files
authored
proto_repository: add attributes to write a proto_repository_info provider (stackb#328)
* Use non-zip archive for @protoapis dep * Add proto_repository_info provider, rule, and github_proto_repository macro * Upgrade to rules_go 0.39.1 * Bump minimum bazel version to 5.4.0 * Add test for ProtoRepositoryInfo provider * Bump bazelci version
1 parent 361cff2 commit a78c49d

File tree

17 files changed

+197
-71
lines changed

17 files changed

+197
-71
lines changed

.bazelci/presubmit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
buildifier:
33
version: 5.1.0
44
warnings: "-function-docstring,-function-docstring-header,-module-docstring,-function-docstring-args,-list-append"
5-
bazel: 5.1.1
5+
bazel: 5.4.0
66
tasks:
77
default_workspace_ubuntu1804:
88
platform: ubuntu1804

.bazelrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ build:bazelci --deleted_packages=docs
1313

1414
# workaround for scala
1515
build --incompatible_java_common_parameters=false
16-

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.1.1
1+
5.4.0

deps/BUILD.bazel

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,17 @@ depsgen(
9797
deps = ["//deps:io_grpc_grpc_java"],
9898
)
9999

100-
# Release: v0.35.0
101-
# TargetCommitish: release-0.35
102-
# Date: 2022-09-11 15:59:49 +0000 UTC
103-
# URL: https://github.com/bazelbuild/rules_go/releases/tag/v0.35.0
104-
# Size: 931734 (932 kB)
100+
# Release: v0.39.1
101+
# TargetCommitish: release-0.39
102+
# Date: 2023-04-20 04:35:08 +0000 UTC
103+
# URL: https://github.com/bazelbuild/rules_go/releases/tag/v0.39.1
104+
# Size: 1759832 (1.8 MB)
105105
proto_dependency(
106106
name = "io_bazel_rules_go",
107107
repository_rule = "http_archive",
108-
sha256 = "cc027f11f98aef8bc52c472ced0714994507a16ccd3a0820b2df2d6db695facd",
109-
strip_prefix = "rules_go-0.35.0",
110-
urls = ["https://github.com/bazelbuild/rules_go/archive/v0.35.0.tar.gz"],
108+
sha256 = "473a064d502e89d11c497a59f9717d1846e01515a3210bd169f22323161c076e",
109+
strip_prefix = "rules_go-0.39.1",
110+
urls = ["https://github.com/bazelbuild/rules_go/archive/v0.39.1.tar.gz"],
111111
visibility = ["//visibility:public"],
112112
)
113113

deps/core_deps.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ def io_bazel_rules_go():
1919
_maybe(
2020
http_archive,
2121
name = "io_bazel_rules_go",
22-
sha256 = "cc027f11f98aef8bc52c472ced0714994507a16ccd3a0820b2df2d6db695facd",
23-
strip_prefix = "rules_go-0.35.0",
22+
sha256 = "473a064d502e89d11c497a59f9717d1846e01515a3210bd169f22323161c076e",
23+
strip_prefix = "rules_go-0.39.1",
2424
urls = [
25-
"https://github.com/bazelbuild/rules_go/archive/v0.35.0.tar.gz",
25+
"https://github.com/bazelbuild/rules_go/archive/v0.39.1.tar.gz",
2626
],
2727
)
2828

example/golden/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ func TestRunGazelle(t *testing.T) {
109109
if err := bazel_testing.RunBazel("build", "..."); err != nil {
110110
t.Fatal(err)
111111
}
112+
if err := bazel_testing.RunBazel("test", "..."); err != nil {
113+
t.Fatal(err)
114+
}
112115
}
113116
""",
114117
strip_prefix = "example/golden/testdata/proto_repository",

example/golden/testdata/proto_repository/BUILD.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
33
load("@build_stack_rules_proto//rules:proto_gazelle.bzl", "DEFAULT_LANGUAGES", "proto_gazelle")
4+
load("//:proto_repository_info_test.bzl", "proto_repository_info_test")
45

56
# gazelle:prefix github.com/corp/repo
67
# gazelle:go_generate_proto false
@@ -19,4 +20,14 @@ proto_gazelle(
1920
imports = ["@googleapis//:imports.csv"],
2021
)
2122

23+
proto_repository_info_test(
24+
name = "proto_repository_info_test",
25+
info = "@googleapis//:proto_repository",
26+
want_source_host = "github.com",
27+
want_source_owner = "googleapis",
28+
want_source_repo = "googleapis",
29+
want_source_commit = "66759bdf6a5ebb898c2a51c8649aefd1ee0b7ffe",
30+
want_source_prefix = "",
31+
)
32+
2233
exports_files(["config.yaml"])

example/golden/testdata/proto_repository/BUILD.out

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
load("@bazel_gazelle//:def.bzl", "gazelle_binary")
33
load("@build_stack_rules_proto//rules:proto_gazelle.bzl", "DEFAULT_LANGUAGES", "proto_gazelle")
4+
load("//:proto_repository_info_test.bzl", "proto_repository_info_test")
45

56
# gazelle:prefix github.com/corp/repo
67
# gazelle:go_generate_proto false
@@ -19,4 +20,14 @@ proto_gazelle(
1920
imports = ["@googleapis//:imports.csv"],
2021
)
2122

23+
proto_repository_info_test(
24+
name = "proto_repository_info_test",
25+
info = "@googleapis//:proto_repository",
26+
want_source_commit = "66759bdf6a5ebb898c2a51c8649aefd1ee0b7ffe",
27+
want_source_host = "github.com",
28+
want_source_owner = "googleapis",
29+
want_source_prefix = "",
30+
want_source_repo = "googleapis",
31+
)
32+
2233
exports_files(["config.yaml"])

example/golden/testdata/proto_repository/WORKSPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ proto_repository(
2020
cfgs = ["//:config.yaml"],
2121
reresolve_known_proto_imports = True,
2222
sha256 = "b9dbc65ebc738a486265ef7b708e9449bf361541890091983e946557ee0a4bfc",
23+
source_commit = "66759bdf6a5ebb898c2a51c8649aefd1ee0b7ffe",
24+
source_owner = "googleapis",
25+
source_repo = "googleapis",
2326
strip_prefix = "googleapis-66759bdf6a5ebb898c2a51c8649aefd1ee0b7ffe",
2427
type = "zip",
2528
urls = ["https://codeload.github.com/googleapis/googleapis/zip/66759bdf6a5ebb898c2a51c8649aefd1ee0b7ffe"],
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
load("@build_stack_rules_proto//rules:providers.bzl", "ProtoRepositoryInfo")
2+
3+
def _proto_repository_info_test_impl(ctx):
4+
info = ctx.attr.info[ProtoRepositoryInfo]
5+
6+
must_attr(info, ctx.attr, "source_host")
7+
must_attr(info, ctx.attr, "source_owner")
8+
must_attr(info, ctx.attr, "source_repo")
9+
must_attr(info, ctx.attr, "source_commit")
10+
must_attr(info, ctx.attr, "source_prefix")
11+
12+
ctx.actions.write(ctx.outputs.json, info.to_json())
13+
14+
# we're checking attr values in the provider, so the script really does not
15+
# need to do anything
16+
ctx.actions.write(ctx.outputs.executable, "echo PASS")
17+
18+
return [DefaultInfo(
19+
files = depset([ctx.outputs.json, ctx.outputs.executable]),
20+
)]
21+
22+
proto_repository_info_test = rule(
23+
implementation = _proto_repository_info_test_impl,
24+
attrs = {
25+
"info": attr.label(
26+
providers = [ProtoRepositoryInfo],
27+
mandatory = True,
28+
),
29+
"want_source_host": attr.string(),
30+
"want_source_owner": attr.string(),
31+
"want_source_repo": attr.string(),
32+
"want_source_commit": attr.string(),
33+
"want_source_prefix": attr.string(),
34+
},
35+
outputs = {
36+
"json": "%{name}.json",
37+
},
38+
test = True,
39+
)
40+
41+
def must_attr(info, attr, name):
42+
got = getattr(info, name)
43+
want = getattr(attr, "want_" + name)
44+
if got != want:
45+
fail(".%s: want %s, got %s" % (name, want, got))

0 commit comments

Comments
 (0)