aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
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/main/java/com/google/devtools
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/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/actions/ParameterFileWriteAction.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/ParameterFileWriteAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/ParameterFileWriteAction.java
index 8efc38e987..694806d590 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/ParameterFileWriteAction.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/ParameterFileWriteAction.java
@@ -33,6 +33,7 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
import com.google.devtools.build.lib.util.Fingerprint;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
@@ -89,12 +90,17 @@ public final class ParameterFileWriteAction extends AbstractFileWriteAction {
this.hasInputArtifactToExpand = !Iterables.isEmpty(inputs);
}
+ @VisibleForTesting
+ public CommandLine getCommandLine() {
+ return commandLine;
+ }
+
/**
* Returns the list of options written to the parameter file. Don't use this method outside tests
* - the list is often huge, resulting in significant garbage collection overhead.
*/
@VisibleForTesting
- public Iterable<String> getContents() throws CommandLineExpansionException {
+ public Iterable<String> getArguments() throws CommandLineExpansionException {
Preconditions.checkState(
!hasInputArtifactToExpand,
"This action contains a CommandLine with TreeArtifacts: %s, which must be expanded using "
@@ -104,6 +110,22 @@ public final class ParameterFileWriteAction extends AbstractFileWriteAction {
}
@VisibleForTesting
+ public String getStringContents() throws CommandLineExpansionException, IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ParameterFile.writeParameterFile(out, getArguments(), type, charset);
+ return new String(out.toByteArray(), charset);
+ }
+
+ // TODO(37444705): Remove method at end of migration.
+ @VisibleForTesting
+ @Deprecated
+ public Iterable<String> getContents() throws CommandLineExpansionException {
+ return getArguments();
+ }
+
+ // TODO(37444705): Remove method at end of migration.
+ @VisibleForTesting
+ @Deprecated
public Iterable<String> getContents(ArtifactExpander artifactExpander)
throws CommandLineExpansionException {
return commandLine.arguments(artifactExpander);