use of com.google.devtools.build.lib.packages.NoSuchTargetException in project bazel by bazelbuild.
the class PackageCacheTest method assertLabelValidity.
private void assertLabelValidity(boolean expected, String labelString) throws Exception {
Label label = Label.parseAbsolute(labelString);
boolean actual = false;
String error = null;
try {
getTarget(label);
actual = true;
} catch (NoSuchPackageException | NoSuchTargetException e) {
error = e.getMessage();
}
if (actual != expected) {
fail("assertLabelValidity(" + label + ") " + actual + ", not equal to expected value " + expected + " (error=" + error + ")");
}
}
use of com.google.devtools.build.lib.packages.NoSuchTargetException in project bazel by bazelbuild.
the class PackageFunctionTest method testIncrementalSkyframeHybridGlobbingOnDanglingSymlink.
// Regression test for the two ugly consequences of a bug where GlobFunction incorrectly matched
// dangling symlinks.
@Test
public void testIncrementalSkyframeHybridGlobbingOnDanglingSymlink() throws Exception {
Path packageDirPath = scratch.file("foo/BUILD", "exports_files(glob(['*.txt']))").getParentDirectory();
scratch.file("foo/existing.txt");
FileSystemUtils.ensureSymbolicLink(packageDirPath.getChild("dangling.txt"), "nope");
preparePackageLoading(rootDirectory);
SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//foo"));
PackageValue value = validPackage(skyKey);
assertFalse(value.getPackage().containsErrors());
assertThat(value.getPackage().getTarget("existing.txt").getName()).isEqualTo("existing.txt");
try {
value.getPackage().getTarget("dangling.txt");
fail();
} catch (NoSuchTargetException expected) {
}
scratch.overwriteFile("foo/BUILD", "exports_files(glob(['*.txt']))", "#some-irrelevant-comment");
getSkyframeExecutor().invalidateFilesUnderPathForTesting(reporter, ModifiedFileSet.builder().modify(new PathFragment("foo/BUILD")).build(), rootDirectory);
value = validPackage(skyKey);
assertFalse(value.getPackage().containsErrors());
assertThat(value.getPackage().getTarget("existing.txt").getName()).isEqualTo("existing.txt");
try {
value.getPackage().getTarget("dangling.txt");
fail();
} catch (NoSuchTargetException expected) {
// One consequence of the bug was that dangling symlinks were matched by globs evaluated by
// Skyframe globbing, meaning there would incorrectly be corresponding targets in packages
// that had skyframe cache hits during skyframe hybrid globbing.
}
scratch.file("foo/nope");
getSkyframeExecutor().invalidateFilesUnderPathForTesting(reporter, ModifiedFileSet.builder().modify(new PathFragment("foo/nope")).build(), rootDirectory);
PackageValue newValue = validPackage(skyKey);
assertFalse(newValue.getPackage().containsErrors());
assertThat(newValue.getPackage().getTarget("existing.txt").getName()).isEqualTo("existing.txt");
// Another consequence of the bug is that change pruning would incorrectly cut off changes that
// caused a dangling symlink potentially matched by a glob to come into existence.
assertThat(newValue.getPackage().getTarget("dangling.txt").getName()).isEqualTo("dangling.txt");
assertThat(newValue.getPackage()).isNotSameAs(value.getPackage());
}
use of com.google.devtools.build.lib.packages.NoSuchTargetException in project bazel by bazelbuild.
the class PackageFunctionTest method testRecursiveGlobNeverMatchesPackageDirectory.
// Regression test for Skyframe globbing incorrectly matching the package's directory path on
// 'glob(['**'], exclude_directories = 0)'. We test for this directly by triggering
// hybrid globbing (gives coverage for both legacy globbing and skyframe globbing).
@Test
public void testRecursiveGlobNeverMatchesPackageDirectory() throws Exception {
scratch.file("foo/BUILD", "[sh_library(name = x + '-matched') for x in glob(['**'], exclude_directories = 0)]");
scratch.file("foo/bar");
preparePackageLoading(rootDirectory);
SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//foo"));
PackageValue value = validPackage(skyKey);
assertFalse(value.getPackage().containsErrors());
assertThat(value.getPackage().getTarget("bar-matched").getName()).isEqualTo("bar-matched");
try {
value.getPackage().getTarget("-matched");
fail();
} catch (NoSuchTargetException expected) {
}
scratch.overwriteFile("foo/BUILD", "[sh_library(name = x + '-matched') for x in glob(['**'], exclude_directories = 0)]", "#some-irrelevant-comment");
getSkyframeExecutor().invalidateFilesUnderPathForTesting(reporter, ModifiedFileSet.builder().modify(new PathFragment("foo/BUILD")).build(), rootDirectory);
value = validPackage(skyKey);
assertFalse(value.getPackage().containsErrors());
assertThat(value.getPackage().getTarget("bar-matched").getName()).isEqualTo("bar-matched");
try {
value.getPackage().getTarget("-matched");
fail();
} catch (NoSuchTargetException expected) {
}
}
Aggregations