From 1a62038b41919bdf34d3a3b83e22a0e73de3d3f9 Mon Sep 17 00:00:00 2001 From: Mira Leung Date: Thu, 25 Mar 2021 17:31:46 -0700 Subject: [PATCH] fix(gapic): generate gapic build on seeing service.yaml or grpc_service_config.json (#37) --- .../main/java/com/google/api/codegen/bazel/ApisVisitor.java | 4 +++- .../com/google/api/codegen/bazel/BazelBuildFileView.java | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/bazel/src/main/java/com/google/api/codegen/bazel/ApisVisitor.java b/bazel/src/main/java/com/google/api/codegen/bazel/ApisVisitor.java index 2911e90..5f4bca5 100644 --- a/bazel/src/main/java/com/google/api/codegen/bazel/ApisVisitor.java +++ b/bazel/src/main/java/com/google/api/codegen/bazel/ApisVisitor.java @@ -137,7 +137,9 @@ public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOExce BazelBuildFileTemplate template = null; String tmplType = ""; if (bp.getProtoPackage() != null) { - if (bp.getGapicYamlPath() != null) { + boolean isGapicLibrary = + bp.getServiceYamlPath() != null || bp.getServiceConfigJsonPath() != null; + if (isGapicLibrary) { bp.injectFieldsFromTopLevel(); template = this.gapicApiTempl; tmplType = "GAPIC_VERSIONED"; 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 80f9b76..3fbe649 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 @@ -62,7 +62,9 @@ class BazelBuildFileView { tokens.put("go_proto_importpath", bp.getLangProtoPackages().get("go").split(";")[0]); tokens.put("go_proto_deps", joinSetWithIndentation(mapGoProtoDeps(actualImports))); - if (bp.getGapicYamlPath() == null) { + boolean isGapicLibrary = + bp.getServiceYamlPath() != null || bp.getServiceConfigJsonPath() != null; + if (!isGapicLibrary) { return; } @@ -209,7 +211,7 @@ private Set mapJavaGapicDeps(Set protoImports) { private Set mapJavaGapicTestDeps(Set protoImports) { Set javaImports = new TreeSet<>(); for (String protoImport : protoImports) { - if (protoImport.endsWith(":iam_policy_proto") + if (protoImport.endsWith(":iam_policy_proto") || protoImport.endsWith(":policy_proto") || protoImport.endsWith(":options_proto")) { javaImports.add(replaceLabelName(protoImport, ":iam_java_grpc"));