Search in sources :

Example 11 with WalkableGraph

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));
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) WalkableGraph(com.google.devtools.build.skyframe.WalkableGraph) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Test(org.junit.Test)

Example 12 with WalkableGraph

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));
}
Also used : WalkableGraph(com.google.devtools.build.skyframe.WalkableGraph) Test(org.junit.Test)

Example 13 with 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")));
}
Also used : WalkableGraph(com.google.devtools.build.skyframe.WalkableGraph) Test(org.junit.Test)

Example 14 with WalkableGraph

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);
}
Also used : WalkableGraph(com.google.devtools.build.skyframe.WalkableGraph) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) IOException(java.io.IOException) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) Test(org.junit.Test)

Example 15 with WalkableGraph

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();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) WalkableGraph(com.google.devtools.build.skyframe.WalkableGraph) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Test(org.junit.Test)

Aggregations

WalkableGraph (com.google.devtools.build.skyframe.WalkableGraph)18 Test (org.junit.Test)13 SkyKey (com.google.devtools.build.skyframe.SkyKey)9 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)6 Label (com.google.devtools.build.lib.cmdline.Label)3 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)2 NoSuchTargetException (com.google.devtools.build.lib.packages.NoSuchTargetException)2 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Function (com.google.common.base.Function)1 Predicate (com.google.common.base.Predicate)1 ActionAnalysisMetadata (com.google.devtools.build.lib.actions.ActionAnalysisMetadata)1 ActionGraph (com.google.devtools.build.lib.actions.ActionGraph)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 ArtifactOwner (com.google.devtools.build.lib.actions.ArtifactOwner)1 TargetParsingException (com.google.devtools.build.lib.cmdline.TargetParsingException)1 Target (com.google.devtools.build.lib.packages.Target)1 ParseFailureListener (com.google.devtools.build.lib.pkgcache.ParseFailureListener)1 CoverageReportActionsWrapper (com.google.devtools.build.lib.rules.test.CoverageReportActionFactory.CoverageReportActionsWrapper)1