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

fix(bazel): Remove monolith rule deps from the Java µgen Bazel rules [ggj] #764

Merged
merged 14 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ jobs:
run: bazel --batch test $(bazel query "//src/test/..." | grep "Test$") --noshow_progress --test_output=errors

- name: Integration Tests
run: bazel --batch test //test/integration:asset //test/integration:credentials //test/integration:iam //test/integration:kms //test/integration:logging //test/integration:pubsub //test/integration:redis //test/integration:library --noshow_progress
run: |
bazel clean --expunge --async
bazel --batch test //test/integration:asset //test/integration:credentials //test/integration:iam //test/integration:kms //test/integration:logging //test/integration:pubsub //test/integration:redis //test/integration:library --noshow_progress
miraleung marked this conversation as resolved.
Show resolved Hide resolved

- uses: actions/upload-artifact@v2
if: ${{ failure() }}
Expand Down
20 changes: 18 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ http_archive(
jvm_maven_import_external(
name = "google_java_format_all_deps",
artifact = "com.google.googlejavaformat:google-java-format:jar:all-deps:1.7",
server_urls = ["https://repo.maven.apache.org/maven2/", "http://repo1.maven.org/maven2/"],
licenses = ["notice", "reciprocal"]
licenses = [
"notice",
"reciprocal",
],
server_urls = [
"https://repo.maven.apache.org/maven2/",
"http://repo1.maven.org/maven2/",
],
)

# gax-java and its transitive dependencies must be imported before
Expand Down Expand Up @@ -62,8 +68,18 @@ load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

# Bazel rules.
_rules_gapic_version = "0.5.4"

http_archive(
name = "rules_gapic",
strip_prefix = "rules_gapic-%s" % _rules_gapic_version,
urls = ["https://github.com/googleapis/rules_gapic/archive/v%s.tar.gz" % _rules_gapic_version],
)

# Java dependencies.
# Import the monolith so we can transitively use its gapic rules for googleapis.
# TODO: Remove this after this dep has been removed from googleapis' switched_rules_by_language.
http_archive(
name = "com_google_api_codegen",
strip_prefix = "gapic-generator-2.11.1",
Expand Down
2 changes: 1 addition & 1 deletion rules_java_gapic/java_gapic.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.

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

SERVICE_YAML_ALLOWLIST = ["clouddms", "cloudkms", "datastream", "pubsub"]
NO_GRPC_CONFIG_ALLOWLIST = ["library"]
Expand Down
178 changes: 164 additions & 14 deletions test/integration/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
load(
"@com_google_googleapis_imports//:imports.bzl",
"java_gapic_assembly_gradle_pkg",
"@gapic_generator_java//rules_java_gapic:java_gapic.bzl",
"java_gapic_library",
"java_gapic_test",
"java_grpc_library",
"java_proto_library",
"proto_library_with_info",
)
load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library")
load(
"@gapic_generator_java//rules_java_gapic:java_gapic_pkg.bzl",
"java_gapic_assembly_gradle_pkg",
)
load("@rules_gapic//:gapic.bzl", "proto_library_with_info")
load(
"//:rules_bazel/java/integration_test.bzl",
"golden_update",
Expand All @@ -29,20 +31,20 @@ INTEGRATION_TEST_LIBRARIES = [
"logging", # Java package remapping in gapic.yaml.
"redis", # Has a gapic.yaml.
"library", # No gRPC service config.
"compute", # REGAPIC test.
"compute", # REGAPIC test.
]

# Keys must match the values in INTEGRATION_TEST_LIBRARIES above.
API_GAPIC_TARGETS = {
"asset": "@com_google_googleapis//google/cloud/asset/v1:asset_java_gapic",
"credentials": "@com_google_googleapis//google/iam/credentials/v1:credentials_java_gapic",
"asset": ":asset_java_gapic",
"credentials": ":credentials_java_gapic",
"iam": ":iam_java_gapic", # Googleapis' LRO does not have a Java Gapic.
"kms": ":kms_java_gapic", # Local target because mixins are not rolled out yet.
"pubsub": ":pubsub_java_gapic",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are some tests coming from googleapis/googleapis-discovery and some are "native" to gapic-generator-java? (i.e. what is special about iam, kms and pubsub?)

Copy link
Contributor Author

@miraleung miraleung Jun 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add some custom changes to IAM, KMS, and PubSub to exercise edge cases that the googleapis target does not cover.

"logging": "@com_google_googleapis//google/logging/v2:logging_java_gapic",
"redis": "@com_google_googleapis//google/cloud/redis/v1beta1:redis_java_gapic",
"library": "@com_google_googleapis//google/example/library/v1:library_java_gapic",
"compute": "@com_google_googleapis_discovery//google/cloud/compute/v1:compute_small_java_gapic",
"logging": ":logging_java_gapic",
"redis": ":redis_java_gapic",
"library": ":library_java_gapic",
"compute": ":compute_small_java_gapic",
}

[integration_test(
Expand All @@ -57,6 +59,154 @@ API_GAPIC_TARGETS = {
target = API_GAPIC_TARGETS[lib_name],
) for lib_name in INTEGRATION_TEST_LIBRARIES]

###################################################
# Temporary proto_with_info definitions for
# monolith depdency removal.
# Remove this section when the monolith rule deps are
# out of googleapis.
###################################################
proto_library_with_info(
name = "asset_proto_with_info",
deps = [
"@com_google_googleapis//google/cloud:common_resources_proto",
"@com_google_googleapis//google/cloud/asset/v1:asset_proto",
],
)

proto_library_with_info(
name = "credentials_proto_with_info",
deps = [
"@com_google_googleapis//google/cloud:common_resources_proto",
"@com_google_googleapis//google/iam/credentials/v1:credentials_proto",
],
)

proto_library_with_info(
name = "logging_proto_with_info",
deps = [
"@com_google_googleapis//google/cloud:common_resources_proto",
"@com_google_googleapis//google/logging/v2:logging_proto",
],
)

proto_library_with_info(
name = "pubsub_proto_with_info",
deps = [
"@com_google_googleapis//google/cloud:common_resources_proto",
"@com_google_googleapis//google/iam/v1:iam_policy_proto",
"@com_google_googleapis//google/iam/v1:policy_proto",
"@com_google_googleapis//google/pubsub/v1:pubsub_proto",
],
)

proto_library_with_info(
name = "redis_proto_with_info",
deps = [
"@com_google_googleapis//google/cloud:common_resources_proto",
"@com_google_googleapis//google/cloud/redis/v1beta1:redis_proto",
],
)

proto_library_with_info(
name = "iam_proto_with_info",
deps = [
"@com_google_googleapis//google/iam/v1:iam_policy_proto",
"@com_google_googleapis//google/iam/v1:options_proto",
"@com_google_googleapis//google/iam/v1:policy_proto",
],
)

proto_library_with_info(
name = "library_proto_with_info",
deps = [
"@com_google_googleapis//google/cloud:common_resources_proto",
"@com_google_googleapis//google/example/library/v1:library_proto",
],
)

proto_library_with_info(
name = "compute_small_proto_with_info",
deps = [
"@com_google_googleapis//google/cloud:common_resources_proto",
"@com_google_googleapis_discovery//google/cloud/compute/v1:compute_small_proto",
],
)

java_gapic_library(
name = "compute_small_java_gapic",
srcs = [":compute_small_proto_with_info"],
test_deps = [],
transport = "rest",
deps = [
"@com_google_googleapis_discovery//google/cloud/compute/v1:compute_small_java_proto",
],
)

java_gapic_library(
name = "asset_java_gapic",
srcs = [":asset_proto_with_info"],
grpc_service_config = "@com_google_googleapis//google/cloud/asset/v1:cloudasset_grpc_service_config.json",
test_deps = [
"@com_google_googleapis//google/cloud/asset/v1:asset_java_grpc",
"@com_google_googleapis//google/iam/v1:iam_java_grpc",
],
deps = [
"@com_google_googleapis//google/cloud/asset/v1:asset_java_proto",
"@com_google_googleapis//google/iam/v1:iam_java_proto",
"@com_google_googleapis//google/identity/accesscontextmanager/v1:accesscontextmanager_proto",
],
)

java_gapic_library(
name = "credentials_java_gapic",
srcs = [":credentials_proto_with_info"],
grpc_service_config = "@com_google_googleapis//google/iam/credentials/v1:iamcredentials_grpc_service_config.json",
test_deps = [
"@com_google_googleapis//google/iam/credentials/v1:credentials_java_grpc",
],
deps = [
"@com_google_googleapis//google/iam/credentials/v1:credentials_java_proto",
],
)

java_gapic_library(
name = "logging_java_gapic",
srcs = [":logging_proto_with_info"],
gapic_yaml = "@com_google_googleapis//google/logging/v2:logging_gapic.yaml",
grpc_service_config = "@com_google_googleapis//google/logging/v2:logging_grpc_service_config.json",
test_deps = [
"@com_google_googleapis//google/logging/v2:logging_java_grpc",
],
deps = [
"@com_google_googleapis//google/api:api_java_proto",
"@com_google_googleapis//google/logging/v2:logging_java_proto",
],
)

java_gapic_library(
name = "redis_java_gapic",
srcs = [":redis_proto_with_info"],
gapic_yaml = "@com_google_googleapis//google/cloud/redis/v1beta1:redis_gapic.yaml",
grpc_service_config = "@com_google_googleapis//google/cloud/redis/v1beta1:redis_grpc_service_config.json",
test_deps = [
"@com_google_googleapis//google/cloud/redis/v1beta1:redis_java_grpc",
],
deps = [
"@com_google_googleapis//google/cloud/redis/v1beta1:redis_java_proto",
],
)

java_gapic_library(
name = "library_java_gapic",
srcs = [":library_proto_with_info"],
gapic_yaml = "@com_google_googleapis//google/example/library/v1:library_example_gapic.yaml",
test_deps = [
"@com_google_googleapis//google/example/library/v1:library_java_grpc",
],
deps = [
"@com_google_googleapis//google/example/library/v1:library_java_proto",
],
)
####################################################
# API Library Rules
####################################################
Expand Down Expand Up @@ -168,7 +318,7 @@ java_gapic_assembly_gradle_pkg(
# IAM (for a standalone mixed-in API).
java_gapic_library(
name = "iam_java_gapic",
srcs = ["@com_google_googleapis//google/iam/v1:iam_proto_with_info"],
srcs = [":iam_proto_with_info"],
grpc_service_config = "iam_grpc_service_config.json",
test_deps = [
"@com_google_googleapis//google/iam/v1:iam_java_grpc",
Expand Down Expand Up @@ -283,7 +433,7 @@ java_gapic_assembly_gradle_pkg(
# TODO: Remove some of these targets when PubSub has been migrated in googleapis.
java_gapic_library(
name = "pubsub_java_gapic",
srcs = ["@com_google_googleapis//google/pubsub/v1:pubsub_proto_with_info"],
srcs = [":pubsub_proto_with_info"],
gapic_yaml = "@com_google_googleapis//google/pubsub/v1:pubsub_gapic.yaml",
grpc_service_config = "@com_google_googleapis//google/pubsub/v1:pubsub_grpc_service_config.json",
# For the IAM mixin.
Expand Down