use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class PackageFunctionTest method testGlobWithExternalSymlink.
/**
* Tests that a symlink to a file outside of the package root is handled consistently. If the
* default behavior of Bazel was changed from {@code
* ExternalFileAction#DEPEND_ON_EXTERNAL_PKG_FOR_EXTERNAL_REPO_PATHS} to {@code
* ExternalFileAction#ASSUME_NON_EXISTENT_AND_IMMUTABLE_FOR_EXTERNAL_PATHS} then foo/link.sh
* should no longer appear in the srcs of //foo:foo. However, either way the srcs should be the
* same independent of the evaluation being incremental or clean.
*/
@Test
public void testGlobWithExternalSymlink() throws Exception {
scratch.file("foo/BUILD", "sh_library(name = 'foo', srcs = glob(['*.sh']))", "sh_library(name = 'bar', srcs = glob(['link.sh']))", "sh_library(name = 'baz', srcs = glob(['subdir_link/*.txt']))");
scratch.file("foo/ordinary.sh");
Path externalTarget = scratch.file("../ops/target.txt");
FileSystemUtils.ensureSymbolicLink(scratch.resolve("foo/link.sh"), externalTarget);
FileSystemUtils.ensureSymbolicLink(scratch.resolve("foo/subdir_link"), externalTarget.getParentDirectory());
preparePackageLoading(rootDirectory);
SkyKey fooKey = PackageValue.key(PackageIdentifier.parse("@//foo"));
PackageValue fooValue = validPackage(fooKey);
assertSrcs(fooValue, "foo", "//foo:link.sh", "//foo:ordinary.sh");
assertSrcs(fooValue, "bar", "//foo:link.sh");
assertSrcs(fooValue, "baz", "//foo:subdir_link/target.txt");
scratch.overwriteFile("foo/BUILD", "sh_library(name = 'foo', srcs = glob(['*.sh'])) #comment", "sh_library(name = 'bar', srcs = glob(['link.sh']))", "sh_library(name = 'baz', srcs = glob(['subdir_link/*.txt']))");
getSkyframeExecutor().invalidateFilesUnderPathForTesting(reporter, ModifiedFileSet.builder().modify(new PathFragment("foo/BUILD")).build(), rootDirectory);
PackageValue fooValue2 = validPackage(fooKey);
assertThat(fooValue2).isNotEqualTo(fooValue);
assertSrcs(fooValue2, "foo", "//foo:link.sh", "//foo:ordinary.sh");
assertSrcs(fooValue2, "bar", "//foo:link.sh");
assertSrcs(fooValue2, "baz", "//foo:subdir_link/target.txt");
}
use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class PackageFunctionTest method testBadWorkspaceFile.
@Test
public void testBadWorkspaceFile() throws Exception {
Path workspacePath = scratch.overwriteFile("WORKSPACE", "junk");
SkyKey skyKey = PackageValue.key(PackageIdentifier.createInMainRepo("external"));
getSkyframeExecutor().invalidate(Predicates.equalTo(com.google.devtools.build.lib.skyframe.FileStateValue.key(RootedPath.toRootedPath(workspacePath.getParentDirectory(), new PathFragment(workspacePath.getBaseName())))));
reporter.removeHandler(failFastHandler);
EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate(getSkyframeExecutor(), skyKey, /*keepGoing=*/
false, reporter);
assertFalse(result.hasError());
assertTrue(result.get(skyKey).getPackage().containsErrors());
}
use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class PackageLookupFunctionTest method testPackageLookupValueHashCodeAndEqualsContract.
@Test
public void testPackageLookupValueHashCodeAndEqualsContract() throws Exception {
Path root1 = rootDirectory.getRelative("root1");
Path root2 = rootDirectory.getRelative("root2");
// Our (seeming) duplication of parameters here is intentional. Some of the subclasses of
// PackageLookupValue are supposed to have reference equality semantics, and some are supposed
// to have logical equality semantics.
new EqualsTester().addEqualityGroup(PackageLookupValue.success(root1, BuildFileName.BUILD), PackageLookupValue.success(root1, BuildFileName.BUILD)).addEqualityGroup(PackageLookupValue.success(root2, BuildFileName.BUILD), PackageLookupValue.success(root2, BuildFileName.BUILD)).addEqualityGroup(PackageLookupValue.NO_BUILD_FILE_VALUE, PackageLookupValue.NO_BUILD_FILE_VALUE).addEqualityGroup(PackageLookupValue.DELETED_PACKAGE_VALUE, PackageLookupValue.DELETED_PACKAGE_VALUE).addEqualityGroup(PackageLookupValue.invalidPackageName("nope1"), PackageLookupValue.invalidPackageName("nope1")).addEqualityGroup(PackageLookupValue.invalidPackageName("nope2"), PackageLookupValue.invalidPackageName("nope2")).testEquals();
}
use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class TargetMarkerFunctionTest method testTargetFunctionRethrowsExceptions.
@Test
public void testTargetFunctionRethrowsExceptions() throws Exception {
reporter.removeHandler(failFastHandler);
scratch.file("a/BUILD", "sh_library(name = 'b/c')");
Path subpackageBuildFile = scratch.file("a/b/BUILD", "sh_library(name = 'c')");
fs.stubStatIOException(subpackageBuildFile, new IOException("nope"));
BuildFileNotFoundException exn = (BuildFileNotFoundException) getErrorFromTargetValue("//a:b/c");
assertThat(exn.getMessage()).contains("nope");
}
use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.
the class TimestampBuilderMediumTest method testPersistentCache_failedIntegrityCheckCausesActionReexecution.
@Test
public void testPersistentCache_failedIntegrityCheckCausesActionReexecution() throws Exception {
// [action] -> /hello
Artifact hello = createDerivedArtifact("hello");
Button button = createActionButton(emptySet, Sets.newHashSet(hello));
button.pressed = false;
buildArtifacts(persistentBuilder(cache), hello);
// built
assertTrue(button.pressed);
button.pressed = false;
buildArtifacts(persistentBuilder(cache), hello);
// not rebuilt
assertFalse(button.pressed);
hello.getPath().setWritable(true);
FileSystemUtils.writeContentAsLatin1(hello.getPath(), "new content");
button.pressed = false;
buildArtifacts(persistentBuilder(cache), hello);
// rebuilt
assertTrue(button.pressed);
button.pressed = false;
buildArtifacts(persistentBuilder(cache), hello);
// not rebuilt
assertFalse(button.pressed);
cache.save();
// Get filename index path and store a copy of it.
Path indexPath = Iterables.getOnlyElement(UnixGlob.forPath(cacheRoot).addPattern("filename_index*").globInterruptible());
Path indexCopy = scratch.resolve("index_copy");
FileSystemUtils.copyFile(indexPath, indexCopy);
// Add extra records to the action cache and indexer.
Artifact helloExtra = createDerivedArtifact("hello_extra");
Button buttonExtra = createActionButton(emptySet, Sets.newHashSet(helloExtra));
buildArtifacts(persistentBuilder(cache), helloExtra);
// built
assertTrue(buttonExtra.pressed);
cache.save();
assertTrue(indexPath.getFileSize() > indexCopy.getFileSize());
// Validate current cache.
buildArtifacts(persistentBuilder(createCache()), hello);
// not rebuilt
assertFalse(button.pressed);
// Restore outdated file index.
FileSystemUtils.copyFile(indexCopy, indexPath);
// Second attempt will initialize empty cache, causing rebuild.
try {
createCache();
fail("Expected IOException");
} catch (IOException e) {
assertThat(e.getMessage()).contains("Failed action cache referential integrity check");
}
// Validate cache with incorrect (out-of-date) filename index.
buildArtifacts(persistentBuilder(createCache()), hello);
// rebuilt due to the out-of-date index
assertTrue(button.pressed);
}
Aggregations