use of com.google.devtools.build.lib.cmdline.PackageIdentifier in project bazel by bazelbuild.
the class PackageProgressReceiverTest method testReset.
@Test
public void testReset() {
// After resetting, messages should be as immediately after creation.
PackageProgressReceiver progress = new PackageProgressReceiver();
String defaultState = progress.progressState().getFirst();
String defaultActivity = progress.progressState().getSecond();
PackageIdentifier id = PackageIdentifier.createInMainRepo("foo/bar/baz");
progress.startReadPackage(id);
progress.doneReadPackage(id);
progress.reset();
assertEquals(defaultState, progress.progressState().getFirst());
assertEquals(defaultActivity, progress.progressState().getSecond());
}
use of com.google.devtools.build.lib.cmdline.PackageIdentifier in project bazel by bazelbuild.
the class BuildView method setArtifactRoots.
/**
* Sets the possible artifact roots in the artifact factory. This allows the factory to resolve
* paths with unknown roots to artifacts.
*/
// for BuildViewTestCase
@VisibleForTesting
public void setArtifactRoots(ImmutableMap<PackageIdentifier, Path> packageRoots) {
Map<Path, Root> rootMap = new HashMap<>();
Map<PackageIdentifier, Root> realPackageRoots = new HashMap<>();
for (Map.Entry<PackageIdentifier, Path> entry : packageRoots.entrySet()) {
Root root = rootMap.get(entry.getValue());
if (root == null) {
root = Root.asSourceRoot(entry.getValue(), entry.getKey().getRepository().isMain());
rootMap.put(entry.getValue(), root);
}
realPackageRoots.put(entry.getKey(), root);
}
// Source Artifact roots:
getArtifactFactory().setPackageRoots(realPackageRoots);
}
use of com.google.devtools.build.lib.cmdline.PackageIdentifier in project bazel by bazelbuild.
the class ContainingPackageLookupFunction method compute.
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
PackageIdentifier dir = (PackageIdentifier) skyKey.argument();
PackageLookupValue pkgLookupValue = (PackageLookupValue) env.getValue(PackageLookupValue.key(dir));
if (pkgLookupValue == null) {
return null;
}
if (pkgLookupValue.packageExists()) {
return ContainingPackageLookupValue.withContainingPackage(dir, pkgLookupValue.getRoot());
}
PathFragment parentDir = dir.getPackageFragment().getParentDirectory();
if (parentDir == null) {
return ContainingPackageLookupValue.NONE;
}
PackageIdentifier parentId = PackageIdentifier.create(dir.getRepository(), parentDir);
return env.getValue(ContainingPackageLookupValue.key(parentId));
}
use of com.google.devtools.build.lib.cmdline.PackageIdentifier in project bazel by bazelbuild.
the class CollectTargetsInPackageFunction method compute.
@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException {
CollectTargetsInPackageValue.CollectTargetsInPackageKey argument = (CollectTargetsInPackageValue.CollectTargetsInPackageKey) skyKey.argument();
PackageIdentifier packageId = argument.getPackageId();
PackageValue packageValue = (PackageValue) env.getValue(PackageValue.key(packageId));
if (env.valuesMissing()) {
return null;
}
Package pkg = packageValue.getPackage();
if (pkg.containsErrors()) {
env.getListener().handle(Event.error("package contains errors: " + packageId.getPackageFragment().getPathString()));
}
env.getValues(Iterables.transform(TargetPatternResolverUtil.resolvePackageTargets(pkg, argument.getFilteringPolicy()).getTargets(), TO_TRANSITIVE_TRAVERSAL_KEY));
if (env.valuesMissing()) {
return null;
}
return CollectTargetsInPackageValue.INSTANCE;
}
use of com.google.devtools.build.lib.cmdline.PackageIdentifier 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