use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunctionTest method testTraversalOfDanglingSymlinkInADirectory.
@Test
public void testTraversalOfDanglingSymlinkInADirectory() throws Exception {
Artifact dirArtifact = sourceArtifact("a");
RootedPath file = createFile(childOf(dirArtifact, "file.txt"));
RootedPath link = rootedPath(sourceArtifact("a/dangling.sym"));
PathFragment linkTarget = new PathFragment("non_existent");
parentOf(link).asPath().createDirectory();
link.asPath().createSymbolicLink(linkTarget);
traverseAndAssertFiles(fileLikeRoot(dirArtifact, DONT_CROSS), regularFileForTesting(file), danglingSymlinkForTesting(link, linkTarget));
}
use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class RecursivePkgFunctionTest method testPackagesUnderMultipleRoots.
@Test
public void testPackagesUnderMultipleRoots() throws Exception {
Path root1 = rootDirectory.getRelative("root1");
Path root2 = rootDirectory.getRelative("root2");
scratch.file(root1 + "/WORKSPACE");
scratch.file(root2 + "/WORKSPACE");
scratch.file(root1 + "/a/BUILD");
scratch.file(root2 + "/a/b/BUILD");
setPackageCacheOptions("--package_path=" + "root1" + ":" + "root2");
RecursivePkgValue valueForRoot1 = buildRecursivePkgValue(root1, new PathFragment("a"));
String root1Pkg = Iterables.getOnlyElement(valueForRoot1.getPackages());
assertEquals(root1Pkg, "a");
RecursivePkgValue valueForRoot2 = buildRecursivePkgValue(root2, new PathFragment("a"));
String root2Pkg = Iterables.getOnlyElement(valueForRoot2.getPackages());
assertEquals(root2Pkg, "a/b");
}
use of com.google.devtools.build.lib.vfs.PathFragment 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.lib.vfs.PathFragment 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.lib.vfs.PathFragment in project bazel by bazelbuild.
the class PackageFunctionTest method testGlobOrderStable.
// Cast of srcs attribute to Iterable<Label>.
@SuppressWarnings("unchecked")
@Test
public void testGlobOrderStable() throws Exception {
scratch.file("foo/BUILD", "sh_library(name = 'foo', srcs = glob(['**/*.txt']))");
scratch.file("foo/b.txt");
scratch.file("foo/c/c.txt");
preparePackageLoading(rootDirectory);
SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//foo"));
PackageValue value = validPackage(skyKey);
assertThat((Iterable<Label>) value.getPackage().getTarget("foo").getAssociatedRule().getAttributeContainer().getAttr("srcs")).containsExactly(Label.parseAbsoluteUnchecked("//foo:b.txt"), Label.parseAbsoluteUnchecked("//foo:c/c.txt")).inOrder();
scratch.file("foo/d.txt");
getSkyframeExecutor().invalidateFilesUnderPathForTesting(reporter, ModifiedFileSet.builder().modify(new PathFragment("foo/d.txt")).build(), rootDirectory);
value = validPackage(skyKey);
assertThat((Iterable<Label>) value.getPackage().getTarget("foo").getAssociatedRule().getAttributeContainer().getAttr("srcs")).containsExactly(Label.parseAbsoluteUnchecked("//foo:b.txt"), Label.parseAbsoluteUnchecked("//foo:c/c.txt"), Label.parseAbsoluteUnchecked("//foo:d.txt")).inOrder();
}
Aggregations