Skip to content

Commit

Permalink
chore: re-work Bazel build to accommodate Maven setup (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
chanseokoh authored Feb 18, 2022
1 parent 2a3df94 commit 55cc23e
Show file tree
Hide file tree
Showing 19 changed files with 666 additions and 42 deletions.
51 changes: 38 additions & 13 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,24 @@ TEST_DEPS = [
"@io_github_java_diff_utils//jar",
]

proto_library(
name = "service_config_proto",
srcs = ["src/main/proto/service_config.proto"],
deps = [
"@com_google_googleapis//google/rpc:code_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:wrappers_proto",
"@com_google_protobuf//:struct_proto",
],
)
java_proto_library(
name = "service_config_java_proto",
deps = ["@io_grpc_proto//:service_config_proto"],
deps = [":service_config_proto"],
)

proto_library(
name = "test_protos",
srcs = glob(["src/test/resources/*.proto"]),
srcs = glob(["src/test/proto/*.proto"]),
deps = [
"@com_google_googleapis//google/api:annotations_proto",
"@com_google_googleapis//google/api:client_proto",
Expand Down Expand Up @@ -85,14 +95,25 @@ java_plugin(
deps = ["@com_google_auto_value_auto_value//jar"],
)

java_binary(
name = "protoc-gen-java_gapic",
java_library(
name = "gapic_generator_java",
srcs = glob(["src/main/java/**/*.java"]),
main_class = "com.google.api.generator.Main",
plugins = [":autovalue_plugin"],
deps = MAIN_DEPS,
)

java_library(
name = "gapic_generator_java_test",
srcs = glob(["src/test/java/**/*.java"]),
deps = [":gapic_generator_java"] + MAIN_DEPS + TEST_DEPS,
)

java_binary(
name = "protoc-gen-java_gapic",
main_class = "com.google.api.generator.Main",
runtime_deps = [":gapic_generator_java"] + MAIN_DEPS,
)

# Request dumper binary, which dumps the CodeGeneratorRequest to a file on disk
# which will be identical to the one passed to the protoc-gen-java_gapic during
# normal execution. The dumped file then can be used to run this gapic-generator
Expand All @@ -112,7 +133,7 @@ java_binary(
java_binary(
name = "protoc-gen-code_generator_request_dumper",
main_class = "com.google.api.generator.debug.CodeGeneratorRequestDumper",
runtime_deps = [":protoc-gen-java_gapic"] + MAIN_DEPS + MAIN_DEPS_DEBUG_RUNTIME_ONLY,
runtime_deps = [":gapic_generator_java"] + MAIN_DEPS + MAIN_DEPS_DEBUG_RUNTIME_ONLY,
)

# A binary similar to protoc-gen-java_gapic but reads the CodeGeneratorRequest
Expand All @@ -125,14 +146,14 @@ java_binary(
java_binary(
name = "code_generator_request_file_to_gapic_main",
main_class = "com.google.api.generator.debug.CodeGeneratorRequestFileToGapicMain",
runtime_deps = [":protoc-gen-java_gapic"] + MAIN_DEPS + MAIN_DEPS_DEBUG_RUNTIME_ONLY,
runtime_deps = [":gapic_generator_java"] + MAIN_DEPS + MAIN_DEPS_DEBUG_RUNTIME_ONLY,
)

# another test resource
genrule(
name = "basic_proto_descriptor",
srcs = ["src/test/resources/basic.proto"],
outs = ["basic_proto.descriptor"],
srcs = ["src/test/proto/basic.proto"],
outs = ["test-proto.descriptorset"],
cmd = "$(location @com_google_protobuf//:protoc) " +
"--include_source_info --include_imports --descriptor_set_out=$(OUTS) $(SRCS)",
message = "Generating proto descriptor",
Expand All @@ -143,9 +164,11 @@ genrule(
# bazel test //:unit_com_google_api_generator_engine_JavaCodeGeneratorTest
[java_test(
name = "unit_" + file[14:-5].replace('/', '_'),
srcs = glob(["src/test/java/**/*.java"]),
test_class = file[14:-5].replace('/', '.'),
deps = [":protoc-gen-java_gapic"] + MAIN_DEPS + TEST_DEPS,
runtime_deps = [
":gapic_generator_java",
":gapic_generator_java_test",
] + MAIN_DEPS + TEST_DEPS,
data = [":basic_proto_descriptor"] + glob([
"src/test/java/**/*.golden",
"src/test/resources/**",
Expand Down Expand Up @@ -182,10 +205,12 @@ GOLDEN_UPDATING_UNIT_TESTS = [
# bazel run //:update_com_google_api_generator_engine_JavaCodeGeneratorTest
[java_binary(
name = "update_%s" % test_class.replace('.', '_'),
srcs = glob(["src/test/java/**/*.java"]),
main_class = "com.google.api.generator.test.framework.SingleJUnitTestRunner",
args = [test_class],
deps = [":protoc-gen-java_gapic"] + MAIN_DEPS + TEST_DEPS,
runtime_deps = [
":gapic_generator_java",
":gapic_generator_java-test",
] + MAIN_DEPS + TEST_DEPS,
data = glob([
"src/test/java/**/*.golden",
"src/test/resources/**",
Expand Down
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
java_proto_library(
name = "showcase_java_proto",
deps = [
"showcase_proto",
":showcase_proto",
],
)
Expand Down
9 changes: 0 additions & 9 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,6 @@ def gapic_generator_java_repositories():
actual = "@com_google_code_gson_gson//jar",
)

# grpc-proto doesn't have releases, so we use hashes instead.
_io_grpc_proto_prefix = "8e3fec8612bc0708e857950dccadfd5063703e04" # Nov. 6, 2021.
_maybe(
http_archive,
name = "io_grpc_proto",
urls = ["https://github.com/grpc/grpc-proto/archive/%s.zip" % _io_grpc_proto_prefix],
strip_prefix = "grpc-proto-%s" % _io_grpc_proto_prefix,
)

def _maybe(repo_rule, name, strip_repo_prefix = "", **kwargs):
if not name.startswith(strip_repo_prefix):
return
Expand Down
Loading

0 comments on commit 55cc23e

Please sign in to comment.