use of com.google.devtools.build.lib.actions.ActionExecutionContext in project bazel by bazelbuild.
the class PopulateTreeArtifactActionTest method testTreeArtifactPopulated.
@Test
public void testTreeArtifactPopulated() throws Exception {
ArrayList<Artifact> treefileArtifacts = new ArrayList<Artifact>();
PopulateTreeArtifactAction action = createPopulateTreeArtifactAction();
ActionExecutionContext executionContext = actionExecutionContext(treefileArtifacts);
action.execute(executionContext);
assertThat(Artifact.toExecPaths(treefileArtifacts)).containsExactly("test/archive_member/archive_members/1.class", "test/archive_member/archive_members/2.class", "test/archive_member/archive_members/txt/text.txt");
}
use of com.google.devtools.build.lib.actions.ActionExecutionContext 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);
}
use of com.google.devtools.build.lib.actions.ActionExecutionContext in project bazel by bazelbuild.
the class ActionExecutionFunction method checkCacheAndExecuteIfNeeded.
private ActionExecutionValue checkCacheAndExecuteIfNeeded(Action action, ContinuationState state, Environment env, Map<String, String> clientEnv) throws ActionExecutionException, InterruptedException {
// other action's value, provided here, since it is populated with metadata for the outputs.
if (!state.hasArtifactData()) {
return skyframeActionExecutor.executeAction(action, null, -1, null);
}
// This may be recreated if we discover inputs.
ActionMetadataHandler metadataHandler = new ActionMetadataHandler(state.inputArtifactData, action.getOutputs(), tsgm.get());
long actionStartTime = BlazeClock.nanoTime();
// We only need to check the action cache if we haven't done it on a previous run.
if (!state.hasCheckedActionCache()) {
state.token = skyframeActionExecutor.checkActionCache(action, metadataHandler, actionStartTime, state.allInputs.actionCacheInputs, clientEnv);
}
if (state.token == null) {
// We got a hit from the action cache -- no need to execute.
return new ActionExecutionValue(metadataHandler.getOutputArtifactData(), metadataHandler.getOutputTreeArtifactData(), metadataHandler.getAdditionalOutputData());
}
// This may be recreated if we discover inputs.
PerActionFileCache perActionFileCache = new PerActionFileCache(state.inputArtifactData);
ActionExecutionContext actionExecutionContext = null;
try {
if (action.discoversInputs()) {
if (state.discoveredInputs == null) {
try {
state.discoveredInputs = skyframeActionExecutor.discoverInputs(action, perActionFileCache, metadataHandler, env);
Preconditions.checkState(state.discoveredInputs != null, "discoverInputs() returned null on action %s", action);
} catch (MissingDepException e) {
Preconditions.checkState(env.valuesMissing(), action);
return null;
}
}
addDiscoveredInputs(state.inputArtifactData, state.expandedArtifacts, state.discoveredInputs, env);
if (env.valuesMissing()) {
return null;
}
perActionFileCache = new PerActionFileCache(state.inputArtifactData);
metadataHandler = new ActionMetadataHandler(state.inputArtifactData, action.getOutputs(), tsgm.get());
// available.
if (state.discoveredInputsStage2 == null) {
state.discoveredInputsStage2 = action.discoverInputsStage2(env);
}
if (state.discoveredInputsStage2 != null) {
addDiscoveredInputs(state.inputArtifactData, state.expandedArtifacts, state.discoveredInputsStage2, env);
if (env.valuesMissing()) {
return null;
}
perActionFileCache = new PerActionFileCache(state.inputArtifactData);
metadataHandler = new ActionMetadataHandler(state.inputArtifactData, action.getOutputs(), tsgm.get());
}
}
actionExecutionContext = skyframeActionExecutor.getContext(perActionFileCache, metadataHandler, Collections.unmodifiableMap(state.expandedArtifacts));
if (!state.hasExecutedAction()) {
state.value = skyframeActionExecutor.executeAction(action, metadataHandler, actionStartTime, actionExecutionContext);
}
} finally {
if (actionExecutionContext != null) {
try {
actionExecutionContext.getFileOutErr().close();
} catch (IOException e) {
// Nothing we can do here.
}
}
}
if (action.discoversInputs()) {
Iterable<Artifact> newInputs = filterKnownInputs(action.getInputs(), state.inputArtifactData.keySet());
Map<SkyKey, SkyValue> metadataFoundDuringActionExecution = env.getValues(toKeys(newInputs, action.getMandatoryInputs()));
state.discoveredInputs = newInputs;
if (env.valuesMissing()) {
return null;
}
if (!Iterables.isEmpty(newInputs)) {
// We are in the interesting case of an action that discovered its inputs during
// execution, and found some new ones, but the new ones were already present in the graph.
// We must therefore cache the metadata for those new ones.
Map<Artifact, FileArtifactValue> inputArtifactData = new HashMap<>();
inputArtifactData.putAll(state.inputArtifactData);
for (Map.Entry<SkyKey, SkyValue> entry : metadataFoundDuringActionExecution.entrySet()) {
inputArtifactData.put(ArtifactSkyKey.artifact(entry.getKey()), (FileArtifactValue) entry.getValue());
}
state.inputArtifactData = inputArtifactData;
metadataHandler = new ActionMetadataHandler(state.inputArtifactData, action.getOutputs(), tsgm.get());
}
}
Preconditions.checkState(!env.valuesMissing(), action);
skyframeActionExecutor.afterExecution(action, metadataHandler, state.token, clientEnv);
return state.value;
}
use of com.google.devtools.build.lib.actions.ActionExecutionContext in project bazel by bazelbuild.
the class PopulateTreeArtifactActionTest method testInvalidManifestEntryPaths.
@Test
public void testInvalidManifestEntryPaths() throws Exception {
Action action = createPopulateTreeArtifactAction();
scratch.overwriteFile("archiveManifest.txt", "archive_members/1.class", "../invalid_relative_path/myfile.class");
ActionExecutionContext executionContext = actionExecutionContext(new ArrayList<Artifact>());
try {
action.execute(executionContext);
fail("Invalid manifest entry paths, expected exception");
} catch (ActionExecutionException e) {
// Expect ActionExecutionException
}
}
use of com.google.devtools.build.lib.actions.ActionExecutionContext in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testInvalidSymlinkRejected.
@Test
public void testInvalidSymlinkRejected() throws Exception {
// Failure expected
StoredEventHandler storingEventHandler = new StoredEventHandler();
reporter.removeHandler(failFastHandler);
reporter.addHandler(storingEventHandler);
final Artifact out = createTreeArtifact("output");
TreeArtifactTestAction action = new TreeArtifactTestAction(out) {
@Override
public void execute(ActionExecutionContext actionExecutionContext) {
try {
writeFile(out.getPath().getChild("one"), "one");
writeFile(out.getPath().getChild("two"), "two");
FileSystemUtils.ensureSymbolicLink(out.getPath().getChild("links").getChild("link"), "../invalid");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
registerAction(action);
try {
buildArtifact(action.getSoleOutput());
// Should have thrown
fail();
} catch (BuildFailedException e) {
List<Event> errors = ImmutableList.copyOf(Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
assertThat(errors).hasSize(2);
assertThat(errors.get(0).getMessage()).contains("Failed to resolve relative path links/link");
assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
}
}
Aggregations