From 965fe2530a2340fe262982ebc2f8d6a0a68dbca0 Mon Sep 17 00:00:00 2001 From: Noah Dietz Date: Tue, 16 Nov 2021 14:48:22 -0800 Subject: [PATCH] fix(bazel): iam/location mixin java deps (#89) Fixes java mixin dependency generation in bazel targets. The generated deps are based on the existing PubSub & KMS targets that have mixins today. --- .../bazel/BUILD.bazel.gapic_api.mustache | 2 +- .../api/codegen/bazel/BazelBuildFileView.java | 36 ++++++------------- .../example/library/v1/BUILD.bazel.baseline | 8 ++--- .../library/v1legacy/BUILD.bazel.baseline | 8 ++--- 4 files changed, 19 insertions(+), 35 deletions(-) diff --git a/bazel/src/main/java/com/google/api/codegen/bazel/BUILD.bazel.gapic_api.mustache b/bazel/src/main/java/com/google/api/codegen/bazel/BUILD.bazel.gapic_api.mustache index 284c49f..f575cd0 100644 --- a/bazel/src/main/java/com/google/api/codegen/bazel/BUILD.bazel.gapic_api.mustache +++ b/bazel/src/main/java/com/google/api/codegen/bazel/BUILD.bazel.gapic_api.mustache @@ -88,7 +88,7 @@ java_gapic_assembly_gradle_pkg( ":{{name}}_java_gapic", ":{{name}}_java_grpc", ":{{name}}_java_proto", - ":{{name}}_proto",{{extra_imports_java}} + ":{{name}}_proto", ], ) diff --git a/bazel/src/main/java/com/google/api/codegen/bazel/BazelBuildFileView.java b/bazel/src/main/java/com/google/api/codegen/bazel/BazelBuildFileView.java index c70e2a2..0263ca1 100644 --- a/bazel/src/main/java/com/google/api/codegen/bazel/BazelBuildFileView.java +++ b/bazel/src/main/java/com/google/api/codegen/bazel/BazelBuildFileView.java @@ -45,7 +45,17 @@ class BazelBuildFileView { Set extraProtosNodeJS = new TreeSet<>(); Set extraImports = new TreeSet<>(); extraImports.add(COMMON_RESOURCES_PROTO); + // Add location_proto dependency for mix-in if individual language rules need it. + if (bp.hasLocations() && !bp.getProtoPackage().equals("google.cloud.location")) { + extraImports.add("//google/cloud/location:location_proto"); + } + // Add iam_policy_proto dependency for mix-in if individual language rules need it. + if (bp.hasIAMPolicy() && !bp.getProtoPackage().equals("google.iam.v1")) { + extraImports.add("//google/iam/v1:iam_policy_proto"); + } tokens.put("extra_imports", joinSetWithIndentation(extraImports)); + // Remove common_resources.proto because it is only needed for the proto_library_with_info target. + extraImports.remove(COMMON_RESOURCES_PROTO); String packPrefix = bp.getProtoPackage().replace(".", "/") + '/'; Set actualImports = new TreeSet<>(); @@ -127,26 +137,13 @@ class BazelBuildFileView { javaTests.add(javaPackage + "." + actualService + "ClientTest"); } - // Remove common_resources.proto because it is only needed for the proto_library_with_info target. - extraImports.remove(COMMON_RESOURCES_PROTO); - // Add location_proto dependency for mix-in if individual language rules need it. - if (bp.hasLocations() && !bp.getProtoPackage().equals("google.cloud.location")) { - extraImports.add("//google/cloud/location:location_proto"); - } actualImports.addAll(extraImports); tokens.put("java_tests", joinSetWithIndentation(javaTests)); tokens.put("java_gapic_deps", joinSetWithIndentationNl(mapJavaGapicDeps(actualImports))); tokens.put( "java_gapic_test_deps", joinSetWithIndentationNl(mapJavaGapicTestDeps(actualImports))); - tokens.put("extra_imports_java", joinSetWithIndentationNl(mapJavaGapicAssemblyPkgDeps(extraImports))); - // Add iam_policy_proto dependency for mix-in if individual language rules need it. - // Java does not seem to need it for mix-in purposes, so this is added after Java deps - // are worked out. - if (bp.hasIAMPolicy() && !bp.getProtoPackage().equals("google.iam.v1")) { - extraImports.add("//google/iam/v1:iam_policy_proto"); - } actualImports.addAll(extraImports); // Construct GAPIC import path & package name based on go_package proto option @@ -245,7 +242,6 @@ private Set mapJavaGapicDeps(Set protoImports) { javaImports.add(replaceLabelName(protoImport, ":api_java_proto")); } else if (protoImport.endsWith(":location_proto")) { javaImports.add("//google/cloud/location:location_java_proto"); - javaImports.add("//google/cloud/location:location_java_grpc"); } else if (protoImport.endsWith(":common_proto")) { javaImports.add(replaceLabelName(protoImport, ":common_java_proto")); } @@ -253,18 +249,6 @@ private Set mapJavaGapicDeps(Set protoImports) { return javaImports; } - private Set mapJavaGapicAssemblyPkgDeps(Set protoImports) { - Set asemmblyPkgDeps = new TreeSet<>(); - for (String protoImport : protoImports) { - if (protoImport.endsWith(":location_proto")) { - asemmblyPkgDeps.add("//google/cloud/location:location_java_proto"); - asemmblyPkgDeps.add("//google/cloud/location:location_java_grpc"); - } - asemmblyPkgDeps.add(protoImport); - } - return asemmblyPkgDeps; - } - private Set mapJavaGapicTestDeps(Set protoImports) { Set javaImports = new TreeSet<>(); for (String protoImport : protoImports) { diff --git a/bazel/src/test/data/googleapis/google/example/library/v1/BUILD.bazel.baseline b/bazel/src/test/data/googleapis/google/example/library/v1/BUILD.bazel.baseline index 49b12ce..caa458b 100644 --- a/bazel/src/test/data/googleapis/google/example/library/v1/BUILD.bazel.baseline +++ b/bazel/src/test/data/googleapis/google/example/library/v1/BUILD.bazel.baseline @@ -39,7 +39,9 @@ proto_library_with_info( name = "library_proto_with_info", deps = [ ":library_proto", + "//google/cloud/location:location_proto", "//google/cloud:common_resources_proto", + "//google/iam/v1:iam_policy_proto", ], ) @@ -75,13 +77,14 @@ java_gapic_library( test_deps = [ ":library_java_grpc", "//google/cloud/location:location_java_grpc", + "//google/iam/v1:iam_java_grpc", ], deps = [ ":library_java_proto", "//google/api:api_java_proto", "//google/cloud/common:common_java_proto", - "//google/cloud/location:location_java_grpc", "//google/cloud/location:location_java_proto", + "//google/iam/v1:iam_java_proto", ], ) @@ -101,9 +104,6 @@ java_gapic_assembly_gradle_pkg( ":library_java_grpc", ":library_java_proto", ":library_proto", - "//google/cloud/location:location_java_grpc", - "//google/cloud/location:location_java_proto", - "//google/cloud/location:location_proto", ], ) diff --git a/bazel/src/test/data/googleapis/google/example/library/v1legacy/BUILD.bazel.baseline b/bazel/src/test/data/googleapis/google/example/library/v1legacy/BUILD.bazel.baseline index ec276d5..a891195 100644 --- a/bazel/src/test/data/googleapis/google/example/library/v1legacy/BUILD.bazel.baseline +++ b/bazel/src/test/data/googleapis/google/example/library/v1legacy/BUILD.bazel.baseline @@ -37,7 +37,9 @@ proto_library_with_info( name = "library_proto_with_info", deps = [ ":library_proto", + "//google/cloud/location:location_proto", "//google/cloud:common_resources_proto", + "//google/iam/v1:iam_policy_proto", ], ) @@ -73,12 +75,13 @@ java_gapic_library( test_deps = [ ":library_java_grpc", "//google/cloud/location:location_java_grpc", + "//google/iam/v1:iam_java_grpc", ], deps = [ ":library_java_proto", "//google/api:api_java_proto", - "//google/cloud/location:location_java_grpc", "//google/cloud/location:location_java_proto", + "//google/iam/v1:iam_java_proto", ], ) @@ -98,9 +101,6 @@ java_gapic_assembly_gradle_pkg( ":library_java_grpc", ":library_java_proto", ":library_proto", - "//google/cloud/location:location_java_grpc", - "//google/cloud/location:location_java_proto", - "//google/cloud/location:location_proto", ], )