aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar Carmi Grushko <carmi@google.com>2016-11-18 21:15:55 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-11-21 19:39:08 +0000
commit49473f9e25aa610d6d4022e2c3e93828c9a8970a (patch)
tree370bdd099594759b4eca16be5ed3c2c42134842d /src/main/java
parente860316559eac366d47923a8eb4b5489a661aa35 (diff)
ProtoCompileActionBuilder can create strict-deps-checking command lines.
No behavior changes, for now. -- MOS_MIGRATED_REVID=139614509
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java1
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java27
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/proto/SupportData.java12
3 files changed, 34 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java
index f98de01ef9..7819f13d22 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibrary.java
@@ -54,6 +54,7 @@ public class BazelProtoLibrary implements RuleConfiguredTargetFactory {
SupportData.create(
Predicates.<TransitiveInfoCollection>alwaysTrue() /* nonWeakDepsPredicate */,
protoSources,
+ null /* protosInDirectDeps */,
transitiveImports,
!protoSources.isEmpty());
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 951ba048b6..51d86fe7d9 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
@@ -37,6 +37,7 @@ import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.util.LazyString;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -285,7 +286,9 @@ public class ProtoCompileActionBuilder {
result.add(ruleContext.getFragment(ProtoConfiguration.class).protocOpts());
// Add include maps
- result.add(new ProtoCommandLineArgv(supportData.getTransitiveImports()));
+ result.add(
+ new ProtoCommandLineArgv(
+ null /* protosInDirectDependencies */, supportData.getTransitiveImports()));
for (Artifact src : supportData.getDirectProtoSources()) {
result.addPath(src.getRootRelativePath());
@@ -306,10 +309,15 @@ public class ProtoCompileActionBuilder {
* Static inner class since these objects live into the execution phase and so they must not keep
* alive references to the surrounding analysis-phase objects.
*/
- private static class ProtoCommandLineArgv extends CustomCommandLine.CustomMultiArgv {
+ @VisibleForTesting
+ static class ProtoCommandLineArgv extends CustomCommandLine.CustomMultiArgv {
+ @Nullable private final Iterable<Artifact> protosInDirectDependencies;
private final Iterable<Artifact> transitiveImports;
- ProtoCommandLineArgv(Iterable<Artifact> transitiveImports) {
+ ProtoCommandLineArgv(
+ @Nullable Iterable<Artifact> protosInDirectDependencies,
+ Iterable<Artifact> transitiveImports) {
+ this.protosInDirectDependencies = protosInDirectDependencies;
this.transitiveImports = transitiveImports;
}
@@ -320,6 +328,13 @@ public class ProtoCompileActionBuilder {
builder.add(
"-I" + artifact.getRootRelativePathString() + "=" + artifact.getExecPathString());
}
+ if (protosInDirectDependencies != null) {
+ ArrayList<String> rootRelativePaths = new ArrayList<>();
+ for (Artifact directDependency : protosInDirectDependencies) {
+ rootRelativePaths.add(directDependency.getRootRelativePathString());
+ }
+ builder.add("--direct_dependencies=" + Joiner.on(":").join(rootRelativePaths));
+ }
return builder.build();
}
}
@@ -425,6 +440,8 @@ public class ProtoCompileActionBuilder {
* Note {@code toolchainInvocations} is ordered, and affects the order in which plugins are
* called. As some plugins rely on output from other plugins, their order matters.
*
+ * @param toolchainInvocations See {@link #createCommandLineFromToolchains}.
+ * @param allowServices If false, the compilation will break if any .proto file has service
* @return a command-line to pass to proto-compiler.
*/
@VisibleForTesting
@@ -470,7 +487,9 @@ public class ProtoCompileActionBuilder {
cmdLine.add(protocOpts);
// Add include maps
- cmdLine.add(new ProtoCommandLineArgv(supportData.getTransitiveImports()));
+ cmdLine.add(
+ new ProtoCommandLineArgv(
+ supportData.getProtosInDirectDeps(), supportData.getTransitiveImports()));
for (Artifact src : supportData.getDirectProtoSources()) {
cmdLine.addPath(src.getRootRelativePath());
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 762af4f7a3..4da9f2acfe 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
@@ -21,7 +21,7 @@ import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-
+import javax.annotation.Nullable;
/**
* A helper class for the *Support classes containing some data from ProtoLibrary.
@@ -32,10 +32,11 @@ public abstract class SupportData {
public static SupportData create(
Predicate<TransitiveInfoCollection> nonWeakDepsPredicate,
ImmutableList<Artifact> protoSources,
+ @Nullable NestedSet<Artifact> protosInDirectDeps,
NestedSet<Artifact> transitiveImports,
boolean hasProtoSources) {
return new AutoValue_SupportData(
- nonWeakDepsPredicate, protoSources, transitiveImports, hasProtoSources);
+ nonWeakDepsPredicate, protoSources, transitiveImports, protosInDirectDeps, hasProtoSources);
}
public abstract Predicate<TransitiveInfoCollection> getNonWeakDepsPredicate();
@@ -44,6 +45,13 @@ public abstract class SupportData {
public abstract NestedSet<Artifact> getTransitiveImports();
+ /**
+ * .proto files in the direct dependencies of this proto_library. Used for strict deps checking.
+ * <code>null</code> means "strict deps checking is off".
+ */
+ @Nullable
+ public abstract NestedSet<Artifact> getProtosInDirectDeps();
+
public abstract boolean hasProtoSources();
SupportData() {}