Search in sources :

Example 1 with PackageValue

use of com.google.devtools.build.lib.skyframe.PackageValue in project bazel by bazelbuild.

the class SkyQueryEnvironment method bulkGetPackages.

@ThreadSafe
public Map<PackageIdentifier, Package> bulkGetPackages(Iterable<PackageIdentifier> pkgIds) throws 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));
    }
    return pkgResults.build();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) SkyValue(com.google.devtools.build.skyframe.SkyValue) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) PackageValue(com.google.devtools.build.lib.skyframe.PackageValue) Package(com.google.devtools.build.lib.packages.Package) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ImmutableMap(com.google.common.collect.ImmutableMap) ThreadSafe(com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe)

Example 2 with PackageValue

use of com.google.devtools.build.lib.skyframe.PackageValue in project bazel by bazelbuild.

the class GenQuery method getScope.

// The transitive closure of these targets is an upper estimate on the labels
// the query will touch
private static Set<Target> getScope(RuleContext context) throws InterruptedException {
    List<Label> scopeLabels = context.attributes().get("scope", BuildType.LABEL_LIST);
    Set<Target> scope = Sets.newHashSetWithExpectedSize(scopeLabels.size());
    for (Label scopePart : scopeLabels) {
        SkyFunction.Environment env = context.getAnalysisEnvironment().getSkyframeEnv();
        PackageValue packageNode = (PackageValue) env.getValue(PackageValue.key(scopePart.getPackageIdentifier()));
        Preconditions.checkNotNull(packageNode, "Packages in transitive closure of scope '%s'" + "were already loaded during the loading phase", scopePart);
        try {
            scope.add(packageNode.getPackage().getTarget(scopePart.getName()));
        } catch (NoSuchTargetException e) {
            throw new IllegalStateException(e);
        }
    }
    return scope;
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Target(com.google.devtools.build.lib.packages.Target) SkyFunction(com.google.devtools.build.skyframe.SkyFunction) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) Label(com.google.devtools.build.lib.cmdline.Label) PackageValue(com.google.devtools.build.lib.skyframe.PackageValue)

Example 3 with PackageValue

use of com.google.devtools.build.lib.skyframe.PackageValue in project bazel by bazelbuild.

the class SkyQueryEnvironment method makeTargetsFromPackageKeyToTargetKeyMap.

@ThreadSafe
public Map<SkyKey, Target> makeTargetsFromPackageKeyToTargetKeyMap(Multimap<SkyKey, SkyKey> packageKeyToTargetKeyMap) throws InterruptedException {
    ImmutableMap.Builder<SkyKey, Target> result = ImmutableMap.builder();
    Set<SkyKey> processedTargets = new HashSet<>();
    Map<SkyKey, SkyValue> packageMap = graph.getSuccessfulValues(packageKeyToTargetKeyMap.keySet());
    for (Map.Entry<SkyKey, SkyValue> entry : packageMap.entrySet()) {
        for (SkyKey targetKey : packageKeyToTargetKeyMap.get(entry.getKey())) {
            if (processedTargets.add(targetKey)) {
                try {
                    result.put(targetKey, ((PackageValue) entry.getValue()).getPackage().getTarget((SKYKEY_TO_LABEL.apply(targetKey)).getName()));
                } catch (NoSuchTargetException e) {
                // Skip missing target.
                }
            }
        }
    }
    return result.build();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) SkyValue(com.google.devtools.build.skyframe.SkyValue) Target(com.google.devtools.build.lib.packages.Target) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) PackageValue(com.google.devtools.build.lib.skyframe.PackageValue) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashSet(java.util.LinkedHashSet) CompactHashSet(com.google.devtools.build.lib.collect.CompactHashSet) HashSet(java.util.HashSet) ThreadSafe(com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe)

Example 4 with PackageValue

use of com.google.devtools.build.lib.skyframe.PackageValue 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());
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) Label(com.google.devtools.build.lib.cmdline.Label) PackageValue(com.google.devtools.build.lib.skyframe.PackageValue) ImmutableMap(com.google.common.collect.ImmutableMap) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Target(com.google.devtools.build.lib.packages.Target) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) Package(com.google.devtools.build.lib.packages.Package) TransitiveTargetValue(com.google.devtools.build.lib.skyframe.TransitiveTargetValue) Nullable(javax.annotation.Nullable)

Aggregations

PackageValue (com.google.devtools.build.lib.skyframe.PackageValue)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 NoSuchTargetException (com.google.devtools.build.lib.packages.NoSuchTargetException)3 Target (com.google.devtools.build.lib.packages.Target)3 SkyKey (com.google.devtools.build.skyframe.SkyKey)3 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)2 Label (com.google.devtools.build.lib.cmdline.Label)2 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)2 ThreadSafe (com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe)2 Package (com.google.devtools.build.lib.packages.Package)2 SkyValue (com.google.devtools.build.skyframe.SkyValue)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CompactHashSet (com.google.devtools.build.lib.collect.CompactHashSet)1 TransitiveTargetValue (com.google.devtools.build.lib.skyframe.TransitiveTargetValue)1 SkyFunction (com.google.devtools.build.skyframe.SkyFunction)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Nullable (javax.annotation.Nullable)1