Search in sources :

Example 21 with Executor

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);
    }
}
Also used : ActionExecutionMetadata(com.google.devtools.build.lib.actions.ActionExecutionMetadata) Executor(com.google.devtools.build.lib.actions.Executor) ResourceHandle(com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle) EventBus(com.google.common.eventbus.EventBus)

Example 22 with Executor

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)));
            }
        }
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) Executor(com.google.devtools.build.lib.actions.Executor) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) UserExecException(com.google.devtools.build.lib.actions.UserExecException) IOException(java.io.IOException)

Example 23 with Executor

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);
    }
}
Also used : ActionExecutionMetadata(com.google.devtools.build.lib.actions.ActionExecutionMetadata) Executor(com.google.devtools.build.lib.actions.Executor) ResourceHandle(com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle) EventBus(com.google.common.eventbus.EventBus)

Example 24 with Executor

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);
}
Also used : DummyExecutor(com.google.devtools.build.lib.actions.util.DummyExecutor) Executor(com.google.devtools.build.lib.actions.Executor) DummyExecutor(com.google.devtools.build.lib.actions.util.DummyExecutor) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) Collection(java.util.Collection) IOException(java.io.IOException) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) AbstractAction(com.google.devtools.build.lib.actions.AbstractAction) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 25 with 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);
}
Also used : TestExecutorBuilder(com.google.devtools.build.lib.exec.util.TestExecutorBuilder) Executor(com.google.devtools.build.lib.actions.Executor) Test(org.junit.Test)

Aggregations

Executor (com.google.devtools.build.lib.actions.Executor)26 IOException (java.io.IOException)12 Path (com.google.devtools.build.lib.vfs.Path)10 Artifact (com.google.devtools.build.lib.actions.Artifact)8 ExecException (com.google.devtools.build.lib.actions.ExecException)8 UserExecException (com.google.devtools.build.lib.actions.UserExecException)5 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)4 ActionInput (com.google.devtools.build.lib.actions.ActionInput)4 TestExecutorBuilder (com.google.devtools.build.lib.exec.util.TestExecutorBuilder)4 FileOutErr (com.google.devtools.build.lib.util.io.FileOutErr)4 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)4 EventBus (com.google.common.eventbus.EventBus)3 ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)3 ActionExecutionMetadata (com.google.devtools.build.lib.actions.ActionExecutionMetadata)3 ResourceHandle (com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle)3 Spawn (com.google.devtools.build.lib.actions.Spawn)3 ArrayList (java.util.ArrayList)3 HashCode (com.google.common.hash.HashCode)2 ActionInputFileCache (com.google.devtools.build.lib.actions.ActionInputFileCache)2 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)2