aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2018-04-26 04:44:47 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-26 04:46:00 -0700
commit425156edd865a554ef33af855dc8e4bd29160607 (patch)
treef835163d94e053d9540e04be05dfdf93a9739653 /src/test/java/com/google/devtools/build
parent9f3825f97dffbbaa5d0a1f78c51cea87c2eb577c (diff)
Prepare to abstract away the param file write action from tests.
Rule authors frequently wants to make assertions on the parameter files their rule implementations have created. However, if they do not explicitly create parameter file write actions, or if indeed _there aren't_ any parameter file write actions inserted into the action graph, the tests will fail. This CL adds necessary methods for the migration. RELNOTES: None PiperOrigin-RevId: 194379748
Diffstat (limited to 'src/test/java/com/google/devtools/build')
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java68
1 files changed, 59 insertions, 9 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
index 6a2d37d3db..785462a097 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
@@ -41,6 +41,8 @@ import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander;
import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact;
import com.google.devtools.build.lib.actions.ArtifactOwner;
import com.google.devtools.build.lib.actions.ArtifactRoot;
+import com.google.devtools.build.lib.actions.CommandAction;
+import com.google.devtools.build.lib.actions.CommandLine;
import com.google.devtools.build.lib.actions.CommandLineExpansionException;
import com.google.devtools.build.lib.actions.MapBasedActionGraph;
import com.google.devtools.build.lib.actions.MiddlemanFactory;
@@ -655,17 +657,65 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
return skyframeExecutor.getActionGraph(reporter);
}
+ /** Locates the first parameter file used by the action and returns its command line. */
+ @Nullable
+ protected final CommandLine paramFileCommandLineForAction(Action action) {
+ ParameterFileWriteAction parameterFileWriteAction = paramFileWriteActionForAction(action);
+ return parameterFileWriteAction != null ? parameterFileWriteAction.getCommandLine() : null;
+ }
+
+ /** Locates the first parameter file used by the action and returns its args. */
+ @Nullable
+ protected final Iterable<String> paramFileArgsForAction(Action action)
+ throws CommandLineExpansionException {
+ ParameterFileWriteAction parameterFileWriteAction = paramFileWriteActionForAction(action);
+ return parameterFileWriteAction != null
+ ? parameterFileWriteAction.getCommandLine().arguments()
+ : null;
+ }
+
+ /**
+ * Locates the first parameter file used by the action and returns its args.
+ *
+ * <p>If no param file is used, return the action's arguments.
+ */
+ @Nullable
+ protected final Iterable<String> paramFileArgsOrActionArgs(CommandAction action)
+ throws CommandLineExpansionException {
+ ParameterFileWriteAction parameterFileWriteAction = paramFileWriteActionForAction(action);
+ return parameterFileWriteAction != null
+ ? parameterFileWriteAction.getCommandLine().arguments()
+ : action.getArguments();
+ }
+
+ /** Locates the first parameter file used by the action and returns its contents. */
+ @Nullable
+ protected final String paramFileStringContentsForAction(Action action)
+ throws CommandLineExpansionException, IOException {
+ ParameterFileWriteAction parameterFileWriteAction = paramFileWriteActionForAction(action);
+ return parameterFileWriteAction != null ? parameterFileWriteAction.getStringContents() : null;
+ }
+
+ // TODO(b/37444705): Remove this method
+ @Deprecated
@Nullable
protected final ParameterFileWriteAction findParamsFileAction(SpawnAction spawnAction) {
- for (Artifact input : spawnAction.getInputs()) {
- Action generatingAction = getGeneratingAction(input);
- if (generatingAction instanceof ParameterFileWriteAction) {
- return (ParameterFileWriteAction) generatingAction;
+ return paramFileWriteActionForAction(spawnAction);
+ }
+
+ @Nullable
+ private ParameterFileWriteAction paramFileWriteActionForAction(Action action) {
+ for (Artifact input : action.getInputs()) {
+ if (!(input instanceof SpecialArtifact)) {
+ Action generatingAction = getGeneratingAction(input);
+ if (generatingAction instanceof ParameterFileWriteAction) {
+ return (ParameterFileWriteAction) generatingAction;
+ }
}
}
return null;
}
-
+
protected final ActionAnalysisMetadata getGeneratingActionAnalysisMetadata(Artifact artifact) {
Preconditions.checkNotNull(artifact);
ActionAnalysisMetadata actionAnalysisMetadata =
@@ -729,10 +779,10 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
protected final List<String> getGeneratingSpawnActionArgs(Artifact artifact)
throws CommandLineExpansionException {
SpawnAction a = getGeneratingSpawnAction(artifact);
- ParameterFileWriteAction p = findParamsFileAction(a);
- return p == null
- ? a.getArguments()
- : ImmutableList.copyOf(Iterables.concat(a.getArguments(), p.getContents()));
+ Iterable<String> paramFileArgs = paramFileArgsForAction(a);
+ return paramFileArgs != null
+ ? ImmutableList.copyOf(Iterables.concat(a.getArguments(), paramFileArgs))
+ : a.getArguments();
}
protected ActionsTestUtil actionsTestUtil() {