use of com.google.devtools.build.lib.actions.Executor in project bazel by bazelbuild.
the class DarwinSandboxedStrategy method exec.
@Override
public void exec(Spawn spawn, ActionExecutionContext actionExecutionContext, AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles) throws ExecException, InterruptedException {
Executor executor = actionExecutionContext.getExecutor();
// Certain actions can't run remotely or in a sandbox - pass them on to the standalone strategy.
if (!spawn.isRemotable() || spawn.hasNoSandbox()) {
SandboxHelpers.fallbackToNonSandboxedExecution(spawn, actionExecutionContext, executor);
return;
}
EventBus eventBus = actionExecutionContext.getExecutor().getEventBus();
ActionExecutionMetadata owner = spawn.getResourceOwner();
eventBus.post(ActionStatusMessage.schedulingStrategy(owner));
try (ResourceHandle handle = ResourceManager.instance().acquireResources(owner, spawn.getLocalResources())) {
SandboxHelpers.postActionStatusMessage(eventBus, spawn);
actuallyExec(spawn, actionExecutionContext, writeOutputFiles);
}
}
use of com.google.devtools.build.lib.actions.Executor in project bazel by bazelbuild.
the class LinuxSandboxedStrategy method actuallyExec.
public void actuallyExec(Spawn spawn, ActionExecutionContext actionExecutionContext, AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles) throws ExecException, InterruptedException {
Executor executor = actionExecutionContext.getExecutor();
SandboxHelpers.reportSubcommand(executor, spawn);
// Each invocation of "exec" gets its own sandbox.
Path sandboxPath = SandboxHelpers.getSandboxRoot(blazeDirs, productName, uuid, execCounter);
Path sandboxExecRoot = sandboxPath.getRelative("execroot").getRelative(execRoot.getBaseName());
Path sandboxTempDir = sandboxPath.getRelative("tmp");
Set<Path> writableDirs = getWritableDirs(sandboxExecRoot, spawn.getEnvironment());
SymlinkedExecRoot symlinkedExecRoot = new SymlinkedExecRoot(sandboxExecRoot);
ImmutableSet<PathFragment> outputs = SandboxHelpers.getOutputFiles(spawn);
try {
symlinkedExecRoot.createFileSystem(getMounts(spawn, actionExecutionContext), outputs, writableDirs);
sandboxTempDir.createDirectory();
} catch (IOException e) {
throw new UserExecException("I/O error during sandboxed execution", e);
}
SandboxRunner runner = getSandboxRunner(spawn, sandboxPath, sandboxExecRoot, sandboxTempDir);
try {
runSpawn(spawn, actionExecutionContext, spawn.getEnvironment(), symlinkedExecRoot, outputs, runner, writeOutputFiles);
} finally {
if (!sandboxOptions.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 LinuxSandboxedStrategy method exec.
@Override
public void exec(Spawn spawn, ActionExecutionContext actionExecutionContext, AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles) throws ExecException, InterruptedException {
Executor executor = actionExecutionContext.getExecutor();
// Certain actions can't run remotely or in a sandbox - pass them on to the standalone strategy.
if (!spawn.isRemotable() || spawn.hasNoSandbox()) {
SandboxHelpers.fallbackToNonSandboxedExecution(spawn, actionExecutionContext, executor);
return;
}
EventBus eventBus = actionExecutionContext.getExecutor().getEventBus();
ActionExecutionMetadata owner = spawn.getResourceOwner();
eventBus.post(ActionStatusMessage.schedulingStrategy(owner));
try (ResourceHandle handle = ResourceManager.instance().acquireResources(owner, spawn.getLocalResources())) {
SandboxHelpers.postActionStatusMessage(eventBus, spawn);
actuallyExec(spawn, actionExecutionContext, writeOutputFiles);
}
}
use of com.google.devtools.build.lib.actions.Executor in project bazel by bazelbuild.
the class ActionDataTest method testArgumentToBuildArtifactsIsPassedDownToAction.
@Test
public void testArgumentToBuildArtifactsIsPassedDownToAction() throws Exception {
class MyAction extends AbstractAction {
Object executor = null;
public MyAction(Collection<Artifact> outputs) {
super(ActionsTestUtil.NULL_ACTION_OWNER, ImmutableList.<Artifact>of(), outputs);
}
@Override
public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException {
this.executor = actionExecutionContext.getExecutor();
try {
FileSystemUtils.createEmptyFile(getPrimaryOutput().getPath());
} catch (IOException e) {
throw new ActionExecutionException("failed: ", e, this, false);
}
}
@Override
protected String computeKey() {
return "MyAction";
}
@Override
public String getMnemonic() {
return "MyAction";
}
}
Artifact output = createDerivedArtifact("foo");
Set<Artifact> outputs = Sets.newHashSet(output);
MyAction action = new MyAction(outputs);
registerAction(action);
Executor executor = new DummyExecutor(scratch.dir("/"));
amnesiacBuilder().buildArtifacts(reporter, outputs, null, null, null, null, executor, null, /*explain=*/
false, null, null);
assertSame(executor, action.executor);
executor = new DummyExecutor(scratch.dir("/"));
amnesiacBuilder().buildArtifacts(reporter, outputs, null, null, null, null, executor, null, /*explain=*/
false, null, null);
assertSame(executor, action.executor);
}
use of com.google.devtools.build.lib.actions.Executor in project bazel by bazelbuild.
the class TemplateExpansionActionTest method testExpansion.
@Test
public void testExpansion() throws Exception {
Executor executor = new TestExecutorBuilder(directories, binTools).build();
create().execute(createContext(executor));
String content = new String(FileSystemUtils.readContentAsLatin1(output));
String expected = Joiner.on('\n').join("key=foo", "value=bar");
assertEquals(expected, content);
}
Aggregations