aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar elenairina <elenairina@google.com>2018-02-27 08:28:59 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-27 08:31:51 -0800
commit98ed9af727ec6342206d181fcd465e3e83980c52 (patch)
treecc222a83217b8f3558c2acc2502a5c5ace428bc7
parent19c64284fb33372bd1a9185e0e8bb2a7b32265a1 (diff)
Expose ProtoSourcesProvider.transitive_proto_path_flags to Skylark.
Progress on #4544. RELNOTES: None. PiperOrigin-RevId: 187179454
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java11
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java8
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSourcesProvider.java9
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/proto/SupportData.java4
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryTest.java12
5 files changed, 27 insertions, 17 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java
index 374b534cd9..a86bdda6dc 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java
@@ -100,29 +100,28 @@ public class ProtoCommon {
}
/**
- * Returns all proto source roots in this lib and in its transitive dependencies, each prefixed
- * by {@code --proto_path}.
+ * Returns all proto source roots in this lib and in its transitive dependencies.
*
* Build will fail if the {@code proto_source_root} of the current lib is different than the
* package name.
*/
public static NestedSet<String> collectTransitiveProtoPathFlags(RuleContext ruleContext) {
- NestedSetBuilder<String> protoPathFlags = NestedSetBuilder.stableOrder();
+ NestedSetBuilder<String> protoPath = NestedSetBuilder.stableOrder();
// first add the protoSourceRoot of the current target, if any
String protoSourceRoot =
ruleContext.attributes().get("proto_source_root", Type.STRING);
if (protoSourceRoot != null && !protoSourceRoot.isEmpty()) {
checkProtoSourceRootIsTheSameAsPackage(protoSourceRoot, ruleContext);
- protoPathFlags.add("--proto_path=" + protoSourceRoot);
+ protoPath.add(protoSourceRoot);
}
for (ProtoSourcesProvider provider : ruleContext.getPrerequisites(
"deps", Mode.TARGET, ProtoSourcesProvider.class)) {
- protoPathFlags.addTransitive(provider.getTransitiveProtoPathFlags());
+ protoPath.addTransitive(provider.getTransitiveProtoPathFlags());
}
- return protoPathFlags.build();
+ return protoPath.build();
}
private static void checkProtoSourceRootIsTheSameAsPackage(
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java
index 374bf9b9fe..6fdcc040f0 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java
@@ -530,7 +530,9 @@ public class ProtoCompileActionBuilder {
ImmutableList<String> protocOpts) {
CustomCommandLine.Builder cmdLine = CustomCommandLine.builder();
- cmdLine.addAll(transitiveProtoPathFlags);
+ cmdLine.addAll(
+ VectorArg.of(transitiveProtoPathFlags)
+ .mapped(ProtoCompileActionBuilder::expandTransitiveProtoPathFlags));
// A set to check if there are multiple invocations with the same name.
HashSet<String> invocationNames = new HashSet<>();
@@ -604,6 +606,10 @@ public class ProtoCompileActionBuilder {
}
}
+ private static void expandTransitiveProtoPathFlags(String flag, Consumer<String> args) {
+ args.accept("--proto_path=" + flag);
+ }
+
private static void expandTransitiveImportArg(Artifact artifact, Consumer<String> args) {
args.accept("-I" + getPathIgnoringRepository(artifact) + "=" + artifact.getExecPathString());
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSourcesProvider.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSourcesProvider.java
index a4b5765176..48158ba420 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSourcesProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSourcesProvider.java
@@ -133,9 +133,14 @@ public abstract class ProtoSourcesProvider implements TransitiveInfoProvider {
public abstract NestedSet<Artifact> transitiveDescriptorSets();
/**
- * Directories of .proto sources collected from the transitive closure, each prefixed with
- * {@code --proto_path}. These flags will be passed to {@code protoc} in the specified oreder.
+ * Directories of .proto sources collected from the transitive closure. These flags will be passed
+ * to {@code protoc} in the specified order, via the {@code --proto_path} flag.
*/
+ @SkylarkCallable(
+ name = "transitive_proto_path",
+ doc = "A set of proto source roots collected from the transitive closure of this rule.",
+ structField = true
+ )
public abstract NestedSet<String> getTransitiveProtoPathFlags();
ProtoSourcesProvider() {}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/SupportData.java b/src/main/java/com/google/devtools/build/lib/rules/proto/SupportData.java
index 9e02d190d5..924b8c87b6 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/SupportData.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/SupportData.java
@@ -52,8 +52,8 @@ public abstract class SupportData {
public abstract NestedSet<Artifact> getProtosInDirectDeps();
/**
- * Directories of .proto sources collected from the transitive closure, each prefixed with
- * {@code --proto_path}. These flags will be passed to {@code protoc} in the specified oreder.
+ * Directories of .proto sources collected from the transitive closure. These flags will be passed
+ * to {@code protoc} in the specified order, via the {@code --proto_path} flag.
*/
public abstract NestedSet<String> getTransitiveProtoPathFlags();
diff --git a/src/test/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryTest.java
index 7e283a546f..51484ae952 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryTest.java
@@ -251,11 +251,11 @@ public class BazelProtoLibraryTest extends BuildViewTestCase {
);
ConfiguredTarget protoTarget = getConfiguredTarget("//x/foo:nodeps");
ProtoSourcesProvider sourcesProvider = protoTarget.getProvider(ProtoSourcesProvider.class);
- assertThat(sourcesProvider.getTransitiveProtoPathFlags()).containsExactly("--proto_path=x/foo");
+ assertThat(sourcesProvider.getTransitiveProtoPathFlags()).containsExactly("x/foo");
SupportData supportData =
protoTarget.getProvider(ProtoSupportDataProvider.class).getSupportData();
- assertThat(supportData.getTransitiveProtoPathFlags()).containsExactly("--proto_path=x/foo");
+ assertThat(supportData.getTransitiveProtoPathFlags()).containsExactly("x/foo");
assertThat(getGeneratingSpawnAction(getDescriptorOutput("//x/foo:nodeps"))
.getRemainingArguments())
@@ -304,11 +304,11 @@ public class BazelProtoLibraryTest extends BuildViewTestCase {
);
ConfiguredTarget protoTarget = getConfiguredTarget("//x/foo:withdeps");
ProtoSourcesProvider sourcesProvider = protoTarget.getProvider(ProtoSourcesProvider.class);
- assertThat(sourcesProvider.getTransitiveProtoPathFlags()).containsExactly("--proto_path=x/foo");
+ assertThat(sourcesProvider.getTransitiveProtoPathFlags()).containsExactly("x/foo");
SupportData supportData =
protoTarget.getProvider(ProtoSupportDataProvider.class).getSupportData();
- assertThat(supportData.getTransitiveProtoPathFlags()).containsExactly("--proto_path=x/foo");
+ assertThat(supportData.getTransitiveProtoPathFlags()).containsExactly("x/foo");
assertThat(getGeneratingSpawnAction(getDescriptorOutput("//x/foo:withdeps"))
.getRemainingArguments())
@@ -342,12 +342,12 @@ public class BazelProtoLibraryTest extends BuildViewTestCase {
ConfiguredTarget protoTarget = getConfiguredTarget("//x/foo:withdeps");
ProtoSourcesProvider sourcesProvider = protoTarget.getProvider(ProtoSourcesProvider.class);
assertThat(sourcesProvider.getTransitiveProtoPathFlags())
- .containsExactly("--proto_path=x/foo", "--proto_path=x/bar");
+ .containsExactly("x/foo", "x/bar");
SupportData supportData =
protoTarget.getProvider(ProtoSupportDataProvider.class).getSupportData();
assertThat(supportData.getTransitiveProtoPathFlags())
- .containsExactly("--proto_path=x/foo", "--proto_path=x/bar");
+ .containsExactly("x/foo", "x/bar");
assertThat(getGeneratingSpawnAction(getDescriptorOutput("//x/foo:withdeps"))
.getRemainingArguments())