use of com.google.devtools.build.skyframe.WalkableGraph in project bazel by bazelbuild.
the class RecursivePkgFunctionTest 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 for recursive package values, and "a/b" is excluded,
PathFragment excludedPathFragment = new PathFragment("a/b");
SkyKey key = buildRecursivePkgKey(rootDirectory, new PathFragment("a"), ImmutableSet.of(excludedPathFragment));
EvaluationResult<RecursivePkgValue> evaluationResult = getEvaluationResult(key);
RecursivePkgValue value = evaluationResult.get(key);
// Then the package corresponding to "a/b" is not present in the result,
assertThat(value.getPackages()).doesNotContain("a/b");
// And the "a" package and "a/c" package are.
assertThat(value.getPackages()).contains("a");
assertThat(value.getPackages()).contains("a/c");
// Also, the computation graph does not contain a cached value for "a/b".
WalkableGraph graph = Preconditions.checkNotNull(evaluationResult.getWalkableGraph());
assertFalse(exists(buildRecursivePkgKey(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(buildRecursivePkgKey(rootDirectory, new PathFragment("a/c"), ImmutableSet.<PathFragment>of()), graph));
}
use of com.google.devtools.build.skyframe.WalkableGraph in project bazel by bazelbuild.
the class PrepareDepsOfPatternsFunctionTest method testFunctionLoadsTargetAndNotUnspecifiedTargets.
@Test
public void testFunctionLoadsTargetAndNotUnspecifiedTargets() throws Exception {
// Given a package "//foo" with independent target rules ":foo" and ":foo2",
createFooAndFoo2(/*dependent=*/
false);
// Given a target pattern sequence consisting of a single-target pattern for "//foo",
ImmutableList<String> patternSequence = ImmutableList.of("//foo");
// When PrepareDepsOfPatternsFunction successfully completes evaluation,
WalkableGraph walkableGraph = getGraphFromPatternsEvaluation(patternSequence);
// Then the graph contains a value for the target "@//foo:foo",
assertValidValue(walkableGraph, getKeyForLabel(Label.create("@//foo", "foo")));
// And the graph does not contain a value for the target "@//foo:foo2".
assertFalse(exists(getKeyForLabel(Label.create("@//foo", "foo2")), walkableGraph));
}
use of com.google.devtools.build.skyframe.WalkableGraph in project bazel by bazelbuild.
the class PrepareDepsOfPatternsFunctionTest method testFunctionLoadsTargetDependencies.
@Test
public void testFunctionLoadsTargetDependencies() throws Exception {
// Given a package "//foo" with target rules ":foo" and ":foo2",
// And given ":foo" depends on ":foo2",
createFooAndFoo2(/*dependent=*/
true);
// Given a target pattern sequence consisting of a single-target pattern for "//foo",
ImmutableList<String> patternSequence = ImmutableList.of("//foo");
// When PrepareDepsOfPatternsFunction successfully completes evaluation,
WalkableGraph walkableGraph = getGraphFromPatternsEvaluation(patternSequence);
// Then the graph contains an entry for ":foo"'s dependency, ":foo2".
assertValidValue(walkableGraph, getKeyForLabel(Label.create("@//foo", "foo2")));
}
use of com.google.devtools.build.skyframe.WalkableGraph in project bazel by bazelbuild.
the class PrepareDepsOfPatternsFunctionTest method testDependencyTraversalNoSuchPackageException.
@Test
public void testDependencyTraversalNoSuchPackageException() throws Exception {
// Given a package "//foo" with a target ":foo" that has a dependency on a non-existent target
// "//bar:bar" in a non-existent package "//bar",
createFooWithDependencyOnMissingBarPackage();
// Given a target pattern sequence consisting of a single-target pattern for "//foo",
ImmutableList<String> patternSequence = ImmutableList.of("//foo");
// When PrepareDepsOfPatternsFunction completes evaluation,
WalkableGraph walkableGraph = getGraphFromPatternsEvaluation(patternSequence);
// Then the graph contains an entry for ":foo",
assertValidValue(walkableGraph, getKeyForLabel(Label.create("@//foo", "foo")), /*expectTransitiveException=*/
true);
// And an entry with a NoSuchPackageException for "//bar:bar",
Exception e = assertException(walkableGraph, getKeyForLabel(Label.create("@//bar", "bar")));
assertThat(e).isInstanceOf(NoSuchPackageException.class);
}
use of com.google.devtools.build.skyframe.WalkableGraph in project bazel by bazelbuild.
the class PrepareDepsOfTargetsUnderDirectoryFunctionTest method testExcludedSubdirectoryGettingPassedDown.
@Test
public void testExcludedSubdirectoryGettingPassedDown() throws Exception {
// Given a package "a", and a package below it in "a/b/c", and a non-BUILD file below it in
// "a/b/d",
scratch.file("a/BUILD");
scratch.file("a/b/c/BUILD");
scratch.file("a/b/d/helloworld");
// When the top package is evaluated for recursive package values, and "a/b/c" is excluded,
ImmutableSet<PathFragment> excludedPaths = ImmutableSet.of(new PathFragment("a/b/c"));
SkyKey key = createPrepDepsKey(rootDirectory, new PathFragment("a"), excludedPaths);
SkyKey collectKey = createCollectPackagesKey(rootDirectory, new PathFragment("a"), excludedPaths);
EvaluationResult<?> evaluationResult = getEvaluationResult(key, collectKey);
CollectPackagesUnderDirectoryValue value = (CollectPackagesUnderDirectoryValue) evaluationResult.getWalkableGraph().getValue(createCollectPackagesKey(rootDirectory, new PathFragment("a"), excludedPaths));
// Then the value reports that "a" is a package,
assertThat(value.isDirectoryPackage()).isTrue();
// And the subdirectory corresponding to "a/b" is present in the result,
RootedPath onlySubdir = Iterables.getOnlyElement(value.getSubdirectoryTransitivelyContainsPackagesOrErrors().keySet());
assertThat(onlySubdir.getRelativePath()).isEqualTo(new PathFragment("a/b"));
// And the "a/b" subdirectory does not report a package under it (because it got excluded).
assertThat(value.getSubdirectoryTransitivelyContainsPackagesOrErrors().get(onlySubdir)).isFalse();
// Also, the computation graph contains a cached value for "a/b" with "a/b/c" excluded, because
// "a/b/c" does live underneath "a/b".
WalkableGraph graph = Preconditions.checkNotNull(evaluationResult.getWalkableGraph());
SkyKey abKey = createCollectPackagesKey(rootDirectory, new PathFragment("a/b"), excludedPaths);
assertThat(exists(abKey, graph)).isTrue();
CollectPackagesUnderDirectoryValue abValue = (CollectPackagesUnderDirectoryValue) Preconditions.checkNotNull(graph.getValue(abKey));
// And that value says that "a/b" is not a package,
assertThat(abValue.isDirectoryPackage()).isFalse();
// And only the subdirectory "a/b/d" is present in that value,
RootedPath abd = Iterables.getOnlyElement(abValue.getSubdirectoryTransitivelyContainsPackagesOrErrors().keySet());
assertThat(abd.getRelativePath()).isEqualTo(new PathFragment("a/b/d"));
// And no package is under "a/b/d".
assertThat(abValue.getSubdirectoryTransitivelyContainsPackagesOrErrors().get(abd)).isFalse();
}
Aggregations