Search in sources :

Example 1 with FileOutErr

use of com.google.devtools.build.lib.util.io.FileOutErr in project bazel by bazelbuild.

the class StandaloneTestStrategy method executeTestAttempt.

private TestResultData executeTestAttempt(TestRunnerAction action, Spawn spawn, ActionExecutionContext actionExecutionContext, Path execRoot, Path coverageDir, Path tmpDir, Path workingDirectory) throws IOException, ExecException, InterruptedException {
    prepareFileSystem(action, tmpDir, coverageDir, workingDirectory);
    try (FileOutErr fileOutErr = new FileOutErr(action.getTestLog().getPath(), action.resolve(execRoot).getTestStderr())) {
        TestResultData data = executeTest(action, spawn, actionExecutionContext.withFileOutErr(fileOutErr));
        appendStderr(fileOutErr.getOutputPath(), fileOutErr.getErrorPath());
        return data;
    }
}
Also used : FileOutErr(com.google.devtools.build.lib.util.io.FileOutErr) TestResultData(com.google.devtools.build.lib.view.test.TestStatus.TestResultData)

Example 2 with FileOutErr

use of com.google.devtools.build.lib.util.io.FileOutErr in project bazel by bazelbuild.

the class FakeCppCompileAction method execute.

@Override
@ThreadCompatible
public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException {
    setModuleFileFlags();
    Executor executor = actionExecutionContext.getExecutor();
    // First, do a normal compilation, to generate the ".d" file. The generated object file is built
    // to a temporary location (tempOutputFile) and ignored afterwards.
    LOG.info("Generating " + getDotdFile());
    CppCompileActionContext context = executor.getContext(actionContext);
    CppCompileActionContext.Reply reply = null;
    try {
        // We delegate stdout/stderr to nowhere, i.e. same as redirecting to /dev/null.
        reply = context.execWithReply(this, actionExecutionContext.withFileOutErr(new FileOutErr()));
    } catch (ExecException e) {
        // We ignore failures here (other than capturing the Distributor reply).
        // The compilation may well fail (that's the whole point of negative compilation tests).
        // We execute it here just for the side effect of generating the ".d" file.
        reply = context.getReplyFromException(e, this);
        if (reply == null) {
            // This can only happen if the ExecException does not come from remote execution.
            throw e.toActionExecutionException("Fake C++ Compilation of rule '" + getOwner().getLabel() + "'", executor.getVerboseFailures(), this);
        }
    }
    IncludeScanningContext scanningContext = executor.getContext(IncludeScanningContext.class);
    Path execRoot = executor.getExecRoot();
    NestedSet<Artifact> discoveredInputs;
    if (getDotdFile() == null) {
        discoveredInputs = NestedSetBuilder.<Artifact>stableOrder().build();
    } else {
        HeaderDiscovery.Builder discoveryBuilder = new HeaderDiscovery.Builder().setAction(this).setDotdFile(getDotdFile()).setSourceFile(getSourceFile()).setSpecialInputsHandler(specialInputsHandler).setDependencySet(processDepset(execRoot, reply)).setPermittedSystemIncludePrefixes(getPermittedSystemIncludePrefixes(execRoot)).setAllowedDerivedinputsMap(getAllowedDerivedInputsMap());
        if (cppSemantics.needsIncludeValidation()) {
            discoveryBuilder.shouldValidateInclusions();
        }
        discoveredInputs = discoveryBuilder.build().discoverInputsFromDotdFiles(execRoot, scanningContext.getArtifactResolver());
    }
    // Clear in-memory .d files early.
    reply = null;
    // depends on.
    try {
        validateInclusions(discoveredInputs, actionExecutionContext.getArtifactExpander(), executor.getEventHandler());
    } catch (ActionExecutionException e) {
        // TODO(bazel-team): (2009) make this into an error, once most of the current warnings
        // are fixed.
        executor.getEventHandler().handle(Event.warn(getOwner().getLocation(), e.getMessage() + ";\n  this warning may eventually become an error"));
    }
    updateActionInputs(discoveredInputs);
    // Generate a fake ".o" file containing the command line needed to generate
    // the real object file.
    LOG.info("Generating " + outputFile);
    // A cc_fake_binary rule generates fake .o files and a fake target file,
    // which merely contain instructions on building the real target. We need to
    // be careful to use a new set of output file names in the instructions, as
    // to not overwrite the fake output files when someone tries to follow the
    // instructions. As the real compilation is executed by the test from its
    // runfiles directory (where writing is forbidden), we patch the command
    // line to write to $TEST_TMPDIR instead.
    final String outputPrefix = "$TEST_TMPDIR/";
    String argv = Joiner.on(' ').join(Iterables.transform(getArgv(outputFile.getExecPath()), new Function<String, String>() {

        @Override
        public String apply(String input) {
            String result = ShellEscaper.escapeString(input);
            // -c <tempOutputFile>, but here it has to be outputFile, so we replace it.
            if (input.equals(tempOutputFile.getPathString())) {
                result = outputPrefix + ShellEscaper.escapeString(outputFile.getExecPathString());
            }
            if (input.equals(outputFile.getExecPathString()) || input.equals(getDotdFile().getSafeExecPath().getPathString())) {
                result = outputPrefix + ShellEscaper.escapeString(input);
            }
            return result;
        }
    }));
    // the compilation would fail.
    try {
        // Ensure that the .d file and .o file are siblings, so that the "mkdir" below works for
        // both.
        Preconditions.checkState(outputFile.getExecPath().getParentDirectory().equals(getDotdFile().getSafeExecPath().getParentDirectory()));
        FileSystemUtils.writeContent(outputFile.getPath(), ISO_8859_1, outputFile.getPath().getBaseName() + ": " + "mkdir -p " + outputPrefix + "$(dirname " + outputFile.getExecPath() + ")" + " && " + argv + "\n");
    } catch (IOException e) {
        throw new ActionExecutionException("failed to create fake compile command for rule '" + getOwner().getLabel() + ": " + e.getMessage(), this, false);
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) FileOutErr(com.google.devtools.build.lib.util.io.FileOutErr) ExecException(com.google.devtools.build.lib.actions.ExecException) IOException(java.io.IOException) Artifact(com.google.devtools.build.lib.actions.Artifact) Function(com.google.common.base.Function) Executor(com.google.devtools.build.lib.actions.Executor) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) ThreadCompatible(com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadCompatible)

Example 3 with FileOutErr

use of com.google.devtools.build.lib.util.io.FileOutErr 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 4 with FileOutErr

use of com.google.devtools.build.lib.util.io.FileOutErr in project bazel by bazelbuild.

the class LTOBackendActionTest method createExecutorAndContext.

@Before
public final void createExecutorAndContext() throws Exception {
    executor = new TestExecutorBuilder(directories, binTools).build();
    context = new ActionExecutionContext(executor, null, null, new FileOutErr(), ImmutableMap.<String, String>of(), null);
}
Also used : TestExecutorBuilder(com.google.devtools.build.lib.exec.util.TestExecutorBuilder) FileOutErr(com.google.devtools.build.lib.util.io.FileOutErr) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) Before(org.junit.Before)

Example 5 with FileOutErr

use of com.google.devtools.build.lib.util.io.FileOutErr in project bazel by bazelbuild.

the class SkyframeActionExecutor method executeActionTask.

/**
   * Execute the specified action, in a profiler task.
   * The caller is responsible for having already checked that we need to
   * execute it and for acquiring/releasing any scheduling locks needed.
   *
   * <p>This is thread-safe so long as you don't try to execute the same action
   * twice at the same time (or overlapping times).
   * May execute in a worker thread.
   *
   * @throws ActionExecutionException if the execution of the specified action
   *   failed for any reason.
   * @throws InterruptedException if the thread was interrupted.
   * @return true if the action output was dumped, false otherwise.
   */
private boolean executeActionTask(Action action, ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException {
    profiler.startTask(ProfilerTask.ACTION_EXECUTE, action);
    // ActionExecutionExceptions that occur as the thread is interrupted are
    // assumed to be a result of that, so we throw InterruptedException
    // instead.
    FileOutErr outErrBuffer = actionExecutionContext.getFileOutErr();
    try {
        action.execute(actionExecutionContext);
        // current implementation it uses regular expression matching.
        if (outErrBuffer.hasRecordedOutput() && (action.showsOutputUnconditionally() || reporter.showOutput(Label.print(action.getOwner().getLabel())))) {
            dumpRecordedOutErr(action, outErrBuffer);
            return true;
        }
    // Defer reporting action success until outputs are checked
    } catch (ActionExecutionException e) {
        processAndThrow(e, action, outErrBuffer);
    } finally {
        profiler.completeTask(ProfilerTask.ACTION_EXECUTE);
    }
    return false;
}
Also used : FileOutErr(com.google.devtools.build.lib.util.io.FileOutErr) AlreadyReportedActionExecutionException(com.google.devtools.build.lib.actions.AlreadyReportedActionExecutionException) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException)

Aggregations

FileOutErr (com.google.devtools.build.lib.util.io.FileOutErr)9 Executor (com.google.devtools.build.lib.actions.Executor)4 ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)3 TestExecutorBuilder (com.google.devtools.build.lib.exec.util.TestExecutorBuilder)3 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)2 Artifact (com.google.devtools.build.lib.actions.Artifact)2 UserExecException (com.google.devtools.build.lib.actions.UserExecException)2 Path (com.google.devtools.build.lib.vfs.Path)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 Function (com.google.common.base.Function)1 HashCode (com.google.common.hash.HashCode)1 ActionInput (com.google.devtools.build.lib.actions.ActionInput)1 ActionInputFileCache (com.google.devtools.build.lib.actions.ActionInputFileCache)1 AlreadyReportedActionExecutionException (com.google.devtools.build.lib.actions.AlreadyReportedActionExecutionException)1 ArtifactExpander (com.google.devtools.build.lib.actions.Artifact.ArtifactExpander)1 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)1 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)1 ExecException (com.google.devtools.build.lib.actions.ExecException)1