diff --git a/BUILD.bazel b/BUILD.bazel index 7574fb74b9..6b95642180 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -16,75 +16,6 @@ TEST_SRCS = [ ] # ============= Proto wrappers ================= -java_proto_library( - name = "annotations_java_proto", - visibility = ["//:__subpackages__"], - deps = [ - "@com_google_googleapis//google/api:annotations_proto", - ], -) - -java_proto_library( - name = "client_java_proto", - visibility = [ - "//src/main/java/com/google/api/generator:__subpackages__", - "//src/test/java/com/google/api/generator:__subpackages__", - ], - deps = [ - "@com_google_googleapis//google/api:client_proto", - ], -) - -java_proto_library( - name = "field_behavior_java_proto", - visibility = [ - "//src/main/java/com/google/api/generator:__subpackages__", - "//src/test/java/com/google/api/generator:__subpackages__", - ], - deps = [ - "@com_google_googleapis//google/api:field_behavior_proto", - ], -) - -java_proto_library( - name = "resource_java_proto", - visibility = [ - "//src/main/java/com/google/api/generator:__subpackages__", - "//src/test/java/com/google/api/generator:__subpackages__", - ], - deps = [ - "@com_google_googleapis//google/api:resource_proto", - ], -) - -java_proto_library( - name = "longrunning_java_proto", - visibility = [ - "//src/main/java/com/google/api/generator:__subpackages__", - "//src/test/java/com/google/api/generator:__subpackages__", - ], - deps = [ - "@com_google_googleapis//google/longrunning:operations_proto", - ], -) - -java_proto_library( - name = "monitored_resource_java_proto", - visibility = ["//:__subpackages__"], - deps = [ - "@com_google_googleapis//google/api:monitored_resource_proto", - ], -) - -java_proto_library( - name = "rpc_java_proto", - visibility = ["//:__subpackages__"], - deps = [ - "@com_google_googleapis//google/rpc:code_proto", - "@com_google_googleapis//google/rpc:error_details_proto", - "@com_google_googleapis//google/rpc:status_proto", - ], -) java_proto_library( name = "service_config_java_proto", @@ -103,13 +34,10 @@ java_binary( ], main_class = "com.google.api.generator.Main", deps = [ - ":annotations_java_proto", - ":client_java_proto", - ":field_behavior_java_proto", - ":longrunning_java_proto", - ":resource_java_proto", "//src/main/java/com/google/api/generator", "//src/main/java/com/google/api/generator/gapic", + "@com_google_googleapis//google/api:api_java_proto", + "@com_google_googleapis//google/longrunning:longrunning_java_proto", "@com_google_guava_guava", "@com_google_protobuf//:protobuf_java", ], diff --git a/WORKSPACE b/WORKSPACE index 9dc131d2f1..162b2b5777 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,4 +1,4 @@ -workspace(name = "com_google_api_codegen") +workspace(name = "com_google_api_generator") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") @@ -14,36 +14,63 @@ http_archive( ], ) -load("//:repository_rules.bzl", "com_google_api_codegen_properties") +load("//:repository_rules.bzl", "com_google_api_generator_properties") -com_google_api_codegen_properties( - name = "com_google_api_codegen_properties", +com_google_api_generator_properties( + name = "com_google_api_generator_properties", file = "//:dependencies.properties", ) -load("//:repositories.bzl", "com_google_api_codegen_repositories") +load("//:repositories.bzl", "com_google_api_generator_repositories") -com_google_api_codegen_repositories() +com_google_api_generator_repositories() # protobuf load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") protobuf_deps() -# gRPC. -load("@io_grpc_java//:repositories.bzl", "grpc_java_repositories") - -grpc_java_repositories() - -# Resource names plugin. -load( - "@com_google_protoc_java_resource_names_plugin//:repositories.bzl", - "com_google_protoc_java_resource_names_plugin_repositories", +# Java dependencies. +# Import the monolith so we can transitively use its gapic rules for googleapis. +http_archive( + name = "com_google_api_codegen", + strip_prefix = "gapic-generator-2.4.6", + urls = ["https://github.com/googleapis/gapic-generator/archive/v2.4.6.zip"], ) + load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language") switched_rules_by_language( name = "com_google_googleapis_imports", + gapic = True, + grpc = True, + java = True, +) + +# TODO(miraleung): When the gax-java Bazel build PRs are submitted, do the following: +# - Rename the next rule. +# - Use these rules in build files: +# - "@com_google_api_gax_java//gax", +# - "@com_google_api_gax_java//gax-grpc:gax_grpc", +_gax_java_version = "1.58.2" + +http_archive( + name = "com_google_api_gax_java_temp", + strip_prefix = "gax-java-%s" % _gax_java_version, + urls = ["https://github.com/googleapis/gax-java/archive/v%s.zip" % _gax_java_version], +) + +load("@com_google_api_gax_java_temp//:repository_rules.bzl", "com_google_api_gax_java_properties") + +com_google_api_gax_java_properties( + name = "com_google_api_gax_java_properties", + file = "@com_google_api_gax_java_temp//:dependencies.properties", ) -com_google_protoc_java_resource_names_plugin_repositories(omit_com_google_protobuf = True) +load("@com_google_api_gax_java_temp//:repositories.bzl", "com_google_api_gax_java_repositories") + +com_google_api_gax_java_repositories() + +load("@io_grpc_grpc_java//:repositories.bzl", "grpc_java_repositories") + +grpc_java_repositories() diff --git a/repositories.bzl b/repositories.bzl index cf0a3fa7db..3c207aae8d 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -15,9 +15,9 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_jar") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external") -load("@com_google_api_codegen_properties//:dependencies.properties.bzl", "PROPERTIES") +load("@com_google_api_generator_properties//:dependencies.properties.bzl", "PROPERTIES") -def com_google_api_codegen_repositories(): +def com_google_api_generator_repositories(): # Import dependencies shared between Gradle and Bazel (i.e. maven dependencies) for name, artifact in PROPERTIES.items(): _maybe( @@ -32,7 +32,6 @@ def com_google_api_codegen_repositories(): # Import Bazel-only dependencies (Gradle version will import maven artifacts of same # version, while Bazel will depend on Bazel workspaces). The versions are shared in the # properties file. - _protobuf_version = PROPERTIES["version.com_google_protobuf"] _maybe( http_archive, @@ -49,13 +48,6 @@ def com_google_api_codegen_repositories(): licenses = ["notice", "reciprocal"], ) - _maybe( - http_archive, - name = "com_google_protoc_java_resource_names_plugin", - strip_prefix = "protoc-java-resource-names-plugin-3fb2ec9b778f62646c05a7b960c893464c7791c0", - urls = ["https://github.com/googleapis/protoc-java-resource-names-plugin/archive/3fb2ec9b778f62646c05a7b960c893464c7791c0.zip"], - ) - _maybe( http_archive, name = "bazel_skylib", @@ -107,6 +99,7 @@ def com_google_api_codegen_repositories(): server_urls = ["https://repo.maven.apache.org/maven2/"], ) + # TODO(miraleung): Remove these gax imports when gax-java's Bazel build PRs have been submitted. _gax_java_version = PROPERTIES["version.com_google_gax_java"] # Use the Maven artifact because a full bazel-build requires pulling in many transitive deps. @@ -124,15 +117,6 @@ def com_google_api_codegen_repositories(): server_urls = ["https://repo.maven.apache.org/maven2/"], ) - # gRPC. - _io_grpc_version = PROPERTIES["version.io_grpc_java"] - _maybe( - http_archive, - name = "io_grpc_java", - urls = ["https://github.com/grpc/grpc-java/archive/v%s.zip" % _io_grpc_version], - strip_prefix = "grpc-java-%s" % _io_grpc_version, - ) - # grpc-proto doesn't have releases, so we use hashes instead. _io_grpc_proto_prefix = "0020624375a8ee4c7dd9b3e513e443b90bc28990" # Aug. 20, 2020. _maybe( diff --git a/repository_rules.bzl b/repository_rules.bzl index cb625aefa1..f5b8a6444c 100644 --- a/repository_rules.bzl +++ b/repository_rules.bzl @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -def _com_google_api_codegen_properties_impl(ctx): +def _com_google_api_generator_properties_impl(ctx): props_path = ctx.path(ctx.attr.file) result = ctx.execute(["cat", props_path]) @@ -36,13 +36,12 @@ PROPERTIES = {props_as_map} """.format( properties_file = props_name, props_as_map = str(props_as_map), - ) + ) ctx.file("BUILD.bazel", "") ctx.file("%s.bzl" % props_name, dependencies_bzl) - -com_google_api_codegen_properties = repository_rule( - implementation = _com_google_api_codegen_properties_impl, +com_google_api_generator_properties = repository_rule( + implementation = _com_google_api_generator_properties_impl, attrs = { "file": attr.label(), }, diff --git a/src/main/java/com/google/api/generator/BUILD.bazel b/src/main/java/com/google/api/generator/BUILD.bazel index a27e2694f8..864fdfcf6f 100644 --- a/src/main/java/com/google/api/generator/BUILD.bazel +++ b/src/main/java/com/google/api/generator/BUILD.bazel @@ -31,15 +31,12 @@ java_library( ":generator_files", ], deps = [ - "//:annotations_java_proto", - "//:client_java_proto", - "//:field_behavior_java_proto", - "//:longrunning_java_proto", - "//:resource_java_proto", "//src/main/java/com/google/api/generator/engine", "//src/main/java/com/google/api/generator/engine/ast", "//src/main/java/com/google/api/generator/gapic", "//src/main/java/com/google/api/generator/gapic/model", + "@com_google_googleapis//google/api:api_java_proto", + "@com_google_googleapis//google/longrunning:longrunning_java_proto", "@com_google_guava_guava//jar", "@com_google_protobuf//:protobuf_java", ], diff --git a/src/main/java/com/google/api/generator/gapic/composer/BUILD.bazel b/src/main/java/com/google/api/generator/gapic/composer/BUILD.bazel index c9be270e28..5054bb6514 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/BUILD.bazel +++ b/src/main/java/com/google/api/generator/gapic/composer/BUILD.bazel @@ -11,9 +11,6 @@ java_library( ":composer_files", ], deps = [ - "//:longrunning_java_proto", - "//:monitored_resource_java_proto", - "//:rpc_java_proto", "//:service_config_java_proto", "//src/main/java/com/google/api/generator/engine/ast", "//src/main/java/com/google/api/generator/gapic:status_java_proto", @@ -23,13 +20,16 @@ java_library( "@com_google_api_gax_grpc//jar", "@com_google_api_gax_java//jar", "@com_google_code_findbugs_jsr305//jar", + "@com_google_googleapis//google/api:api_java_proto", + "@com_google_googleapis//google/longrunning:longrunning_java_proto", + "@com_google_googleapis//google/rpc:rpc_java_proto", "@com_google_guava_guava//jar", "@com_google_protobuf//:protobuf_java", "@com_google_protobuf//:protobuf_java_util", "@com_google_protobuf//java/core", - "@io_grpc_java//api", - "@io_grpc_java//protobuf", - "@io_grpc_java//stub", + "@io_grpc_grpc_java//api", + "@io_grpc_grpc_java//protobuf", + "@io_grpc_grpc_java//stub", "@junit_junit//jar", "@org_threeten_threetenbp//jar", ], diff --git a/src/main/java/com/google/api/generator/gapic/model/BUILD.bazel b/src/main/java/com/google/api/generator/gapic/model/BUILD.bazel index e883369a61..53be89cb6f 100644 --- a/src/main/java/com/google/api/generator/gapic/model/BUILD.bazel +++ b/src/main/java/com/google/api/generator/gapic/model/BUILD.bazel @@ -11,7 +11,6 @@ java_library( ":model_files", ], deps = [ - "//:rpc_java_proto", "//:service_config_java_proto", "//src/main/java/com/google/api/generator:autovalue", "//src/main/java/com/google/api/generator/engine/ast", @@ -19,6 +18,7 @@ java_library( "@com_google_auto_value_auto_value//jar", "@com_google_auto_value_auto_value_annotations//jar", "@com_google_code_findbugs_jsr305//jar", + "@com_google_googleapis//google/rpc:rpc_java_proto", "@com_google_guava_guava//jar", "@com_google_protobuf//:protobuf_java", ], diff --git a/src/main/java/com/google/api/generator/gapic/protoparser/BUILD.bazel b/src/main/java/com/google/api/generator/gapic/protoparser/BUILD.bazel index 412a924667..e1cb8a9ad7 100644 --- a/src/main/java/com/google/api/generator/gapic/protoparser/BUILD.bazel +++ b/src/main/java/com/google/api/generator/gapic/protoparser/BUILD.bazel @@ -19,16 +19,14 @@ java_library( ":protoparser_files", ], deps = [ - "//:annotations_java_proto", - "//:client_java_proto", - "//:longrunning_java_proto", - "//:resource_java_proto", "//:service_config_java_proto", "//src/main/java/com/google/api/generator/engine/ast", "//src/main/java/com/google/api/generator/gapic/model", "//src/main/java/com/google/api/generator/gapic/utils", "@com_google_api_api_common//jar", "@com_google_code_findbugs_jsr305//jar", + "@com_google_googleapis//google/api:api_java_proto", + "@com_google_googleapis//google/longrunning:longrunning_java_proto", "@com_google_guava_guava//jar", "@com_google_protobuf//:protobuf_java", "@com_google_protobuf//:protobuf_java_util", diff --git a/src/test/java/com/google/api/generator/gapic/composer/BUILD.bazel b/src/test/java/com/google/api/generator/gapic/composer/BUILD.bazel index 740ba1b5f2..e1601e6536 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/BUILD.bazel +++ b/src/test/java/com/google/api/generator/gapic/composer/BUILD.bazel @@ -21,13 +21,6 @@ filegroup( srcs = ["{0}.java".format(f) for f in TESTS], ) -java_proto_library( - name = "logging_java_proto", - deps = [ - "@com_google_googleapis//google/logging/v2:logging_proto", - ], -) - java_proto_library( name = "pubsub_java_proto", deps = [ @@ -52,9 +45,6 @@ java_proto_library( test_class = "com.google.api.generator.gapic.composer.{0}".format(test_name), deps = [ ":common_resources_java_proto", - ":logging_java_proto", - ":pubsub_java_proto", - "//:rpc_java_proto", "//:service_config_java_proto", "//src/main/java/com/google/api/generator/engine/ast", "//src/main/java/com/google/api/generator/engine/writer", @@ -63,6 +53,9 @@ java_proto_library( "//src/main/java/com/google/api/generator/gapic/protoparser", "//src/test/java/com/google/api/generator/gapic/testdata:showcase_java_proto", "@com_google_api_gax_java//jar", + "@com_google_googleapis//google/logging/v2:logging_java_proto", + "@com_google_googleapis//google/pubsub/v1:pubsub_java_proto", + "@com_google_googleapis//google/rpc:rpc_java_proto", "@com_google_protobuf//:protobuf_java", "@com_google_truth_truth//jar", "@junit_junit//jar", diff --git a/src/test/java/com/google/api/generator/gapic/model/BUILD.bazel b/src/test/java/com/google/api/generator/gapic/model/BUILD.bazel index 637631b3f0..705c6b9cc7 100644 --- a/src/test/java/com/google/api/generator/gapic/model/BUILD.bazel +++ b/src/test/java/com/google/api/generator/gapic/model/BUILD.bazel @@ -18,12 +18,12 @@ filegroup( ], test_class = "com.google.api.generator.gapic.model.{0}".format(test_name), deps = [ - "//:rpc_java_proto", "//:service_config_java_proto", "//src/main/java/com/google/api/generator:autovalue", "//src/main/java/com/google/api/generator/gapic/model", "//src/main/java/com/google/api/generator/gapic/protoparser", "//src/test/java/com/google/api/generator/gapic/testdata:showcase_java_proto", + "@com_google_googleapis//google/rpc:rpc_java_proto", "@com_google_protobuf//:protobuf_java", "@com_google_protobuf//:protobuf_java_util", "@com_google_truth_truth//jar", diff --git a/src/test/java/com/google/api/generator/gapic/protoparser/BUILD.bazel b/src/test/java/com/google/api/generator/gapic/protoparser/BUILD.bazel index 30dbd181fe..d8bacd3937 100644 --- a/src/test/java/com/google/api/generator/gapic/protoparser/BUILD.bazel +++ b/src/test/java/com/google/api/generator/gapic/protoparser/BUILD.bazel @@ -24,7 +24,6 @@ filegroup( ], test_class = "com.google.api.generator.gapic.protoparser.{0}".format(test_name), deps = [ - "//:rpc_java_proto", "//:service_config_java_proto", "//src/main/java/com/google/api/generator:autovalue", "//src/main/java/com/google/api/generator/engine/ast", @@ -34,6 +33,7 @@ filegroup( "//src/main/java/com/google/api/generator/gapic/utils", "//src/test/java/com/google/api/generator/gapic/testdata:showcase_java_proto", "//src/test/java/com/google/api/generator/gapic/testdata:testgapic_java_proto", + "@com_google_googleapis//google/rpc:rpc_java_proto", "@com_google_protobuf//:protobuf_java", "@com_google_protobuf//:protobuf_java_util", "@com_google_truth_truth//jar",