Skip to content
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
78 changes: 3 additions & 75 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -97,19 +28,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()
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
23 changes: 18 additions & 5 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ then
fi

# Build if needed.
if [[ "${FLAGS_use_cached}" == 0 ]] || [[ ! -f bazel-bin/protoc-gen-gapic-java ]]
if [[ "${FLAGS_use_cached}" == 0 ]] || [[ ! -f bazel-bin/protoc-gen-java_gapic ]]
then
echo_success "Rebuilding the microgenerator..."
bazel build :protoc-gen-gapic-java
bazel build :protoc-gen-java_gapic
if [[ $? -ne 0 ]]
then
echo_error "Build failed."
Expand All @@ -72,12 +72,25 @@ then
echo_success "Done"
fi

# Key values are synced to rules_java_gapic/java_gapic.bzl.
SERVICE_CONFIG_OPT=""
if [ -n "$FLAGS_service_config" ]
then
SERVICE_CONFIG_OPT="grpc-service-config=$FLAGS_service_config"
fi
GAPIC_CONFIG_OPT=""
if [ -n "$FLAGS_gapic_config" ]
then
GAPIC_CONFIG_OPT="gapic-config=$FLAGS_gapic_config"
fi

# Run protoc.
protoc -I="${PROTOC_INCLUDE_DIR}" -I="${FLAGS_googleapis}" -I="${FLAGS_protos}" \
-I="${FLAGS_googleapis}/google/longrunning" \
--plugin=bazel-bin/protoc-gen-gapic-java ${FLAGS_protos}/*.proto \
--gapic-java_out="${FLAGS_out}" \
--gapic-java_opt="${FLAGS_service_config},${FLAGS_gapic_config}" \
--include_source_info \
--plugin=bazel-bin/protoc-gen-java_gapic ${FLAGS_protos}/*.proto \
--java_gapic_out="${FLAGS_out}" \
--java_gapic_opt="${SERVICE_CONFIG_OPT},${GAPIC_CONFIG_OPT}" \
--experimental_allow_proto3_optional

echo_success "Output files written to ${FLAGS_out}"
7 changes: 2 additions & 5 deletions src/main/java/com/google/api/generator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;

@AutoValue
Expand Down Expand Up @@ -116,6 +117,12 @@ public MethodInvocationExpr build() {
|| methodInvocationExpr.staticReferenceType() == null,
"Only the expression reference or the static reference can be set, not both");

Preconditions.checkState(
methodInvocationExpr.arguments().stream().allMatch(e -> !Objects.isNull(e)),
String.format(
"Found null expression in arguments for %s",
methodInvocationExpr.methodIdentifier().name()));

return methodInvocationExpr;
}
}
Expand Down
Loading