diff options
author | laszlocsomor <laszlocsomor@google.com> | 2018-04-23 01:15:01 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-04-23 01:16:27 -0700 |
commit | 84d3097537f045a78baaebc3c6f2ffef4d814cb5 (patch) | |
tree | 6c90c6ea794b916c57d696e0487ee0a7f4c8d014 /src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java | |
parent | d91974e8c55a1670e332920fa51512cb237d4f9e (diff) |
SpawnAction.setShellCommand: expect shell path
SpawnAction.setShellCommand(String) now expects
the shell interpreter's path as an argument. This
change enables two things:
- rules can report an error if the shell is
missing
- SpawnAction no longer has to know about a
default shell
The new ShToolchain class will later also be
responsible for retrieving the active shell
toolchain (added in https://github.com/bazelbuild/bazel/commit/81ed3add408adb20bddbc3ba1818c65806738dc5).
This change brings Bazel closer to not depend on
the shell unless it has to (e.g. to run shell
scripts).
See https://github.com/bazelbuild/bazel/issues/4319
RELNOTES: none
PiperOrigin-RevId: 193885943
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java index 8f9e18aa97..c9a5a2dddc 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java @@ -56,7 +56,6 @@ import com.google.devtools.build.lib.actions.extra.ExtraActionInfo; import com.google.devtools.build.lib.actions.extra.SpawnInfo; import com.google.devtools.build.lib.analysis.AnalysisEnvironment; import com.google.devtools.build.lib.analysis.FilesToRunProvider; -import com.google.devtools.build.lib.analysis.ShellConfiguration; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.collect.nestedset.NestedSet; @@ -680,8 +679,7 @@ public class SpawnAction extends AbstractAction implements ExecutionInfoSpecifie AnalysisEnvironment analysisEnvironment, BuildConfiguration configuration, List<Action> paramFileActions) { - ImmutableList<String> executableArgs = buildExecutableArgs( - configuration.getFragment(ShellConfiguration.class).getShellExecutable()); + ImmutableList<String> executableArgs = buildExecutableArgs(); boolean hasConditionalParamFile = commandLines.stream().anyMatch(c -> c.paramFileInfo != null && !c.paramFileInfo.always()); boolean spillToParamFiles = false; @@ -812,7 +810,7 @@ public class SpawnAction extends AbstractAction implements ExecutionInfoSpecifie */ CommandLine buildCommandLineWithoutParamsFiles() { SpawnActionCommandLine.Builder result = new SpawnActionCommandLine.Builder(); - ImmutableList<String> executableArgs = buildExecutableArgs(null); + ImmutableList<String> executableArgs = buildExecutableArgs(); result.addExecutableArguments(executableArgs); for (CommandLineAndParamFileInfo commandLineAndParamFileInfo : commandLines) { result.addCommandLine(commandLineAndParamFileInfo.commandLine); @@ -851,12 +849,7 @@ public class SpawnAction extends AbstractAction implements ExecutionInfoSpecifie extraActionInfoSupplier); } - private ImmutableList<String> buildExecutableArgs( - @Nullable PathFragment defaultShellExecutable) { - if (isShellCommand && executable == null) { - Preconditions.checkNotNull(defaultShellExecutable); - executable = defaultShellExecutable; - } + private ImmutableList<String> buildExecutableArgs() { Preconditions.checkNotNull(executable); Preconditions.checkNotNull(executableArgs); @@ -1119,18 +1112,16 @@ public class SpawnAction extends AbstractAction implements ExecutionInfoSpecifie } /** - * Sets the executable to be the shell and adds the given command as the - * command to be executed. + * Sets the executable to be the shell and adds the given command as the command to be executed. * - * <p>Note that this will not clear the arguments, so any arguments will - * be passed in addition to the command given here. + * <p>Note that this will not clear the arguments, so any arguments will be passed in addition + * to the command given here. * - * <p>Calling this method overrides any previous values set via calls to - * {@link #setExecutable(Artifact)}, {@link #setJavaExecutable}, or - * {@link #setShellCommand(String)}. + * <p>Calling this method overrides any previous values set via calls to {@link + * #setExecutable(Artifact)}, {@link #setJavaExecutable}, or {@link #setShellCommand(String)}. */ - public Builder setShellCommand(String command) { - this.executable = null; + public Builder setShellCommand(PathFragment shExecutable, String command) { + this.executable = shExecutable; // 0=shell command switch, 1=command this.executableArgs = Lists.newArrayList("-c", command); this.isShellCommand = true; |