Search in sources :

Example 6 with ExecException

use of com.google.devtools.build.lib.actions.ExecException in project bazel by bazelbuild.

the class CppCompileAction method discoverInputs.

@Nullable
@Override
public Iterable<Artifact> discoverInputs(ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException {
    Executor executor = actionExecutionContext.getExecutor();
    Iterable<Artifact> initialResult;
    actionExecutionContext.getExecutor().getEventBus().post(ActionStatusMessage.analysisStrategy(this));
    try {
        initialResult = executor.getContext(actionContext).findAdditionalInputs(this, actionExecutionContext, cppSemantics.getIncludeProcessing());
    } catch (ExecException e) {
        throw e.toActionExecutionException("Include scanning of rule '" + getOwner().getLabel() + "'", executor.getVerboseFailures(), this);
    }
    if (initialResult == null) {
        NestedSetBuilder<Artifact> result = NestedSetBuilder.stableOrder();
        if (useHeaderModules) {
            // Here, we cannot really know what the top-level modules are, so we just mark all
            // transitive modules as "top level".
            topLevelModules = Sets.newLinkedHashSet(context.getTransitiveModules(usePic).toCollection());
            result.addTransitive(context.getTransitiveModules(usePic));
        }
        result.addTransitive(prunableInputs);
        additionalInputs = result.build();
        return result.build();
    }
    Set<Artifact> initialResultSet = Sets.newLinkedHashSet(initialResult);
    if (shouldPruneModules) {
        if (CppFileTypes.CPP_MODULE.matches(sourceFile.getFilename())) {
            usedModules = ImmutableSet.of(sourceFile);
            initialResultSet.add(sourceFile);
        } else {
            usedModules = Sets.newLinkedHashSet();
            topLevelModules = null;
            for (CppCompilationContext.TransitiveModuleHeaders usedModule : context.getUsedModules(usePic, initialResultSet)) {
                usedModules.add(usedModule.getModule());
            }
            initialResultSet.addAll(usedModules);
        }
    }
    initialResult = initialResultSet;
    this.additionalInputs = initialResult;
    // In some cases, execution backends need extra files for each included file. Add them
    // to the set of inputs the caller may need to be aware of.
    Collection<Artifact> result = new HashSet<>();
    ArtifactResolver artifactResolver = executor.getContext(IncludeScanningContext.class).getArtifactResolver();
    for (Artifact artifact : initialResult) {
        result.addAll(specialInputsHandler.getInputsForIncludedFile(artifact, artifactResolver));
    }
    for (Artifact artifact : getInputs()) {
        result.addAll(specialInputsHandler.getInputsForIncludedFile(artifact, artifactResolver));
    }
    // TODO(ulfjack): This only works if include scanning is enabled; the cleanup is in progress,
    // and this needs to be fixed before we can even consider disabling it.
    resolvedInputs = ImmutableList.copyOf(result);
    Iterables.addAll(result, initialResult);
    return Preconditions.checkNotNull(result);
}
Also used : Executor(com.google.devtools.build.lib.actions.Executor) ExecException(com.google.devtools.build.lib.actions.ExecException) Artifact(com.google.devtools.build.lib.actions.Artifact) ArtifactResolver(com.google.devtools.build.lib.actions.ArtifactResolver) HashSet(java.util.HashSet) Nullable(javax.annotation.Nullable)

Example 7 with ExecException

use of com.google.devtools.build.lib.actions.ExecException in project bazel by bazelbuild.

the class ExtractInclusionAction method execute.

@Override
public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException {
    Executor executor = actionExecutionContext.getExecutor();
    IncludeScanningContext context = executor.getContext(IncludeScanningContext.class);
    try {
        context.extractIncludes(actionExecutionContext, this, getPrimaryInput(), getPrimaryOutput());
    } catch (IOException e) {
        throw new ActionExecutionException(e, this, false);
    } catch (ExecException e) {
        throw e.toActionExecutionException(this);
    }
}
Also used : Executor(com.google.devtools.build.lib.actions.Executor) ExecException(com.google.devtools.build.lib.actions.ExecException) IOException(java.io.IOException) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException)

Example 8 with ExecException

use of com.google.devtools.build.lib.actions.ExecException in project bazel by bazelbuild.

the class JavaHeaderCompileAction method execute.

@Override
public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException {
    if (!useDirectClasspath()) {
        super.execute(actionExecutionContext);
        return;
    }
    Executor executor = actionExecutionContext.getExecutor();
    SpawnActionContext context = getContext(executor);
    try {
        context.exec(getDirectSpawn(), actionExecutionContext);
    } catch (ExecException e) {
        // if the direct input spawn failed, try again with transitive inputs to produce better
        // better messages
        super.execute(actionExecutionContext);
        // the compilation should never fail with direct deps but succeed with transitive inputs
        if (fallbackError) {
            throw e.toActionExecutionException("header compilation failed unexpectedly", executor.getVerboseFailures(), this);
        }
        Event event = Event.warn(getOwner().getLocation(), "header compilation failed unexpectedly");
        executor.getEventHandler().handle(event);
    }
}
Also used : Executor(com.google.devtools.build.lib.actions.Executor) ExecException(com.google.devtools.build.lib.actions.ExecException) Event(com.google.devtools.build.lib.events.Event) SpawnActionContext(com.google.devtools.build.lib.actions.SpawnActionContext)

Example 9 with ExecException

use of com.google.devtools.build.lib.actions.ExecException in project bazel by bazelbuild.

the class CleanCommand method exec.

@Override
public ExitCode exec(CommandEnvironment env, OptionsProvider options) throws ShutdownBlazeServerException {
    Options cleanOptions = options.getOptions(Options.class);
    cleanOptions.expunge_async = cleanOptions.cleanStyle.equals("expunge_async");
    cleanOptions.expunge = cleanOptions.cleanStyle.equals("expunge");
    cleanOptions.async = cleanOptions.cleanStyle.equals("async");
    env.getEventBus().post(new NoBuildEvent());
    if (!cleanOptions.expunge && !cleanOptions.expunge_async && !cleanOptions.async && !cleanOptions.cleanStyle.isEmpty()) {
        env.getReporter().handle(Event.error(null, "Invalid clean_style value '" + cleanOptions.cleanStyle + "'"));
        return ExitCode.COMMAND_LINE_ERROR;
    }
    String asyncName = (cleanOptions.expunge || cleanOptions.expunge_async) ? "--expunge_async" : "--async";
    // for non-Linux platforms (https://github.com/bazelbuild/bazel/issues/1906).
    if ((cleanOptions.expunge_async || cleanOptions.async) && OS.getCurrent() != OS.LINUX) {
        boolean expunge = cleanOptions.expunge_async;
        String fallbackName = expunge ? "--expunge" : "synchronous clean";
        env.getReporter().handle(Event.info(null, /*location*/
        asyncName + " cannot be used on non-Linux platforms, falling back to " + fallbackName));
        cleanOptions.expunge_async = false;
        cleanOptions.expunge = expunge;
        cleanOptions.async = false;
        cleanOptions.cleanStyle = expunge ? "expunge" : "";
    }
    String cleanBanner = (cleanOptions.expunge_async || cleanOptions.async) ? "Starting clean." : "Starting clean (this may take a while). " + "Consider using " + asyncName + " if the clean takes more than several minutes.";
    env.getReporter().handle(Event.info(null, /*location*/
    cleanBanner));
    try {
        String symlinkPrefix = options.getOptions(BuildRequest.BuildRequestOptions.class).getSymlinkPrefix(env.getRuntime().getProductName());
        actuallyClean(env, env.getOutputBase(), cleanOptions, symlinkPrefix);
        return ExitCode.SUCCESS;
    } catch (IOException e) {
        env.getReporter().handle(Event.error(e.getMessage()));
        return ExitCode.LOCAL_ENVIRONMENTAL_ERROR;
    } catch (CommandException | ExecException e) {
        env.getReporter().handle(Event.error(e.getMessage()));
        return ExitCode.RUN_FAILURE;
    } catch (InterruptedException e) {
        env.getReporter().handle(Event.error("clean interrupted"));
        return ExitCode.INTERRUPTED;
    }
}
Also used : ExecException(com.google.devtools.build.lib.actions.ExecException) NoBuildEvent(com.google.devtools.build.lib.analysis.NoBuildEvent) IOException(java.io.IOException) CommandException(com.google.devtools.build.lib.shell.CommandException)

Example 10 with ExecException

use of com.google.devtools.build.lib.actions.ExecException in project bazel by bazelbuild.

the class SandboxStrategy method runSpawn.

protected void runSpawn(Spawn spawn, ActionExecutionContext actionExecutionContext, Map<String, String> spawnEnvironment, SandboxExecRoot sandboxExecRoot, Set<PathFragment> outputs, SandboxRunner runner, AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles) throws ExecException, InterruptedException {
    EventHandler eventHandler = actionExecutionContext.getExecutor().getEventHandler();
    ExecException execException = null;
    OutErr outErr = actionExecutionContext.getFileOutErr();
    try {
        runner.run(spawn.getArguments(), spawnEnvironment, outErr, Spawns.getTimeoutSeconds(spawn), SandboxHelpers.shouldAllowNetwork(buildRequest, spawn), sandboxOptions.sandboxDebug, sandboxOptions.sandboxFakeHostname);
    } catch (ExecException e) {
        execException = e;
    }
    if (writeOutputFiles != null && !writeOutputFiles.compareAndSet(null, SandboxStrategy.class)) {
        throw new InterruptedException();
    }
    try {
        // We copy the outputs even when the command failed, otherwise StandaloneTestStrategy
        // won't be able to get the test logs of a failed test. (We should probably do this in
        // some better way.)
        sandboxExecRoot.copyOutputs(execRoot, outputs);
    } catch (IOException e) {
        if (execException == null) {
            throw new UserExecException("Could not move output artifacts from sandboxed execution", e);
        } else {
            // Catch the IOException and turn it into an error message, otherwise this might hide an
            // exception thrown during runner.run earlier.
            eventHandler.handle(Event.error("I/O exception while extracting output artifacts from sandboxed execution: " + e));
        }
    }
    if (execException != null) {
        outErr.printErr("Use --strategy=" + spawn.getMnemonic() + "=standalone to disable sandboxing for the failing actions.\n");
        throw execException;
    }
}
Also used : OutErr(com.google.devtools.build.lib.util.io.OutErr) EnvironmentalExecException(com.google.devtools.build.lib.actions.EnvironmentalExecException) UserExecException(com.google.devtools.build.lib.actions.UserExecException) ExecException(com.google.devtools.build.lib.actions.ExecException) UserExecException(com.google.devtools.build.lib.actions.UserExecException) EventHandler(com.google.devtools.build.lib.events.EventHandler) IOException(java.io.IOException)

Aggregations

ExecException (com.google.devtools.build.lib.actions.ExecException)11 Executor (com.google.devtools.build.lib.actions.Executor)8 IOException (java.io.IOException)6 Artifact (com.google.devtools.build.lib.actions.Artifact)4 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)3 Spawn (com.google.devtools.build.lib.actions.Spawn)3 ThreadCompatible (com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadCompatible)3 Path (com.google.devtools.build.lib.vfs.Path)3 ActionInput (com.google.devtools.build.lib.actions.ActionInput)2 BaseSpawn (com.google.devtools.build.lib.actions.BaseSpawn)2 EnvironmentalExecException (com.google.devtools.build.lib.actions.EnvironmentalExecException)2 SpawnActionContext (com.google.devtools.build.lib.actions.SpawnActionContext)2 Function (com.google.common.base.Function)1 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)1 ArtifactPrefixConflictException (com.google.devtools.build.lib.actions.ArtifactPrefixConflictException)1 ArtifactResolver (com.google.devtools.build.lib.actions.ArtifactResolver)1 SimpleSpawn (com.google.devtools.build.lib.actions.SimpleSpawn)1 TestExecException (com.google.devtools.build.lib.actions.TestExecException)1 UserExecException (com.google.devtools.build.lib.actions.UserExecException)1 ActionsTestUtil (com.google.devtools.build.lib.actions.util.ActionsTestUtil)1