diff --git a/bazel/src/main/java/com/google/api/codegen/bazel/ApiDir.java b/bazel/src/main/java/com/google/api/codegen/bazel/ApiDir.java index 2951d9d..fd2a37c 100644 --- a/bazel/src/main/java/com/google/api/codegen/bazel/ApiDir.java +++ b/bazel/src/main/java/com/google/api/codegen/bazel/ApiDir.java @@ -26,10 +26,12 @@ class ApiDir { Pattern.compile("_(?[a-zA-Z]+\\d+[\\w]*)\\.yaml"); private static String CLOUD_AUTH_SCOPE = "https://www.googleapis.com/auth/cloud-platform"; private static String LOCATIONS_MIXIN = "name: google.cloud.location.Locations"; + private static String IAM_POLICY_MIXIN = "name: google.iam.v1.IAMPolicy"; private final Map serviceYamlPaths = new TreeMap<>(); private final Map cloudScopes = new TreeMap<>(); private final Map containLocations = new TreeMap<>(); + private final Map containIAMPolicy = new TreeMap<>(); Map getServiceYamlPaths() { return serviceYamlPaths; @@ -43,6 +45,10 @@ Map getContainsLocations() { return containLocations; } + Map getContainsIAMPolicy() { + return containIAMPolicy; + } + void parseYamlFile(String fileName, String fileBody) { // It is a service yaml Matcher m = SERVICE_YAML_TYPE.matcher(fileBody); @@ -57,6 +63,9 @@ void parseYamlFile(String fileName, String fileBody) { if (fileBody.contains(LOCATIONS_MIXIN)) { containLocations.put(verKey, true); } + if (fileBody.contains(IAM_POLICY_MIXIN)) { + containIAMPolicy.put(verKey, true); + } } } } diff --git a/bazel/src/main/java/com/google/api/codegen/bazel/ApiVersionedDir.java b/bazel/src/main/java/com/google/api/codegen/bazel/ApiVersionedDir.java index f1e50d8..0d54fda 100644 --- a/bazel/src/main/java/com/google/api/codegen/bazel/ApiVersionedDir.java +++ b/bazel/src/main/java/com/google/api/codegen/bazel/ApiVersionedDir.java @@ -61,6 +61,8 @@ class ApiVersionedDir { private static String LOCATIONS_MIXIN = "name: google.cloud.location.Locations"; + private static String IAM_POLICY_MIXIN = "name: google.iam.v1.IAMPolicy"; + private static final String[] PRESERVED_PROTO_LIBRARY_STRING_ATTRIBUTES = { // TypeScript: "package_name", @@ -167,6 +169,8 @@ class ApiVersionedDir { private boolean containsLocations; + private boolean containsIAMPolicy; + // Names of *_gapic_assembly_* rules (since they may be overridden by the user) private final Map assemblyPkgRulesNames = new HashMap<>(); @@ -250,6 +254,10 @@ boolean hasLocations() { return this.containsLocations; } + boolean hasIAMPolicy() { + return this.containsIAMPolicy; + } + void parseYamlFile(String fileName, String fileBody) { // It is a gapic yaml Matcher m = GAPIC_YAML_TYPE.matcher(fileBody); @@ -286,6 +294,11 @@ void parseYamlFile(String fileName, String fileBody) { if (fileBody.contains(LOCATIONS_MIXIN)) { this.containsLocations = true; } + + // API Serivce config has IAMPolicy API. + if (fileBody.contains(IAM_POLICY_MIXIN)) { + this.containsIAMPolicy = true; + } } } @@ -428,5 +441,8 @@ void injectFieldsFromTopLevel() { boolean topLevelContainsLocations = parent.getContainsLocations().getOrDefault(version, false); containsLocations = topLevelContainsLocations ? topLevelContainsLocations : containsLocations; + + boolean topLevelContainsIAMPolicy = parent.getContainsIAMPolicy().getOrDefault(version, false); + containsIAMPolicy = topLevelContainsIAMPolicy ? topLevelContainsIAMPolicy : containsIAMPolicy; } } 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 e4d371b..afe5bd9 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 @@ -136,6 +136,14 @@ class BazelBuildFileView { "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 String protoPkg = bp.getProtoPackage(); boolean isCloud = bp.getCloudScope() || protoPkg.contains("cloud"); diff --git a/bazel/src/test/data/googleapis/google/example/library/library_example_v1.yaml b/bazel/src/test/data/googleapis/google/example/library/library_example_v1.yaml index 7483aaa..6ee74cf 100644 --- a/bazel/src/test/data/googleapis/google/example/library/library_example_v1.yaml +++ b/bazel/src/test/data/googleapis/google/example/library/library_example_v1.yaml @@ -20,6 +20,7 @@ title: Example Library API apis: - name: google.example.library.v1.LibraryService - name: google.cloud.location.Locations +- name: google.iam.v1.IAMPolicy documentation: summary: A simple Google Example Library API. 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 089b38a..50c1685 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 @@ -137,6 +137,7 @@ go_gapic_library( ":library_go_proto", "//google/api:httpbody_go_proto", "//google/cloud/location:location_go_proto", + "//google/iam/v1:iam_go_proto", ], ) diff --git a/bazel/src/test/data/googleapis/google/example/library/v1/library_example_v1.yaml b/bazel/src/test/data/googleapis/google/example/library/v1/library_example_v1.yaml index 7483aaa..6ee74cf 100644 --- a/bazel/src/test/data/googleapis/google/example/library/v1/library_example_v1.yaml +++ b/bazel/src/test/data/googleapis/google/example/library/v1/library_example_v1.yaml @@ -20,6 +20,7 @@ title: Example Library API apis: - name: google.example.library.v1.LibraryService - name: google.cloud.location.Locations +- name: google.iam.v1.IAMPolicy documentation: summary: A simple Google Example Library API. 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 cae434b..486409d 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 @@ -137,6 +137,7 @@ go_gapic_library( ":library_go_proto", "//google/api:httpbody_go_proto", "//google/cloud/location:location_go_proto", + "//google/iam/v1:iam_go_proto", ], )