use of com.google.devtools.build.lib.skyframe.TransitiveTargetValue in project bazel by bazelbuild.
the class GenQuery method constructPackageMap.
/**
* Precomputes the transitive closure of the scope. Returns two maps: one identifying the
* successful packages, and the other identifying the valid targets. Breaks in the transitive
* closure of the scope will cause the query to error out early.
*/
@Nullable
private static Pair<ImmutableMap<PackageIdentifier, Package>, ImmutableMap<Label, Target>> constructPackageMap(SkyFunction.Environment env, Collection<Target> scope) throws InterruptedException, BrokenQueryScopeException {
// It is not necessary for correctness to construct intermediate NestedSets; we could iterate
// over individual targets in scope immediately. However, creating a composite NestedSet first
// saves us from iterating over the same sub-NestedSets multiple times.
NestedSetBuilder<Label> validTargets = NestedSetBuilder.stableOrder();
NestedSetBuilder<PackageIdentifier> successfulPackageNames = NestedSetBuilder.stableOrder();
for (Target target : scope) {
SkyKey key = TransitiveTargetValue.key(target.getLabel());
TransitiveTargetValue transNode = (TransitiveTargetValue) env.getValue(key);
if (transNode == null) {
return null;
}
if (!transNode.getTransitiveUnsuccessfulPackages().isEmpty()) {
// path, as otherwise this configured target would have failed earlier. See b/34132681.
throw new BrokenQueryScopeException("errors were encountered while computing transitive closure of the scope.");
}
validTargets.addTransitive(transNode.getTransitiveTargets());
successfulPackageNames.addTransitive(transNode.getTransitiveSuccessfulPackages());
}
// Construct the package id to package map for all successful packages.
ImmutableMap.Builder<PackageIdentifier, Package> packageMapBuilder = ImmutableMap.builder();
for (PackageIdentifier pkgId : successfulPackageNames.build()) {
PackageValue pkg = (PackageValue) env.getValue(PackageValue.key(pkgId));
Preconditions.checkNotNull(pkg, "package %s not preloaded", pkgId);
Preconditions.checkState(!pkg.getPackage().containsErrors(), "package %s was found to both have and not have errors.", pkgId);
packageMapBuilder.put(pkg.getPackage().getPackageIdentifier(), pkg.getPackage());
}
ImmutableMap<PackageIdentifier, Package> packageMap = packageMapBuilder.build();
ImmutableMap.Builder<Label, Target> validTargetsMapBuilder = ImmutableMap.builder();
for (Label label : validTargets.build()) {
try {
Target target = packageMap.get(label.getPackageIdentifier()).getTarget(label.getName());
validTargetsMapBuilder.put(label, target);
} catch (NoSuchTargetException e) {
throw new IllegalStateException(e);
}
}
return Pair.of(packageMap, validTargetsMapBuilder.build());
}
use of com.google.devtools.build.lib.skyframe.TransitiveTargetValue in project bazel by bazelbuild.
the class IOExceptionsTest method visitTransitively.
private boolean visitTransitively(Label label) throws InterruptedException {
SkyKey key = TransitiveTargetValue.key(label);
EvaluationResult<SkyValue> result = skyframeExecutor.prepareAndGet(key, /*numThreads=*/
5, reporter);
TransitiveTargetValue value = (TransitiveTargetValue) result.get(key);
System.out.println(value);
boolean hasTransitiveError = (value == null) || value.getTransitiveRootCauses() != null;
return !result.hasError() && !hasTransitiveError;
}
Aggregations