Skip to content

Commit

Permalink
Add proto_repository.apparent_name attr
Browse files Browse the repository at this point in the history
  • Loading branch information
pcj committed Jul 1, 2024
1 parent faf94ca commit 1488c51
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
7 changes: 7 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ proto_gazelle(
],
)

genrule(
name = "imports_csv",
outs = ["imports.csv"],
cmd = "cp $(location @protobufapis//:imports.csv) $@",
tools = ["@protobufapis//:imports.csv"],
)

gazelle(
name = "update_go_deps",
args = [
Expand Down
4 changes: 2 additions & 2 deletions example/routeguide/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ grpc_java_library(
visibility = ["//visibility:public"],
exports = [
":routeguide_java_library",
"@io_grpc_grpc_java//api",
"@io_grpc_grpc_java//context",
"@io_grpc_grpc_java//protobuf",
"@io_grpc_grpc_java//stub",
"@io_grpc_grpc_java//stub:javax_annotation",
"@maven//:com_google_guava_guava",
],
deps = [
":routeguide_java_library",
"@io_grpc_grpc_java//api",
"@io_grpc_grpc_java//context",
"@io_grpc_grpc_java//protobuf",
"@io_grpc_grpc_java//stub",
"@io_grpc_grpc_java//stub:javax_annotation",
Expand Down
8 changes: 6 additions & 2 deletions extensions/proto_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ def _proto_repository_impl(module_ctx):
named_archives[tag.name] = kwargs

# declare a repository rule foreach one
for _, kwargs in named_archives.items():
proto_repository_repo_rule(**kwargs)
for apparent_name, kwargs in named_archives.items():
proto_repository_repo_rule(
apparent_name = apparent_name,
**kwargs
)

return _extension_metadata(
module_ctx,
Expand All @@ -74,6 +77,7 @@ _proto_repository_archive_attrs = proto_repository_attrs | {
mandatory = True,
),
}
_proto_repository_archive_attrs.pop("apparent_name")

proto_repository = module_extension(
implementation = _proto_repository_impl,
Expand Down
1 change: 0 additions & 1 deletion rules/private/proto_repository_tools_srcs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ PROTO_REPOSITORY_TOOLS_SRCS = [
"@build_stack_rules_proto//plugin/grpc/grpc-java:BUILD.bazel",
"@build_stack_rules_proto//plugin/grpc/grpc-node:BUILD.bazel",
"@build_stack_rules_proto//plugin/grpc/grpc-web:BUILD.bazel",
"@build_stack_rules_proto//plugin/grpc-ecosystem/grpc-gateway:BUILD.bazel",
"@build_stack_rules_proto//plugin/scalapb/scalapb:BUILD.bazel",
"@build_stack_rules_proto//plugin/stackb/grpc_js:BUILD.bazel",
"@build_stack_rules_proto//plugin/stephenh/ts-proto:BUILD.bazel",
Expand Down
14 changes: 10 additions & 4 deletions rules/proto/proto_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def _proto_repository_impl(ctx):
"-repo_config",
ctx.path(ctx.attr.build_config),
"-proto_repo_name",
ctx.name,
ctx.attr.apparent_name,
]
if ctx.attr.version:
cmd.append("-go_repository_module_mode")
Expand Down Expand Up @@ -269,12 +269,16 @@ def _proto_repository_impl(ctx):
))
if result.stderr:
# buildifier: disable=print
print("%s: %s" % (ctx.name, result.stderr))
print("[ctx.name=%s]: %s" % (ctx.name, result.stderr))

# Apply patches if necessary.
patch(ctx)

proto_repository_attrs = {
"apparent_name": attr.string(
doc = "the apparent name of the repository (repository_ctx.name provides the canonical one)",
mandatory = True,
),
# Fundamental attributes of a go repository
"importpath": attr.string(mandatory = False), # True in go_repository

Expand Down Expand Up @@ -374,16 +378,18 @@ proto_repository_attrs = {
"reresolve_known_proto_imports": attr.bool(),
}

go_repository = repository_rule(
protobuf_go_repository = repository_rule(
implementation = _proto_repository_impl,
attrs = proto_repository_attrs,
)

def proto_repository(**kwargs):
name = kwargs.get("name")
kwargs.setdefault("apparent_name", name)
kwargs.setdefault("languages", ["proto", "protobuf"])
kwargs.setdefault("build_file_expunge", True)
kwargs.setdefault("build_file_generation", "on")
go_repository(**kwargs)
protobuf_go_repository(**kwargs)

# Copied from @bazel_tools//tools/build_defs/repo:utils.bzl
def patch(ctx):
Expand Down

0 comments on commit 1488c51

Please sign in to comment.