use of com.google.devtools.build.lib.actions.ActionAnalysisMetadata in project bazel by bazelbuild.
the class ActionsTestUtil method assertPrimaryInputAndOutputArtifacts.
/**
* Assert that an artifact is the primary output of its generating action.
*/
public void assertPrimaryInputAndOutputArtifacts(Artifact input, Artifact output) {
ActionAnalysisMetadata generatingAction = actionGraph.getGeneratingAction(output);
assertThat(generatingAction).isNotNull();
assertThat(generatingAction.getPrimaryOutput()).isEqualTo(output);
assertThat(generatingAction.getPrimaryInput()).isEqualTo(input);
}
use of com.google.devtools.build.lib.actions.ActionAnalysisMetadata in project bazel by bazelbuild.
the class ActionsTestUtil method findTransitivePrerequisitesOf.
/**
* Finds all the actions that are instances of <code>actionClass</code>
* in the transitive closure of prerequisites.
*/
public <A extends Action> List<A> findTransitivePrerequisitesOf(Artifact artifact, Class<A> actionClass, Predicate<Artifact> allowedArtifacts) {
List<A> actions = new ArrayList<>();
Set<Artifact> visited = new LinkedHashSet<>();
List<Artifact> toVisit = new LinkedList<>();
toVisit.add(artifact);
while (!toVisit.isEmpty()) {
Artifact current = toVisit.remove(0);
if (!visited.add(current)) {
continue;
}
ActionAnalysisMetadata generatingAction = actionGraph.getGeneratingAction(current);
if (generatingAction != null) {
Iterables.addAll(toVisit, Iterables.filter(generatingAction.getInputs(), allowedArtifacts));
if (actionClass.isInstance(generatingAction)) {
actions.add(actionClass.cast(generatingAction));
}
}
}
return actions;
}
use of com.google.devtools.build.lib.actions.ActionAnalysisMetadata in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testCreateSpawnActionCreatesSpawnAction.
@Test
public void testCreateSpawnActionCreatesSpawnAction() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
createTestSpawnAction(ruleContext);
ActionAnalysisMetadata action = Iterables.getOnlyElement(ruleContext.getRuleContext().getAnalysisEnvironment().getRegisteredActions());
assertThat(action).isInstanceOf(SpawnAction.class);
}
use of com.google.devtools.build.lib.actions.ActionAnalysisMetadata in project bazel by bazelbuild.
the class BuildView method createResult.
private AnalysisResult createResult(ExtendedEventHandler eventHandler, LoadingResult loadingResult, TopLevelArtifactContext topLevelOptions, BuildView.Options viewOptions, SkyframeAnalysisResult skyframeAnalysisResult) throws InterruptedException {
Collection<Target> testsToRun = loadingResult.getTestsToRun();
Collection<ConfiguredTarget> configuredTargets = skyframeAnalysisResult.getConfiguredTargets();
Collection<AspectValue> aspects = skyframeAnalysisResult.getAspects();
Collection<ConfiguredTarget> allTargetsToTest = null;
if (testsToRun != null) {
// Determine the subset of configured targets that are meant to be run as tests.
// Do not remove <ConfiguredTarget>: workaround for Java 7 type inference.
allTargetsToTest = Lists.<ConfiguredTarget>newArrayList(filterTestsByTargets(configuredTargets, Sets.newHashSet(testsToRun)));
}
Set<Artifact> artifactsToBuild = new HashSet<>();
Set<ConfiguredTarget> parallelTests = new HashSet<>();
Set<ConfiguredTarget> exclusiveTests = new HashSet<>();
// build-info and build-changelist.
Collection<Artifact> buildInfoArtifacts = skyframeExecutor.getWorkspaceStatusArtifacts(eventHandler);
Preconditions.checkState(buildInfoArtifacts.size() == 2, buildInfoArtifacts);
artifactsToBuild.addAll(buildInfoArtifacts);
// Extra actions
addExtraActionsIfRequested(viewOptions, configuredTargets, aspects, artifactsToBuild);
// Coverage
NestedSet<Artifact> baselineCoverageArtifacts = getBaselineCoverageArtifacts(configuredTargets);
Iterables.addAll(artifactsToBuild, baselineCoverageArtifacts);
if (coverageReportActionFactory != null) {
CoverageReportActionsWrapper actionsWrapper;
actionsWrapper = coverageReportActionFactory.createCoverageReportActionsWrapper(eventHandler, directories, allTargetsToTest, baselineCoverageArtifacts, getArtifactFactory(), CoverageReportValue.ARTIFACT_OWNER);
if (actionsWrapper != null) {
ImmutableList<ActionAnalysisMetadata> actions = actionsWrapper.getActions();
skyframeExecutor.injectCoverageReportData(actions);
artifactsToBuild.addAll(actionsWrapper.getCoverageOutputs());
}
}
// Tests. This must come last, so that the exclusive tests are scheduled after everything else.
scheduleTestsIfRequested(parallelTests, exclusiveTests, topLevelOptions, allTargetsToTest);
String error = createErrorMessage(loadingResult, skyframeAnalysisResult);
final WalkableGraph graph = skyframeAnalysisResult.getWalkableGraph();
final ActionGraph actionGraph = new ActionGraph() {
@Nullable
@Override
public ActionAnalysisMetadata getGeneratingAction(Artifact artifact) {
ArtifactOwner artifactOwner = artifact.getArtifactOwner();
if (artifactOwner instanceof ActionLookupValue.ActionLookupKey) {
SkyKey key = ActionLookupValue.key((ActionLookupValue.ActionLookupKey) artifactOwner);
ActionLookupValue val;
try {
val = (ActionLookupValue) graph.getValue(key);
} catch (InterruptedException e) {
throw new IllegalStateException("Interruption not expected from this graph: " + key, e);
}
return val == null ? null : val.getGeneratingAction(artifact);
}
return null;
}
};
return new AnalysisResult(configuredTargets, aspects, allTargetsToTest, error, actionGraph, artifactsToBuild, parallelTests, exclusiveTests, topLevelOptions, skyframeAnalysisResult.getPackageRoots(), loadingResult.getWorkspaceName());
}
use of com.google.devtools.build.lib.actions.ActionAnalysisMetadata in project bazel by bazelbuild.
the class ArtifactFunction method compute.
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws ArtifactFunctionException, InterruptedException {
OwnedArtifact ownedArtifact = (OwnedArtifact) skyKey.argument();
Artifact artifact = ownedArtifact.getArtifact();
if (artifact.isSourceArtifact()) {
try {
return createSourceValue(artifact, ownedArtifact.isMandatory(), env);
} catch (MissingInputFileException e) {
// is potentially used to report root causes.
throw new ArtifactFunctionException(e, Transience.TRANSIENT);
}
}
ActionAnalysisMetadata actionMetadata = extractActionFromArtifact(artifact, env);
if (actionMetadata == null) {
return null;
}
// actions, execute those actions in parallel and then aggregate the action execution results.
if (artifact.isTreeArtifact() && actionMetadata instanceof ActionTemplate) {
// Create the directory structures for the output TreeArtifact first.
try {
FileSystemUtils.createDirectoryAndParents(artifact.getPath());
} catch (IOException e) {
env.getListener().handle(Event.error(String.format("Failed to create output directory for TreeArtifact %s: %s", artifact, e.getMessage())));
throw new ArtifactFunctionException(e, Transience.TRANSIENT);
}
return createTreeArtifactValueFromActionTemplate((ActionTemplate) actionMetadata, artifact, env);
} else {
Preconditions.checkState(actionMetadata instanceof Action, "%s is not a proper Action object and therefore cannot be executed", actionMetadata);
Action action = (Action) actionMetadata;
ActionExecutionValue actionValue = (ActionExecutionValue) env.getValue(ActionExecutionValue.key(action));
if (actionValue == null) {
return null;
}
if (artifact.isTreeArtifact()) {
// TreeArtifactValue.
return Preconditions.checkNotNull(actionValue.getTreeArtifactValue(artifact), artifact);
} else if (isAggregatingValue(action)) {
return createAggregatingValue(artifact, action, actionValue.getArtifactValue(artifact), env);
} else {
return createSimpleFileArtifactValue(artifact, action, actionValue, env);
}
}
}
Aggregations