Skip to content

Commit

Permalink
fix(bazel): iam/location mixin java deps (#89)
Browse files Browse the repository at this point in the history
Fixes java mixin dependency generation in bazel targets. The generated deps are based on the existing PubSub & KMS targets that have mixins today.
  • Loading branch information
noahdietz committed Nov 16, 2021
1 parent e23c181 commit 965fe25
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,17 @@ class BazelBuildFileView {
Set<String> extraProtosNodeJS = new TreeSet<>();
Set<String> 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<String> actualImports = new TreeSet<>();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -245,26 +242,13 @@ private Set<String> mapJavaGapicDeps(Set<String> 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"));
}
}
return javaImports;
}

private Set<String> mapJavaGapicAssemblyPkgDeps(Set<String> protoImports) {
Set<String> 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<String> mapJavaGapicTestDeps(Set<String> protoImports) {
Set<String> javaImports = new TreeSet<>();
for (String protoImport : protoImports) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down Expand Up @@ -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",
],
)

Expand All @@ -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",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down Expand Up @@ -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",
],
)

Expand All @@ -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",
],
)

Expand Down

0 comments on commit 965fe25

Please sign in to comment.