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][codegen] feat: Add simple comments to ServiceClient #305

Merged
merged 9 commits 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
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
startup --batch

build --protocopt=--include_source_info
build --protocopt=--experimental_allow_proto3_optional
80 changes: 5 additions & 75 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package(default_visibility = ["//visibility:public"])

load(
"//:gapic_generator_java.bzl",
"google_java_format",
Expand All @@ -16,75 +18,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",
Expand All @@ -97,19 +30,16 @@ java_proto_library(
# ============= Binary targets ================

java_binary(
name = "protoc-gen-gapic-java",
name = "protoc-gen-java_gapic",
srcs = [
"//src/main/java/com/google/api/generator:generator_files",
],
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",
],
Expand Down
4 changes: 2 additions & 2 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ below are temporary and better ones will be coming.
4. Build this plugin.

```sh
bazel build :protoc-gen-gapic-java
bazel build :protoc-gen-java_gapic
```

5. Run the plugin. At this stage, it will not do anything except write
hardcoded Java into two files.

```
protoc -I=${PROTOC_INCLUDE_DIR} -I=${GOOGLEAPIS_DIR} -I=${YOUR_PROTO_DIR} \
--plugin=bazel-bin/protoc-gen-gapic-java ~/dev/googleapis/google/showcase/v1test/*.proto \
--plugin=bazel-bin/protoc-gen-java_gapic ~/dev/googleapis/google/showcase/v1test/*.proto \
--gapic-java_out=/tmp/test
```

Expand Down
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()
3 changes: 2 additions & 1 deletion dependencies.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ version.io_grpc_java=1.30.2

# Common deps.
maven.com_google_guava_guava=com.google.guava:guava:26.0-jre
maven.javax_validation_javax_validation_api=javax.validation:validation-api:2.0.1.Final
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_validation_javax_validation_api=javax.validation:validation-api:2.0.1.Final

# Gapic YAML parsing for batching settings.
maven.org_yaml_snakeyaml=org.yaml:snakeyaml:1.26
Expand Down
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
Empty file added rules_java_gapic/BUILD.bazel
Empty file.
55 changes: 55 additions & 0 deletions rules_java_gapic/java_gapic.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

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

def java_gapic_library(
name,
srcs,
package = None,
service_yaml = None,
grpc_service_config = None,
gapic_yaml = None,
deps = [],
test_deps = [],
**kwargs):
file_args_dict = {}

if grpc_service_config:
file_args_dict[grpc_service_config] = "grpc-service-config"

if gapic_yaml:
file_args_dict[gapic_yaml] = "gapic-config"

# Currently a no-op.
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"

_java_generator_name = "java_gapic"
proto_custom_library(
name = raw_srcjar_name,
deps = srcs,
plugin = Label("@com_google_api_generator//:protoc-gen-%s" % _java_generator_name),
plugin_file_args = {},
opt_file_args = file_args_dict,
output_type = _java_generator_name,
output_suffix = output_suffix,
**kwargs
)
Loading