Search in sources :

Example 6 with Executor

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)));
            }
        }
    }
}
Also used : SearchPath(com.google.devtools.build.lib.vfs.SearchPath) 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) PrintWriter(java.io.PrintWriter)

Example 7 with Executor

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());
    }
}
Also used : Executor(com.google.devtools.build.lib.actions.Executor) IncludeScanningContext(com.google.devtools.build.lib.rules.cpp.IncludeScanningContext) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 8 with Executor

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

Example 9 with Executor

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);
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) TestExecutorBuilder(com.google.devtools.build.lib.exec.util.TestExecutorBuilder) ArtifactExpander(com.google.devtools.build.lib.actions.Artifact.ArtifactExpander) Executor(com.google.devtools.build.lib.actions.Executor) FileOutErr(com.google.devtools.build.lib.util.io.FileOutErr) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) Collection(java.util.Collection) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)

Example 10 with Executor

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);
    }
}
Also used : Executor(com.google.devtools.build.lib.actions.Executor) ActionInput(com.google.devtools.build.lib.actions.ActionInput) ExecException(com.google.devtools.build.lib.actions.ExecException) IOException(java.io.IOException) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) BaseSpawn(com.google.devtools.build.lib.actions.BaseSpawn) Spawn(com.google.devtools.build.lib.actions.Spawn) ArtifactPrefixConflictException(com.google.devtools.build.lib.actions.ArtifactPrefixConflictException) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)

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