Search in sources :

Example 1 with Package

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

the class BlazeQueryEnvironment method getBuildFiles.

// TODO(bazel-team): rename this to getDependentFiles when all implementations
// of QueryEnvironment is fixed.
@Override
public Set<Target> getBuildFiles(final QueryExpression caller, Set<Target> nodes, boolean buildFiles, boolean subincludes, boolean loads) throws QueryException {
    Set<Target> dependentFiles = new LinkedHashSet<>();
    Set<Package> seenPackages = new HashSet<>();
    // Keep track of seen labels, to avoid adding a fake subinclude label that also exists as a
    // real target.
    Set<Label> seenLabels = new HashSet<>();
    // extensions) for package "pkg", to "buildfiles".
    for (Target x : nodes) {
        Package pkg = x.getPackage();
        if (seenPackages.add(pkg)) {
            if (buildFiles) {
                addIfUniqueLabel(getNode(pkg.getBuildFile()), seenLabels, dependentFiles);
            }
            List<Label> extensions = new ArrayList<>();
            if (subincludes) {
                extensions.addAll(pkg.getSubincludeLabels());
            }
            if (loads) {
                extensions.addAll(pkg.getSkylarkFileDependencies());
            }
            for (Label subinclude : extensions) {
                addIfUniqueLabel(getSubincludeTarget(subinclude, pkg), seenLabels, dependentFiles);
                // Also add the BUILD file of the subinclude.
                if (buildFiles) {
                    try {
                        addIfUniqueLabel(getSubincludeTarget(subinclude.getLocalTargetLabel("BUILD"), pkg), seenLabels, dependentFiles);
                    } catch (LabelSyntaxException e) {
                        throw new AssertionError("BUILD should always parse as a target name", e);
                    }
                }
            }
        }
    }
    return dependentFiles;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Target(com.google.devtools.build.lib.packages.Target) LabelSyntaxException(com.google.devtools.build.lib.cmdline.LabelSyntaxException) Label(com.google.devtools.build.lib.cmdline.Label) ArrayList(java.util.ArrayList) Package(com.google.devtools.build.lib.packages.Package) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with Package

use of com.google.devtools.build.lib.packages.Package 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 3 with Package

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

the class TransitiveBaseTraversalFunction method loadTarget.

private LoadTargetResults loadTarget(Environment env, Label label) throws NoSuchTargetException, NoSuchPackageException, InterruptedException {
    SkyKey packageKey = PackageValue.key(label.getPackageIdentifier());
    SkyKey targetKey = TargetMarkerValue.key(label);
    boolean packageLoadedSuccessfully;
    Target target;
    NoSuchTargetException errorLoadingTarget = null;
    try {
        TargetMarkerValue targetValue = getTargetMarkerValue(targetKey, env);
        boolean targetValueMissing = targetValue == null;
        Preconditions.checkState(targetValueMissing == env.valuesMissing(), targetKey);
        if (targetValueMissing) {
            return ValuesMissing.INSTANCE;
        }
        PackageValue packageValue = (PackageValue) env.getValueOrThrow(packageKey, NoSuchPackageException.class);
        if (packageValue == null) {
            return ValuesMissing.INSTANCE;
        }
        Package pkg = packageValue.getPackage();
        if (pkg.containsErrors()) {
            throw new BuildFileContainsErrorsException(label.getPackageIdentifier());
        }
        packageLoadedSuccessfully = true;
        try {
            target = pkg.getTarget(label.getName());
        } catch (NoSuchTargetException unexpected) {
            // was not present.
            throw new IllegalStateException(unexpected);
        }
    } catch (NoSuchTargetException e) {
        if (!e.hasTarget()) {
            throw e;
        }
        // We know that a Target may be extracted, but we need to get it out of the Package
        // (which is known to be in error).
        PackageValue packageValue = (PackageValue) Preconditions.checkNotNull(env.getValue(packageKey), label);
        Package pkg = packageValue.getPackage();
        try {
            target = pkg.getTarget(label.getName());
        } catch (NoSuchTargetException nste) {
            throw new IllegalStateException("Expected target to exist", nste);
        }
        errorLoadingTarget = e;
        packageLoadedSuccessfully = false;
    }
    return new TargetAndErrorIfAnyImpl(packageLoadedSuccessfully, errorLoadingTarget, target);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) BuildFileContainsErrorsException(com.google.devtools.build.lib.packages.BuildFileContainsErrorsException) Target(com.google.devtools.build.lib.packages.Target) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) Package(com.google.devtools.build.lib.packages.Package)

Example 4 with Package

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

the class TransitiveTargetFunction method getAspectLabels.

@Override
protected Collection<Label> getAspectLabels(Rule fromRule, Attribute attr, Label toLabel, ValueOrException2<NoSuchPackageException, NoSuchTargetException> toVal, final Environment env) throws InterruptedException {
    SkyKey packageKey = PackageValue.key(toLabel.getPackageIdentifier());
    try {
        PackageValue pkgValue = (PackageValue) env.getValueOrThrow(packageKey, NoSuchPackageException.class);
        if (pkgValue == null) {
            return ImmutableList.of();
        }
        Package pkg = pkgValue.getPackage();
        if (pkg.containsErrors()) {
            // TransitiveTargetValue.
            return ImmutableList.of();
        }
        Target dependedTarget = pkgValue.getPackage().getTarget(toLabel.getName());
        return AspectDefinition.visitAspectsIfRequired(fromRule, attr, dependedTarget, DependencyFilter.ALL_DEPS).values();
    } catch (NoSuchThingException e) {
        // TransitiveTargetValue.
        return ImmutableList.of();
    }
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) Target(com.google.devtools.build.lib.packages.Target) NoSuchThingException(com.google.devtools.build.lib.packages.NoSuchThingException) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) Package(com.google.devtools.build.lib.packages.Package)

Example 5 with Package

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

the class WorkspaceNameFunction method compute.

@Override
@Nullable
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
    SkyKey externalPackageKey = PackageValue.key(Label.EXTERNAL_PACKAGE_IDENTIFIER);
    PackageValue externalPackageValue = (PackageValue) env.getValue(externalPackageKey);
    if (externalPackageValue == null) {
        return null;
    }
    Package externalPackage = externalPackageValue.getPackage();
    return externalPackage.containsErrors() ? WorkspaceNameValue.withError() : WorkspaceNameValue.withName(externalPackage.getWorkspaceName());
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) Package(com.google.devtools.build.lib.packages.Package) Nullable(javax.annotation.Nullable)

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