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/gapic/composer/BUILD.bazel b/src/main/java/com/google/api/generator/gapic/composer/BUILD.bazel index c9be270e28..4dce32c387 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 @@ -27,9 +27,9 @@ java_library( "@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", ],