Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ggj][bazel] fix: refactor and rename Bazel rules to use googleapis' toolchain #286

Merged
merged 1 commit into from
Sep 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 43 additions & 16 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -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")

Expand All @@ -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()
22 changes: 3 additions & 19 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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.
Expand All @@ -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(
Expand Down
9 changes: 4 additions & 5 deletions repository_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand All @@ -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(),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down