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] feat: add java_gapic_test Bazel rule #322

Merged
merged 22 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fd218de
feat: add protobuf comment parser util
miraleung Sep 15, 2020
8c792e3
fix: add basic proto build rules
miraleung Sep 15, 2020
d6ee068
feat: add header comments to ServiceClient
miraleung Sep 15, 2020
82aa0b6
fix: build protoc at test time
miraleung Sep 15, 2020
c8f2233
Merge branch 'gp/g0' of github.com:googleapis/gapic-generator-java in…
miraleung Sep 15, 2020
2405b1a
fix!: wrap protobuf location and process comments
miraleung Sep 15, 2020
a59fd3f
feat: add comment parsing to methods and fields
miraleung Sep 16, 2020
66dec11
fix: test
miraleung Sep 16, 2020
8325450
feat: add protobuf comments to ServiceClient
miraleung Sep 16, 2020
5acc151
fix: solidify codegen method order with TypeNode/MethodArg and Compar…
miraleung Sep 16, 2020
97e780a
fix: clean up tests
miraleung Sep 16, 2020
5508e67
fix: merge gp/g2_5
miraleung Sep 17, 2020
0b7288e
fix: merge
miraleung Sep 17, 2020
c6ca60b
fix: ServiceClient member variables and method calls
miraleung Sep 18, 2020
ac89e12
fix: ServiceStubSettings builder type
miraleung Sep 18, 2020
b5e6585
fix: ServiceSettings Builder construction
miraleung Sep 18, 2020
1e10b6b
fix: ServiceStub callable types
miraleung Sep 18, 2020
006aff4
feat: java_gapic_library rule impl
miraleung Sep 18, 2020
f25274f
fix: remove debugging comments
miraleung Sep 18, 2020
76d26d8
feat: add gradle assembly Bazel rules
miraleung Sep 18, 2020
c56271f
feat: add java_gapic_test Bazel rule
miraleung Sep 18, 2020
c1bfc73
Merge branch 'master' into gp/g11
miraleung Sep 19, 2020
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
16 changes: 6 additions & 10 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ com_google_api_generator_properties(
file = "//:dependencies.properties",
)

load("@com_google_api_generator_properties//:dependencies.properties.bzl", "PROPERTIES")
load("//:repositories.bzl", "com_google_api_generator_repositories")

com_google_api_generator_repositories()
Expand All @@ -47,27 +48,22 @@ switched_rules_by_language(
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"
_gax_java_version = PROPERTIES["version.com_google_gax_java"]

http_archive(
name = "com_google_api_gax_java_temp",
name = "com_google_api_gax_java",
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")
load("@com_google_api_gax_java//: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",
file = "@com_google_api_gax_java//:dependencies.properties",
)

load("@com_google_api_gax_java_temp//:repositories.bzl", "com_google_api_gax_java_repositories")
load("@com_google_api_gax_java//:repositories.bzl", "com_google_api_gax_java_repositories")

com_google_api_gax_java_repositories()

Expand Down
8 changes: 5 additions & 3 deletions dependencies.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ version.com_google_protobuf=3.12.2
# Version of google-java-format is downgraded from 1.8 to 1.7, because 1.8 supports java 11 minimum, while our JRE is java 8.
version.google_java_format=1.7
version.com_google_api_common_java=1.9.3
version.com_google_gax_java=1.57.0
# TODO(miraleung): Update this.
version.com_google_gax_java=1.58.3
version.io_grpc_java=1.30.2

# Common deps.
Expand All @@ -20,7 +21,7 @@ maven.com_google_code_findbugs_jsr305=com.google.code.findbugs:jsr305:3.0.0
maven.com_google_auto_value_auto_value=com.google.auto.value:auto-value:1.7.2
maven.com_google_auto_value_auto_value_annotations=com.google.auto.value:auto-value-annotations:1.7.2
maven.com_google_protobuf_protobuf_java=com.google.protobuf:protobuf-java:3.12.2
maven.javax_annotation_api=javax.annotation:javax.annotation-api:1.3.2
maven.javax_annotation_javax_annotation_api=javax.annotation:javax.annotation-api:1.3.2
maven.javax_validation_javax_validation_api=javax.validation:validation-api:2.0.1.Final

# Gapic YAML parsing for batching settings.
Expand All @@ -32,4 +33,5 @@ maven.org_threeten_threetenbp=org.threeten:threetenbp:1.3.3
# Testing.
maven.junit_junit=junit:junit:4.13
maven.org_mockito_mockito_core=org.mockito:mockito-core:2.21.0
maven.com_google_truth_truth=com.google.truth:truth:0.42
# Keep in sync with gax-java.
maven.com_google_truth_truth=com.google.truth:truth:1.0
18 changes: 0 additions & 18 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,6 @@ def com_google_api_generator_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.
_maybe(
jvm_maven_import_external,
name = "com_google_api_gax_java",
artifact = "com.google.api:gax:%s" % _gax_java_version,
server_urls = ["https://repo.maven.apache.org/maven2/"],
)

_maybe(
jvm_maven_import_external,
name = "com_google_api_gax_grpc",
artifact = "com.google.api:gax-grpc:%s" % _gax_java_version,
server_urls = ["https://repo.maven.apache.org/maven2/"],
)

# grpc-proto doesn't have releases, so we use hashes instead.
_io_grpc_proto_prefix = "0020624375a8ee4c7dd9b3e513e443b90bc28990" # Aug. 20, 2020.
_maybe(
Expand Down
20 changes: 20 additions & 0 deletions rules_java_gapic/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")

package(default_visibility = ["//visibility:public"])

exports_files(glob(["resources/**/*"]))

pkg_tar(
name = "gradlew",
extension = "tar.gz",
files = {
"resources/gradle/gradle/wrapper/gradle-wrapper.jar": "gradle/wrapper/gradle-wrapper.jar",
"resources/gradle/gradle/wrapper/gradle-wrapper.properties": "gradle/wrapper/gradle-wrapper.properties",
"resources/gradle/gradlew": "gradlew",
"resources/gradle/gradlew.bat": "gradlew.bat",
},
mode = "644",
modes = {
"gradlew": "555",
},
)
123 changes: 120 additions & 3 deletions rules_java_gapic/java_gapic.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019 Google LLC
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,6 +14,59 @@

load("@com_google_api_codegen//rules_gapic:gapic.bzl", "proto_custom_library", "unzipped_srcjar")

def _java_gapic_postprocess_srcjar_impl(ctx):
gapic_srcjar = ctx.file.gapic_srcjar
output_srcjar_name = ctx.label.name
output_main = ctx.outputs.main
output_test = ctx.outputs.test
formatter = ctx.executable.formatter

output_dir_name = ctx.label.name
output_dir_path = "%s/%s" % (output_main.dirname, output_dir_name)

script = """
unzip -q {gapic_srcjar}
# Sync'd to the output file name in Writer.java.
unzip -q temp-codegen.srcjar -d {output_dir_path}
# This may fail if there are spaces and/or too many files (exceed max length of command length).
{formatter} --replace $(find {output_dir_path} -type f -printf "%p ")
zip -r -j {output_srcjar_name}.srcjar {output_dir_path}/src/main/* {output_dir_path}/proto/src/main/*
zip -r -j {output_srcjar_name}-tests.srcjar {output_dir_path}/src/test/*
mv {output_srcjar_name}.srcjar {output_main}
mv {output_srcjar_name}-tests.srcjar {output_test}
""".format(
gapic_srcjar = gapic_srcjar.path,
output_srcjar_name = output_srcjar_name,
output_main = output_main.path,
formatter = formatter,
output_dir_name = output_dir_name,
output_dir_path = output_dir_path,
output_test = output_test.path,
)

ctx.actions.run_shell(
inputs = [gapic_srcjar],
tools = [formatter],
command = script,
outputs = [output_main, output_test],
)

_java_gapic_postprocess_srcjar = rule(
attrs = {
"gapic_srcjar": attr.label(mandatory = True, allow_single_file = True),
"formatter": attr.label(
default = Label("//:google_java_format_binary"),
executable = True,
cfg = "host",
),
},
outputs = {
"main": "%{name}.srcjar",
"test": "%{name}-test.srcjar",
},
implementation = _java_gapic_postprocess_srcjar_impl,
)

def java_gapic_library(
name,
srcs,
Expand All @@ -36,8 +89,6 @@ def java_gapic_library(
if service_yaml:
file_args_dict[service_yaml] = "gapic-service-config"

#file_args = ["%s=%s" % (k, v) for k, v in file_args_dict.items()]

srcjar_name = name + "_srcjar"
raw_srcjar_name = srcjar_name + "_raw"
output_suffix = ".srcjar"
Expand All @@ -53,3 +104,69 @@ def java_gapic_library(
output_suffix = output_suffix,
**kwargs
)

_java_gapic_postprocess_srcjar(
name = srcjar_name,
gapic_srcjar = "%s.srcjar" % raw_srcjar_name,
**kwargs
)

# General additional deps.
actual_deps = deps + [
"@com_google_googleapis//google/rpc:rpc_java_proto",
"@com_google_googleapis//google/longrunning:longrunning_java_proto",
"@com_google_protobuf//:protobuf_java",
"@com_google_api_api_common//jar",
"@com_google_api_gax_java//gax:gax",
"@com_google_api_gax_java//gax-grpc:gax_grpc",
"@com_google_guava_guava//jar",
"@io_grpc_grpc_java//core:core",
"@io_grpc_grpc_java//protobuf:protobuf",
"@com_google_code_findbugs_jsr305//jar",
"@org_threeten_threetenbp//jar",
"@io_opencensus_opencensus_api//jar",
"@com_google_auth_google_auth_library_credentials//jar",
"@com_google_auth_google_auth_library_oauth2_http//jar",
"@com_google_http_client_google_http_client//jar",
"@javax_annotation_javax_annotation_api//jar",
]

native.java_library(
name = name,
srcs = ["%s.srcjar" % srcjar_name],
deps = actual_deps,
**kwargs
)

# Test deps.
actual_test_deps = test_deps + actual_deps + [
"@com_google_api_gax_java//gax-grpc:gax_grpc_testlib",
"@com_google_api_gax_java//gax:gax_testlib",
"@com_google_code_gson_gson//jar",
"@io_grpc_grpc_java//auth:auth",
"@io_grpc_grpc_netty_shaded//jar",
"@io_grpc_grpc_java//stub:stub",
"@io_opencensus_opencensus_contrib_grpc_metrics//jar",
"@junit_junit//jar",
]

native.java_library(
name = "%s_test" % name,
srcs = ["%s-test.srcjar" % srcjar_name],
deps = [":%s" % name] + actual_test_deps,
**kwargs
)

def java_gapic_test(name, runtime_deps, test_classes, **kwargs):
for test_class in test_classes:
native.java_test(
name = test_class,
test_class = test_class,
runtime_deps = runtime_deps,
**kwargs
)
native.test_suite(
name = name,
tests = test_classes,
**kwargs
)
Loading