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());
}
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"));
}
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.
}
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());
}
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();
}
Aggregations