use of com.google.devtools.build.lib.actions.Executor in project bazel by bazelbuild.
the class DarwinSandboxedStrategy method actuallyExec.
private void actuallyExec(Spawn spawn, ActionExecutionContext actionExecutionContext, AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles) throws ExecException, InterruptedException {
Executor executor = actionExecutionContext.getExecutor();
SandboxHelpers.reportSubcommand(executor, spawn);
PrintWriter errWriter = sandboxDebug ? new PrintWriter(actionExecutionContext.getFileOutErr().getErrorStream()) : null;
// Each invocation of "exec" gets its own sandbox.
Path sandboxPath = SandboxHelpers.getSandboxRoot(blazeDirs, productName, uuid, execCounter);
Path sandboxExecRoot = sandboxPath.getRelative("execroot").getRelative(execRoot.getBaseName());
if (errWriter != null) {
errWriter.printf("sandbox root is %s\n", sandboxPath.toString());
errWriter.printf("working dir is %s\n", sandboxExecRoot.toString());
}
ImmutableMap<String, String> spawnEnvironment = StandaloneSpawnStrategy.locallyDeterminedEnv(execRoot, productName, spawn.getEnvironment());
Set<Path> writableDirs = getWritableDirs(sandboxExecRoot, spawn.getEnvironment());
Path runUnderPath = getRunUnderPath(spawn);
HardlinkedExecRoot hardlinkedExecRoot = new HardlinkedExecRoot(execRoot, sandboxPath, sandboxExecRoot, errWriter);
ImmutableSet<PathFragment> outputs = SandboxHelpers.getOutputFiles(spawn);
try {
hardlinkedExecRoot.createFileSystem(getMounts(spawn, actionExecutionContext), outputs, writableDirs);
} catch (IOException e) {
throw new UserExecException("Could not prepare sandbox directory", e);
}
// Flush our logs before executing the spawn, otherwise they might get overwritten.
if (errWriter != null) {
errWriter.flush();
}
DarwinSandboxRunner runner = new DarwinSandboxRunner(sandboxPath, sandboxExecRoot, getWritableDirs(sandboxExecRoot, spawnEnvironment), getInaccessiblePaths(), runUnderPath, verboseFailures);
try {
runSpawn(spawn, actionExecutionContext, spawnEnvironment, hardlinkedExecRoot, outputs, runner, writeOutputFiles);
} finally {
if (!sandboxDebug) {
try {
FileSystemUtils.deleteTree(sandboxPath);
} catch (IOException e) {
executor.getEventHandler().handle(Event.warn(String.format("Cannot delete sandbox directory after action execution: %s (%s)", sandboxPath.getPathString(), e)));
}
}
}
}
use of com.google.devtools.build.lib.actions.Executor in project bazel by bazelbuild.
the class ObjcCompileAction method execute.
@Override
public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException {
super.execute(actionExecutionContext);
if (dotdPruningPlan == HeaderDiscovery.DotdPruningMode.USE) {
Executor executor = actionExecutionContext.getExecutor();
IncludeScanningContext scanningContext = executor.getContext(IncludeScanningContext.class);
NestedSet<Artifact> discoveredInputs = discoverInputsFromDotdFiles(executor.getExecRoot(), scanningContext.getArtifactResolver());
updateActionInputs(discoveredInputs);
} else {
// TODO(lberki): This is awkward, but necessary since updateInputs() must be called when
// input discovery is in effect. I *think* it's possible to avoid setting discoversInputs()
// to true if the header list file is null and then we'd not need to have this here, but I
// haven't quite managed to get that right yet.
updateActionInputs(getInputs());
}
}
use of com.google.devtools.build.lib.actions.Executor in project bazel by bazelbuild.
the class SymlinkActionTest method testSymlink.
@Test
public void testSymlink() throws Exception {
Executor executor = new TestExecutorBuilder(directories, null).build();
action.execute(new ActionExecutionContext(executor, null, null, null, ImmutableMap.<String, String>of(), null));
assertTrue(output.isSymbolicLink());
assertEquals(input, output.resolveSymbolicLinks());
assertEquals(inputArtifact, action.getPrimaryInput());
assertEquals(outputArtifact, action.getPrimaryOutput());
}
use of com.google.devtools.build.lib.actions.Executor in project bazel by bazelbuild.
the class ParamFileWriteActionTest method actionExecutionContext.
private ActionExecutionContext actionExecutionContext() throws Exception {
final Iterable<TreeFileArtifact> treeFileArtifacts = ImmutableList.of(createTreeFileArtifact(treeArtifact, "artifacts/treeFileArtifact1"), createTreeFileArtifact(treeArtifact, "artifacts/treeFileArtifact2"));
ArtifactExpander artifactExpander = new ArtifactExpander() {
@Override
public void expand(Artifact artifact, Collection<? super Artifact> output) {
for (TreeFileArtifact treeFileArtifact : treeFileArtifacts) {
if (treeFileArtifact.getParent().equals(artifact)) {
output.add(treeFileArtifact);
}
}
}
};
Executor executor = new TestExecutorBuilder(directories, binTools).build();
return new ActionExecutionContext(executor, null, null, new FileOutErr(), ImmutableMap.<String, String>of(), artifactExpander);
}
use of com.google.devtools.build.lib.actions.Executor in project bazel by bazelbuild.
the class PopulateTreeArtifactAction method execute.
@Override
public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException {
Executor executor = actionExecutionContext.getExecutor();
Spawn spawn;
// Create a spawn to unzip the archive file into the output TreeArtifact.
try {
spawn = createSpawn();
} catch (IOException e) {
throw new ActionExecutionException(e, this, false);
} catch (IllegalManifestFileException e) {
throw new ActionExecutionException(e, this, true);
}
// case we just return without generating anything under the output TreeArtifact.
if (spawn.getOutputFiles().isEmpty()) {
return;
}
// Check spawn output TreeFileArtifact conflicts.
try {
checkOutputConflicts(spawn.getOutputFiles());
} catch (ArtifactPrefixConflictException e) {
throw new ActionExecutionException(e, this, true);
}
// Create parent directories for the output TreeFileArtifacts.
try {
for (ActionInput fileEntry : spawn.getOutputFiles()) {
FileSystemUtils.createDirectoryAndParents(((Artifact) fileEntry).getPath().getParentDirectory());
}
} catch (IOException e) {
throw new ActionExecutionException(e, this, false);
}
// Execute the spawn.
try {
getContext(executor).exec(spawn, actionExecutionContext);
} catch (ExecException e) {
throw e.toActionExecutionException(getMnemonic() + " action failed for target: " + getOwner().getLabel(), executor.getVerboseFailures(), this);
}
// Populate the output TreeArtifact with the Spawn output TreeFileArtifacts.
for (ActionInput fileEntry : spawn.getOutputFiles()) {
actionExecutionContext.getMetadataHandler().addExpandedTreeOutput((TreeFileArtifact) fileEntry);
}
}
Aggregations