diff options
author | Googler <noreply@google.com> | 2018-05-18 05:15:04 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-05-18 05:17:01 -0700 |
commit | e854c86bde5af363e03b87dcf46e629dce694c17 (patch) | |
tree | 2e7f8a16843c9b66dea9b3e5593069b7b2f06507 /src/main/java | |
parent | 8f71324e2a73e45f42909061a3919f7cdcb85eed (diff) |
Changing SymlinkTreeStrategy not to use spawns.
RELNOTES: An internal action for symlinking runfiles will use Command instead of a Spawns. This should have no functional chages; the only user visible consequence should be that the internal action is no longer be included in statistics when calculating processes count.
PiperOrigin-RevId: 197131917
Diffstat (limited to 'src/main/java')
6 files changed, 31 insertions, 59 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/SymlinkTreeAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/SymlinkTreeAction.java index 87e2130b86..10a30d8d9f 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/actions/SymlinkTreeAction.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/SymlinkTreeAction.java @@ -102,9 +102,9 @@ public final class SymlinkTreeAction extends AbstractAction { @Override public ActionResult execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException { - return ActionResult.create( - actionExecutionContext - .getContext(SymlinkTreeActionContext.class) - .createSymlinks(this, actionExecutionContext, shellEnvironment, enableRunfiles)); + actionExecutionContext + .getContext(SymlinkTreeActionContext.class) + .createSymlinks(this, actionExecutionContext, shellEnvironment, enableRunfiles); + return ActionResult.EMPTY; } } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/SymlinkTreeActionContext.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/SymlinkTreeActionContext.java index 449a0cc572..be6c9911cf 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/actions/SymlinkTreeActionContext.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/SymlinkTreeActionContext.java @@ -17,8 +17,6 @@ import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.actions.ActionContext; import com.google.devtools.build.lib.actions.ActionExecutionContext; import com.google.devtools.build.lib.actions.ActionExecutionException; -import com.google.devtools.build.lib.actions.SpawnResult; -import java.util.List; /** * Action context for symlink tree actions (an action that creates a tree of symlinks). @@ -30,7 +28,7 @@ public interface SymlinkTreeActionContext extends ActionContext { * * @return a list of SpawnResults created during symlink creation, if any */ - List<SpawnResult> createSymlinks( + void createSymlinks( SymlinkTreeAction action, ActionExecutionContext actionExecutionContext, ImmutableMap<String, String> shellEnvironment, diff --git a/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeHelper.java b/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeHelper.java index 5f231e4fd0..bd00f38500 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeHelper.java +++ b/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeHelper.java @@ -21,15 +21,12 @@ import com.google.common.collect.Lists; import com.google.devtools.build.lib.actions.ActionExecutionContext; import com.google.devtools.build.lib.actions.ActionExecutionMetadata; import com.google.devtools.build.lib.actions.ActionInput; -import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.ExecException; import com.google.devtools.build.lib.actions.ExecutionRequirements; import com.google.devtools.build.lib.actions.ResourceSet; import com.google.devtools.build.lib.actions.SimpleSpawn; import com.google.devtools.build.lib.actions.Spawn; -import com.google.devtools.build.lib.actions.SpawnResult; import com.google.devtools.build.lib.actions.UserExecException; -import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.shell.CommandException; import com.google.devtools.build.lib.util.CommandBuilder; import com.google.devtools.build.lib.util.OsUtils; @@ -63,8 +60,8 @@ public final class SymlinkTreeHelper { * * @param inputManifest exec path to the input runfiles manifest * @param symlinkTreeRoot the root of the symlink tree to be created - * @param filesetTree true if this is fileset symlink tree, - * false if this is a runfiles symlink tree. + * @param filesetTree true if this is fileset symlink tree, false if this is a runfiles symlink + * tree. */ public SymlinkTreeHelper(Path inputManifest, Path symlinkTreeRoot, boolean filesetTree) { this.inputManifest = inputManifest; @@ -80,20 +77,23 @@ public final class SymlinkTreeHelper { * Creates a symlink tree using a CommandBuilder. This means that the symlink tree will always be * present on the developer's workstation. Useful when running commands locally. * - * Warning: this method REALLY executes the command on the box Bazel is running on, without any + * <p>Warning: this method REALLY executes the command on the box Bazel is running on, without any * kind of synchronization, locking, or anything else. * * @param config the configuration that is used for creating the symlink tree. * @throws CommandException */ public void createSymlinksUsingCommand( - Path execRoot, BuildConfiguration config, BinTools binTools) - throws CommandException { + Path execRoot, BinTools binTools, ImmutableMap<String, String> shellEnvironment) + throws CommandException { List<String> argv = getSpawnArgumentList(execRoot, binTools.getExecPath(BUILD_RUNFILES)); - CommandBuilder builder = new CommandBuilder(); - builder.addArgs(argv); - builder.setWorkingDir(execRoot); - builder.build().execute(); + Preconditions.checkNotNull(shellEnvironment); + new CommandBuilder() + .addArgs(argv) + .setWorkingDir(execRoot) + .setEnv(shellEnvironment) + .build() + .execute(); } /** @@ -105,27 +105,19 @@ public final class SymlinkTreeHelper { * @param enableRunfiles * @return a list of SpawnResults created during symlink creation, if any */ - public List<SpawnResult> createSymlinks( - ActionExecutionMetadata owner, + public void createSymlinks( ActionExecutionContext actionExecutionContext, BinTools binTools, ImmutableMap<String, String> shellEnvironment, - Artifact inputManifestArtifact, boolean enableRunfiles) - throws ExecException, InterruptedException { - Preconditions.checkState( - actionExecutionContext.getInputPath(inputManifestArtifact).equals(inputManifest)); + throws ExecException { if (enableRunfiles) { - Spawn spawn = - createSpawn( - owner, - actionExecutionContext.getExecRoot(), - binTools, - shellEnvironment, - inputManifestArtifact); - return actionExecutionContext - .getSpawnActionContext(spawn) - .exec(spawn, actionExecutionContext); + try { + createSymlinksUsingCommand( + actionExecutionContext.getExecRoot(), binTools, shellEnvironment); + } catch (CommandException e) { + throw new UserExecException(e.getMessage(), e); + } } else { // Pretend we created the runfiles tree by copying the manifest try { @@ -134,7 +126,6 @@ public final class SymlinkTreeHelper { } catch (IOException e) { throw new UserExecException(e.getMessage(), e); } - return ImmutableList.of(); } } @@ -159,9 +150,7 @@ public final class SymlinkTreeHelper { RESOURCE_SET); } - /** - * Returns the complete argument list build-runfiles has to be called with. - */ + /** Returns the complete argument list build-runfiles has to be called with. */ private ImmutableList<String> getSpawnArgumentList(Path execRoot, PathFragment buildRunfiles) { List<String> args = Lists.newArrayList(); args.add(buildRunfiles.getPathString()); diff --git a/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeStrategy.java index d672798e2c..82b24eca1a 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeStrategy.java @@ -13,18 +13,15 @@ // limitations under the License. package com.google.devtools.build.lib.exec; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.actions.ActionExecutionContext; import com.google.devtools.build.lib.actions.ActionExecutionException; import com.google.devtools.build.lib.actions.ExecException; import com.google.devtools.build.lib.actions.ExecutionStrategy; -import com.google.devtools.build.lib.actions.SpawnResult; import com.google.devtools.build.lib.analysis.actions.SymlinkTreeAction; import com.google.devtools.build.lib.analysis.actions.SymlinkTreeActionContext; import com.google.devtools.build.lib.profiler.AutoProfiler; import com.google.devtools.build.lib.skyframe.OutputService; -import java.util.List; import java.util.logging.Logger; /** @@ -44,7 +41,7 @@ public final class SymlinkTreeStrategy implements SymlinkTreeActionContext { } @Override - public List<SpawnResult> createSymlinks( + public void createSymlinks( SymlinkTreeAction action, ActionExecutionContext actionExecutionContext, ImmutableMap<String, String> shellEnvironment, @@ -60,7 +57,6 @@ public final class SymlinkTreeStrategy implements SymlinkTreeActionContext { actionExecutionContext.getInputPath(action.getOutputManifest()), action.isFilesetTree(), action.getOutputManifest().getExecPath().getParentDirectory()); - return ImmutableList.of(); } else { SymlinkTreeHelper helper = new SymlinkTreeHelper( @@ -69,13 +65,7 @@ public final class SymlinkTreeStrategy implements SymlinkTreeActionContext { .getInputPath(action.getOutputManifest()) .getParentDirectory(), action.isFilesetTree()); - return helper.createSymlinks( - action, - actionExecutionContext, - binTools, - shellEnvironment, - action.getInputManifest(), - enableRunfiles); + helper.createSymlinks(actionExecutionContext, binTools, shellEnvironment, enableRunfiles); } } catch (ExecException e) { throw e.toActionExecutionException( diff --git a/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java index ae65551927..fcd21ea316 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java @@ -409,13 +409,7 @@ public abstract class TestStrategy implements TestActionContext { actionExecutionContext.getInputPath(execSettings.getInputManifest()), runfilesDir, false) - .createSymlinks( - testAction, - actionExecutionContext, - binTools, - shellEnvironment, - execSettings.getInputManifest(), - enableRunfiles); + .createSymlinks(actionExecutionContext, binTools, shellEnvironment, enableRunfiles); actionExecutionContext.getEventHandler() .handle(Event.progress(testAction.getProgressMessage())); diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java index 4cf8d7dfb9..25fd5f2432 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java @@ -17,6 +17,7 @@ package com.google.devtools.build.lib.runtime.commands; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.devtools.build.lib.actions.Artifact; @@ -499,7 +500,7 @@ public class RunCommand implements BlazeCommand { runfilesSupport.getRunfilesDirectory(), false); helper.createSymlinksUsingCommand( - env.getExecRoot(), configuration, env.getBlazeWorkspace().getBinTools()); + env.getExecRoot(), env.getBlazeWorkspace().getBinTools(), ImmutableMap.of()); return workingDir; } |