Search in sources :

Example 21 with Package

use of com.google.devtools.build.lib.packages.Package in project bazel by bazelbuild.

the class PackageCacheTest method testBrokenPackageOnMultiplePackagePathEntries.

@Test
public void testBrokenPackageOnMultiplePackagePathEntries() throws Exception {
    reporter.removeHandler(failFastHandler);
    setOptions("--package_path=.:.");
    scratch.file("x/y/BUILD");
    scratch.file("x/BUILD", "genrule(name = 'x',", "srcs = [],", "outs = ['y/z.h'],", "cmd  = '')");
    Package p = getPackage("x");
    assertTrue(p.containsErrors());
}
Also used : Package(com.google.devtools.build.lib.packages.Package) Test(org.junit.Test)

Example 22 with Package

use of com.google.devtools.build.lib.packages.Package in project bazel by bazelbuild.

the class PackageCacheTest method testModifiedBuildFileCausesReloadAfterSync.

@Test
public void testModifiedBuildFileCausesReloadAfterSync() throws Exception {
    Path path = scratch.file("pkg/BUILD", "cc_library(name = 'foo')");
    path.setLastModifiedTime(1000);
    Package oldPkg = getPackage("pkg");
    // modify BUILD file (and change its timestamp)
    path.delete();
    scratch.file("pkg/BUILD", "cc_library(name = 'bar')");
    // earlier; mtime doesn't have to advance
    path.setLastModifiedTime(999);
    // change not yet visible
    assertSame(oldPkg, getPackage("pkg"));
    invalidatePackages();
    Package newPkg = getPackage("pkg");
    assertNotSame(oldPkg, newPkg);
    assertNotNull(newPkg.getTarget("bar"));
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) Package(com.google.devtools.build.lib.packages.Package) Test(org.junit.Test)

Example 23 with Package

use of com.google.devtools.build.lib.packages.Package in project bazel by bazelbuild.

the class PackageCacheTest method testMovedBuildFileCausesReloadAfterSync.

@Test
public void testMovedBuildFileCausesReloadAfterSync() throws Exception {
    Path buildFile1 = scratch.file("pkg/BUILD", "cc_library(name = 'foo')");
    Path buildFile2 = scratch.file("/otherroot/pkg/BUILD", "cc_library(name = 'bar')");
    setOptions("--package_path=/workspace:/otherroot");
    Package oldPkg = getPackage("pkg");
    // change not yet visible
    assertSame(oldPkg, getPackage("pkg"));
    assertEquals(buildFile1, oldPkg.getFilename());
    assertEquals(rootDirectory, oldPkg.getSourceRoot());
    buildFile1.delete();
    invalidatePackages();
    Package newPkg = getPackage("pkg");
    assertNotSame(oldPkg, newPkg);
    assertEquals(buildFile2, newPkg.getFilename());
    assertEquals(scratch.dir("/otherroot"), newPkg.getSourceRoot());
// TODO(bazel-team): (2009) test BUILD file moves in the other direction too.
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) Package(com.google.devtools.build.lib.packages.Package) Test(org.junit.Test)

Example 24 with Package

use of com.google.devtools.build.lib.packages.Package in project bazel by bazelbuild.

the class IncrementalLoadingTest method testIrrelevantFileInSubdirDoesntReloadPackage.

@Test
public void testIrrelevantFileInSubdirDoesntReloadPackage() throws Exception {
    tester.addFile("pkg/BUILD", "sh_library(name = 'pkg', srcs = glob(['**/*.sh']))");
    tester.addFile("pkg/pkg.sh", "#!/bin/bash");
    tester.addFile("pkg/bar/bar.sh", "#!/bin/bash");
    Package pkg = tester.getTarget("//pkg:pkg").getPackage();
    // Write file in directory to force reload of top-level glob.
    tester.addFile("pkg/irrelevant_file");
    // Subglob is also reloaded.
    tester.addFile("pkg/bar/irrelevant_file");
    assertSame(pkg, tester.getTarget("//pkg:pkg").getPackage());
}
Also used : Package(com.google.devtools.build.lib.packages.Package) Test(org.junit.Test)

Example 25 with Package

use of com.google.devtools.build.lib.packages.Package in project bazel by bazelbuild.

the class GraphBackedRecursivePackageProvider method bulkGetPackages.

@Override
public Map<PackageIdentifier, Package> bulkGetPackages(Iterable<PackageIdentifier> pkgIds) throws NoSuchPackageException, InterruptedException {
    Set<SkyKey> pkgKeys = ImmutableSet.copyOf(PackageValue.keys(pkgIds));
    ImmutableMap.Builder<PackageIdentifier, Package> pkgResults = ImmutableMap.builder();
    Map<SkyKey, SkyValue> packages = graph.getSuccessfulValues(pkgKeys);
    for (Map.Entry<SkyKey, SkyValue> pkgEntry : packages.entrySet()) {
        PackageIdentifier pkgId = (PackageIdentifier) pkgEntry.getKey().argument();
        PackageValue pkgValue = (PackageValue) pkgEntry.getValue();
        pkgResults.put(pkgId, Preconditions.checkNotNull(pkgValue.getPackage(), pkgId));
    }
    SetView<SkyKey> unknownKeys = Sets.difference(pkgKeys, packages.keySet());
    if (!Iterables.isEmpty(unknownKeys)) {
        LOGGER.warning("Unable to find " + unknownKeys + " in the batch lookup of " + pkgKeys + ". Successfully looked up " + packages.keySet());
    }
    for (Map.Entry<SkyKey, Exception> missingOrExceptionEntry : graph.getMissingAndExceptions(unknownKeys).entrySet()) {
        PackageIdentifier pkgIdentifier = (PackageIdentifier) missingOrExceptionEntry.getKey().argument();
        Exception exception = missingOrExceptionEntry.getValue();
        if (exception == null) {
            // package, because the SkyQuery environment has already loaded the universe.
            throw new BuildFileNotFoundException(pkgIdentifier, "Package not found");
        }
        Throwables.propagateIfInstanceOf(exception, NoSuchPackageException.class);
        Throwables.propagate(exception);
    }
    return pkgResults.build();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) BuildFileNotFoundException(com.google.devtools.build.lib.packages.BuildFileNotFoundException) ImmutableMap(com.google.common.collect.ImmutableMap) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) BuildFileNotFoundException(com.google.devtools.build.lib.packages.BuildFileNotFoundException) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) SkyValue(com.google.devtools.build.skyframe.SkyValue) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) Package(com.google.devtools.build.lib.packages.Package) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

Package (com.google.devtools.build.lib.packages.Package)61 SkyKey (com.google.devtools.build.skyframe.SkyKey)25 Test (org.junit.Test)20 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)14 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)14 Label (com.google.devtools.build.lib.cmdline.Label)13 Path (com.google.devtools.build.lib.vfs.Path)13 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)13 Target (com.google.devtools.build.lib.packages.Target)12 NoSuchTargetException (com.google.devtools.build.lib.packages.NoSuchTargetException)11 Nullable (javax.annotation.Nullable)10 BuildFileContainsErrorsException (com.google.devtools.build.lib.packages.BuildFileContainsErrorsException)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)5 BuildFileNotFoundException (com.google.devtools.build.lib.packages.BuildFileNotFoundException)5 LinkedHashSet (java.util.LinkedHashSet)5 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)4 SkyValue (com.google.devtools.build.skyframe.SkyValue)4 InvalidConfigurationException (com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)3 Attribute (com.google.devtools.build.lib.packages.Attribute)3