use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class PackageFunctionTest method testPropagatesFilesystemInconsistencies.
@Test
public void testPropagatesFilesystemInconsistencies() throws Exception {
reporter.removeHandler(failFastHandler);
RecordingDifferencer differencer = getSkyframeExecutor().getDifferencerForTesting();
Path pkgRoot = getSkyframeExecutor().getPathEntries().get(0);
Path fooBuildFile = scratch.file("foo/BUILD");
Path fooDir = fooBuildFile.getParentDirectory();
// Our custom filesystem says "foo/BUILD" exists but its parent "foo" is a file.
FileStatus inconsistentParentFileStatus = new FileStatus() {
@Override
public boolean isFile() {
return true;
}
@Override
public boolean isDirectory() {
return false;
}
@Override
public boolean isSymbolicLink() {
return false;
}
@Override
public boolean isSpecialFile() {
return false;
}
@Override
public long getSize() throws IOException {
return 0;
}
@Override
public long getLastModifiedTime() throws IOException {
return 0;
}
@Override
public long getLastChangeTime() throws IOException {
return 0;
}
@Override
public long getNodeId() throws IOException {
return 0;
}
};
fs.stubStat(fooDir, inconsistentParentFileStatus);
RootedPath pkgRootedPath = RootedPath.toRootedPath(pkgRoot, fooDir);
SkyValue fooDirValue = FileStateValue.create(pkgRootedPath, tsgm);
differencer.inject(ImmutableMap.of(FileStateValue.key(pkgRootedPath), fooDirValue));
SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//foo"));
String expectedMessage = "/workspace/foo/BUILD exists but its parent path /workspace/foo isn't " + "an existing directory";
EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate(getSkyframeExecutor(), skyKey, /*keepGoing=*/
false, reporter);
assertTrue(result.hasError());
ErrorInfo errorInfo = result.getError(skyKey);
String errorMessage = errorInfo.getException().getMessage();
assertThat(errorMessage).contains("Inconsistent filesystem operations");
assertThat(errorMessage).contains(expectedMessage);
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class PackageFunctionTest method testPropagatesFilesystemInconsistencies_Globbing.
@Test
public void testPropagatesFilesystemInconsistencies_Globbing() throws Exception {
reporter.removeHandler(failFastHandler);
RecordingDifferencer differencer = getSkyframeExecutor().getDifferencerForTesting();
Path pkgRoot = getSkyframeExecutor().getPathEntries().get(0);
scratch.file("foo/BUILD", "subinclude('//a:a')", "sh_library(name = 'foo', srcs = glob(['bar/**/baz.sh']))");
scratch.file("a/BUILD");
scratch.file("a/a");
Path bazFile = scratch.file("foo/bar/baz/baz.sh");
Path bazDir = bazFile.getParentDirectory();
Path barDir = bazDir.getParentDirectory();
// Our custom filesystem says "foo/bar/baz" does not exist but it also says that "foo/bar"
// has a child directory "baz".
fs.stubStat(bazDir, null);
RootedPath barDirRootedPath = RootedPath.toRootedPath(pkgRoot, barDir);
FileStateValue barDirFileStateValue = FileStateValue.create(barDirRootedPath, tsgm);
FileValue barDirFileValue = FileValue.value(barDirRootedPath, barDirFileStateValue, barDirRootedPath, barDirFileStateValue);
DirectoryListingValue barDirListing = DirectoryListingValue.value(barDirRootedPath, barDirFileValue, DirectoryListingStateValue.create(ImmutableList.of(new Dirent("baz", Dirent.Type.DIRECTORY))));
differencer.inject(ImmutableMap.of(DirectoryListingValue.key(barDirRootedPath), barDirListing));
SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//foo"));
String expectedMessage = "/workspace/foo/bar/baz is no longer an existing directory";
EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate(getSkyframeExecutor(), skyKey, /*keepGoing=*/
false, reporter);
assertTrue(result.hasError());
ErrorInfo errorInfo = result.getError(skyKey);
String errorMessage = errorInfo.getException().getMessage();
assertThat(errorMessage).contains("Inconsistent filesystem operations");
assertThat(errorMessage).contains(expectedMessage);
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class PackageLookupFunctionTest method testBlacklistedPackage.
@Test
public void testBlacklistedPackage() throws Exception {
scratch.file("blacklisted/subdir/BUILD");
scratch.file("blacklisted/BUILD");
PrecomputedValue.BLACKLISTED_PACKAGE_PREFIXES_FILE.set(differencer, new PathFragment("config/blacklisted.txt"));
Path blacklist = scratch.file("config/blacklisted.txt", "blacklisted");
ImmutableSet<String> pkgs = ImmutableSet.of("blacklisted/subdir", "blacklisted");
for (String pkg : pkgs) {
PackageLookupValue packageLookupValue = lookupPackage(pkg);
assertFalse(packageLookupValue.packageExists());
assertEquals(ErrorReason.DELETED_PACKAGE, packageLookupValue.getErrorReason());
assertNotNull(packageLookupValue.getErrorMsg());
}
scratch.overwriteFile("config/blacklisted.txt", "not_blacklisted");
RootedPath rootedBlacklist = RootedPath.toRootedPath(blacklist.getParentDirectory().getParentDirectory(), new PathFragment("config/blacklisted.txt"));
differencer.invalidate(ImmutableSet.of(FileStateValue.key(rootedBlacklist)));
for (String pkg : pkgs) {
PackageLookupValue packageLookupValue = lookupPackage(pkg);
assertTrue(packageLookupValue.packageExists());
}
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunctionTest method testSwitchPackageRootsWhenUsingMultiplePackagePaths.
@Test
public void testSwitchPackageRootsWhenUsingMultiplePackagePaths() throws Exception {
// Layout:
// pp1://a/BUILD
// pp1://a/file.a
// pp1://a/b.sym -> b/ (only created later)
// pp1://a/b/
// pp1://a/b/file.fake
// pp1://a/subdir/file.b
//
// pp2://a/BUILD
// pp2://a/b/
// pp2://a/b/BUILD
// pp2://a/b/file.a
// pp2://a/subdir.fake/
// pp2://a/subdir.fake/file.fake
//
// Notice that pp1://a/b will be overlaid by pp2://a/b as the latter has a BUILD file and that
// takes precedence. On the other hand the package definition pp2://a/BUILD will be ignored
// since package //a is already defined under pp1.
//
// Notice also that pp1://a/b.sym is a relative symlink pointing to b/. This should be resolved
// to the definition of //a/b/ under pp1, not under pp2.
// Set the package paths.
pkgLocator.set(new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory.getRelative("pp1"), rootDirectory.getRelative("pp2"))));
PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, pkgLocator.get());
Artifact aBuildArtifact = sourceArtifactUnderPackagePath("a/BUILD", "pp1");
Artifact bBuildArtifact = sourceArtifactUnderPackagePath("a/b/BUILD", "pp2");
RootedPath pp1aBuild = createFile(rootedPath(aBuildArtifact));
RootedPath pp1aFileA = createFile(siblingOf(pp1aBuild, "file.a"));
RootedPath pp1bFileFake = createFile(siblingOf(pp1aBuild, "b/file.fake"));
RootedPath pp1aSubdirFileB = createFile(siblingOf(pp1aBuild, "subdir/file.b"));
RootedPath pp2aBuild = createFile(rootedPath("a/BUILD", "pp2"));
RootedPath pp2bBuild = createFile(rootedPath(bBuildArtifact));
RootedPath pp2bFileA = createFile(siblingOf(pp2bBuild, "file.a"));
createFile(siblingOf(pp2aBuild, "subdir.fake/file.fake"));
// Traverse //a including subpackages. The result should contain the pp1-definition of //a and
// the pp2-definition of //a/b.
traverseAndAssertFiles(pkgRoot(parentOf(rootedPath(aBuildArtifact)), CROSS), regularFileForTesting(pp1aBuild), regularFileForTesting(pp1aFileA), regularFileForTesting(pp1aSubdirFileB), regularFileForTesting(pp2bBuild), regularFileForTesting(pp2bFileA));
// Traverse //a excluding subpackages. The result should only contain files from //a and not
// from //a/b.
traverseAndAssertFiles(pkgRoot(parentOf(rootedPath(aBuildArtifact)), DONT_CROSS), regularFileForTesting(pp1aBuild), regularFileForTesting(pp1aFileA), regularFileForTesting(pp1aSubdirFileB));
// Create a relative symlink pp1://a/b.sym -> b/. It will be resolved to the subdirectory
// pp1://a/b, even though a package definition pp2://a/b exists.
RootedPath pp1aBsym = siblingOf(pp1aFileA, "b.sym");
pp1aBsym.asPath().createSymbolicLink(new PathFragment("b"));
invalidateDirectory(parentOf(pp1aBsym));
// Traverse //a excluding subpackages. The relative symlink //a/b.sym points to the subdirectory
// a/b, i.e. the pp1-definition, even though there is a pp2-defined package //a/b and we expect
// to see b.sym/b.fake (not b/b.fake).
traverseAndAssertFiles(pkgRoot(parentOf(rootedPath(aBuildArtifact)), DONT_CROSS), regularFileForTesting(pp1aBuild), regularFileForTesting(pp1aFileA), regularFileForTesting(childOf(pp1aBsym, "file.fake")), symlinkToDirectoryForTesting(parentOf(pp1bFileFake), pp1aBsym, new PathFragment("b")), regularFileForTesting(pp1aSubdirFileB));
}
use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.
the class RecursiveFilesystemTraversalFunctionTest method assertTraversalOfFile.
private void assertTraversalOfFile(Artifact rootArtifact) throws Exception {
TraversalRequest traversalRoot = fileLikeRoot(rootArtifact, DONT_CROSS);
RootedPath rootedPath = createFile(rootedPath(rootArtifact), "foo");
// Assert that the SkyValue is built and looks right.
ResolvedFile expected = regularFileForTesting(rootedPath);
RecursiveFilesystemTraversalValue v1 = traverseAndAssertFiles(traversalRoot, expected);
assertThat(progressReceiver.invalidations).isEmpty();
assertThat(progressReceiver.evaluations).contains(v1);
progressReceiver.clear();
// Edit the file and verify that the value is rebuilt.
appendToFile(rootArtifact, "bar");
RecursiveFilesystemTraversalValue v2 = traverseAndAssertFiles(traversalRoot, expected);
assertThat(progressReceiver.invalidations).contains(rftvSkyKey(traversalRoot));
assertThat(progressReceiver.evaluations).contains(v2);
assertThat(v2).isNotEqualTo(v1);
assertTraversalRootHashesAreNotEqual(v1, v2);
progressReceiver.clear();
}
Aggregations