Search in sources :

Example 21 with NoSuchTargetException

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 + ")");
    }
}
Also used : NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) Label(com.google.devtools.build.lib.cmdline.Label)

Example 22 with NoSuchTargetException

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

Example 23 with NoSuchTargetException

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

Aggregations

NoSuchTargetException (com.google.devtools.build.lib.packages.NoSuchTargetException)23 SkyKey (com.google.devtools.build.skyframe.SkyKey)13 Label (com.google.devtools.build.lib.cmdline.Label)12 Target (com.google.devtools.build.lib.packages.Target)12 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)9 Package (com.google.devtools.build.lib.packages.Package)9 Test (org.junit.Test)6 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)5 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)4 Attribute (com.google.devtools.build.lib.packages.Attribute)4 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)4 HashMap (java.util.HashMap)4 Nullable (javax.annotation.Nullable)4 Rule (com.google.devtools.build.lib.packages.Rule)3 SkyValue (com.google.devtools.build.skyframe.SkyValue)3 ValueOrException2 (com.google.devtools.build.skyframe.ValueOrException2)3 LinkedHashSet (java.util.LinkedHashSet)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 InconsistentAspectOrderException (com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException)2 MergedConfiguredTarget (com.google.devtools.build.lib.analysis.MergedConfiguredTarget)2