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);
}
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);
}
}
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);
}
}
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;
}
}
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;
}
}
Aggregations