use of com.google.devtools.build.skyframe.WalkableGraph in project bazel by bazelbuild.
the class PrepareDepsOfTargetsUnderDirectoryFunctionTest method testTargetFilterSensitivity.
@Test
public void testTargetFilterSensitivity() throws Exception {
// Given a package "a" with a genrule "a" that depends on a target in package "b", and a test
// rule "aTest",
createPackages();
// When package "a" is evaluated under a test-only filtering policy,
SkyKey key = createPrepDepsKey(rootDirectory, new PathFragment("a"), ImmutableSet.<PathFragment>of(), FilteringPolicies.FILTER_TESTS);
EvaluationResult<?> evaluationResult = getEvaluationResult(key);
WalkableGraph graph = Preconditions.checkNotNull(evaluationResult.getWalkableGraph());
// Then the TransitiveTraversalValue for "@//a:a" is not evaluated,
SkyKey aaKey = TransitiveTraversalValue.key(Label.create("@//a", "a"));
assertThat(exists(aaKey, graph)).isFalse();
// But the TransitiveTraversalValue for "@//a:aTest" is.
SkyKey aaTestKey = TransitiveTraversalValue.key(Label.create("@//a", "aTest"));
assertThat(exists(aaTestKey, graph)).isTrue();
}
use of com.google.devtools.build.skyframe.WalkableGraph in project bazel by bazelbuild.
the class PrepareDepsOfTargetsUnderDirectoryFunctionTest method testSubdirectoryExclusion.
@Test
public void testSubdirectoryExclusion() throws Exception {
// Given a package "a" with two packages below it, "a/b" and "a/c",
scratch.file("a/BUILD");
scratch.file("a/b/BUILD");
scratch.file("a/c/BUILD");
// When the top package is evaluated via PrepareDepsOfTargetsUnderDirectoryValue with "a/b"
// excluded,
PathFragment excludedPathFragment = new PathFragment("a/b");
SkyKey key = createPrepDepsKey(rootDirectory, new PathFragment("a"), ImmutableSet.of(excludedPathFragment));
SkyKey collectkey = createCollectPackagesKey(rootDirectory, new PathFragment("a"), ImmutableSet.of(excludedPathFragment));
EvaluationResult<?> evaluationResult = getEvaluationResult(key, collectkey);
CollectPackagesUnderDirectoryValue value = (CollectPackagesUnderDirectoryValue) evaluationResult.getWalkableGraph().getValue(createCollectPackagesKey(rootDirectory, new PathFragment("a"), ImmutableSet.of(excludedPathFragment)));
// Then the value reports that "a" is a package,
assertThat(value.isDirectoryPackage()).isTrue();
// And only the subdirectory corresponding to "a/c" is present in the result,
RootedPath onlySubdir = Iterables.getOnlyElement(value.getSubdirectoryTransitivelyContainsPackagesOrErrors().keySet());
assertThat(onlySubdir.getRelativePath()).isEqualTo(new PathFragment("a/c"));
// And the "a/c" subdirectory reports a package under it.
assertThat(value.getSubdirectoryTransitivelyContainsPackagesOrErrors().get(onlySubdir)).isTrue();
// Also, the computation graph does not contain a cached value for "a/b".
WalkableGraph graph = Preconditions.checkNotNull(evaluationResult.getWalkableGraph());
assertFalse(exists(createPrepDepsKey(rootDirectory, excludedPathFragment, ImmutableSet.<PathFragment>of()), graph));
// And the computation graph does contain a cached value for "a/c" with the empty set excluded,
// because that key was evaluated.
assertTrue(exists(createPrepDepsKey(rootDirectory, new PathFragment("a/c"), ImmutableSet.<PathFragment>of()), graph));
}
use of com.google.devtools.build.skyframe.WalkableGraph in project bazel by bazelbuild.
the class SkyframeLabelVisitorTestCase method getVisitedLabels.
/**
* Returns the set of labels that were visited in the loading of the given starting labels.
* Semantics are somewhat subtle in case of errors. The returned set always contains the starting
* labels, even if they were not successfully loaded, but does not contain other unsuccessfully
* loaded targets.
*/
public static Set<Label> getVisitedLabels(Iterable<Label> startingLabels, SkyframeExecutor skyframeExecutor) throws InterruptedException {
final WalkableGraph graph = new DelegatingWalkableGraph(((InMemoryMemoizingEvaluator) skyframeExecutor.getEvaluatorForTesting()).getGraphForTesting());
List<SkyKey> startingKeys = new ArrayList<>();
for (Label label : startingLabels) {
startingKeys.add(TransitiveTargetValue.key(label));
}
Iterable<SkyKey> nodesToVisit = new ArrayList<>(startingKeys);
Set<SkyKey> visitedNodes = new HashSet<>();
while (!Iterables.isEmpty(nodesToVisit)) {
List<SkyKey> existingNodes = new ArrayList<>();
for (SkyKey key : nodesToVisit) {
if (exists(key, graph) && graph.getValue(key) != null && visitedNodes.add(key)) {
existingNodes.add(key);
}
}
nodesToVisit = Iterables.filter(Iterables.concat(graph.getDirectDeps(existingNodes).values()), new Predicate<SkyKey>() {
@Override
public boolean apply(SkyKey skyKey) {
return skyKey.functionName().equals(SkyFunctions.TRANSITIVE_TARGET);
}
});
}
visitedNodes.addAll(startingKeys);
return ImmutableSet.copyOf(Collections2.transform(visitedNodes, new Function<SkyKey, Label>() {
@Override
public Label apply(SkyKey skyKey) {
return (Label) skyKey.argument();
}
}));
}
use of com.google.devtools.build.skyframe.WalkableGraph 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.skyframe.WalkableGraph in project bazel by bazelbuild.
the class SkyframeTargetPatternEvaluator method parseTargetPatternKeys.
ResolvedTargets<Target> parseTargetPatternKeys(List<String> targetPattern, Iterable<SkyKey> patternSkyKeys, int numThreads, boolean keepGoing, ExtendedEventHandler eventHandler, TargetPatternsResultBuilder finalTargetSetEvaluator) throws InterruptedException, TargetParsingException {
EvaluationResult<TargetPatternValue> result = skyframeExecutor.targetPatterns(patternSkyKeys, numThreads, keepGoing, eventHandler);
String errorMessage = null;
for (SkyKey key : patternSkyKeys) {
TargetPatternValue resultValue = result.get(key);
if (resultValue != null) {
ResolvedTargets<Label> results = resultValue.getTargets();
if (((TargetPatternValue.TargetPatternKey) key.argument()).isNegative()) {
finalTargetSetEvaluator.addLabelsOfNegativePattern(results);
} else {
finalTargetSetEvaluator.addLabelsOfPositivePattern(results);
}
} else {
TargetPatternValue.TargetPatternKey patternKey = (TargetPatternValue.TargetPatternKey) key.argument();
String rawPattern = patternKey.getPattern();
ErrorInfo error = result.errorMap().get(key);
if (error == null) {
Preconditions.checkState(!keepGoing);
continue;
}
if (error.getException() != null) {
// This exception may not be a TargetParsingException because in a nokeep_going build, the
// target pattern parser may swallow a NoSuchPackageException but the framework will
// bubble it up anyway.
Preconditions.checkArgument(!keepGoing || error.getException() instanceof TargetParsingException, error);
errorMessage = error.getException().getMessage();
} else if (!Iterables.isEmpty(error.getCycleInfo())) {
errorMessage = "cycles detected during target parsing";
skyframeExecutor.getCyclesReporter().reportCycles(error.getCycleInfo(), key, eventHandler);
} else {
throw new IllegalStateException(error.toString());
}
if (keepGoing) {
eventHandler.handle(Event.error("Skipping '" + rawPattern + "': " + errorMessage));
eventHandler.post(PatternExpandingError.skipped(rawPattern, errorMessage));
}
finalTargetSetEvaluator.setError();
if (eventHandler instanceof ParseFailureListener) {
ParseFailureListener parseListener = (ParseFailureListener) eventHandler;
parseListener.parsingError(rawPattern, errorMessage);
}
}
}
if (result.hasError()) {
Preconditions.checkState(errorMessage != null, "unexpected errors: %s", result.errorMap());
finalTargetSetEvaluator.setError();
if (!keepGoing) {
eventHandler.post(PatternExpandingError.failed(targetPattern, errorMessage));
throw new TargetParsingException(errorMessage);
}
}
WalkableGraph walkableGraph = Preconditions.checkNotNull(result.getWalkableGraph(), result);
return finalTargetSetEvaluator.build(walkableGraph);
}
Aggregations