Search in sources :

Example 1 with NoSuchPackageException

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

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

the class TransitiveBaseTraversalFunction method getStrictLabelAspectKeys.

/**
   * Return an Iterable of SkyKeys corresponding to the Aspect-related dependencies of target.
   *
   * <p>This method may return a precise set of aspect keys, but may need to request additional
   * dependencies from the env to do so.
   */
private Iterable<SkyKey> getStrictLabelAspectKeys(Target target, Map<SkyKey, ValueOrException2<NoSuchPackageException, NoSuchTargetException>> depMap, Environment env) throws InterruptedException {
    List<SkyKey> depKeys = Lists.newArrayList();
    if (target instanceof Rule) {
        Map<Label, ValueOrException2<NoSuchPackageException, NoSuchTargetException>> labelDepMap = new HashMap<>(depMap.size());
        for (Entry<SkyKey, ValueOrException2<NoSuchPackageException, NoSuchTargetException>> entry : depMap.entrySet()) {
            labelDepMap.put((Label) entry.getKey().argument(), entry.getValue());
        }
        Multimap<Attribute, Label> transitions = ((Rule) target).getTransitions(DependencyFilter.NO_NODEP_ATTRIBUTES);
        for (Entry<Attribute, Label> entry : transitions.entries()) {
            ValueOrException2<NoSuchPackageException, NoSuchTargetException> value = labelDepMap.get(entry.getValue());
            for (Label label : getAspectLabels((Rule) target, entry.getKey(), entry.getValue(), value, env)) {
                depKeys.add(getKey(label));
            }
        }
    }
    return depKeys;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) HashMap(java.util.HashMap) Attribute(com.google.devtools.build.lib.packages.Attribute) Label(com.google.devtools.build.lib.cmdline.Label) ValueOrException2(com.google.devtools.build.skyframe.ValueOrException2) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) Rule(com.google.devtools.build.lib.packages.Rule)

Example 3 with NoSuchPackageException

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

the class TransitiveBaseTraversalFunction method compute.

@Override
public SkyValue compute(SkyKey key, Environment env) throws TransitiveBaseTraversalFunctionException, InterruptedException {
    Label label = (Label) key.argument();
    LoadTargetResults loadTargetResults;
    try {
        loadTargetResults = loadTarget(env, label);
    } catch (NoSuchTargetException e) {
        throw new TransitiveBaseTraversalFunctionException(e);
    } catch (NoSuchPackageException e) {
        throw new TransitiveBaseTraversalFunctionException(e);
    }
    LoadTargetResultsType loadTargetResultsType = loadTargetResults.getType();
    if (loadTargetResultsType.equals(LoadTargetResultsType.VALUES_MISSING)) {
        return null;
    }
    Preconditions.checkState(loadTargetResultsType.equals(LoadTargetResultsType.TARGET_AND_ERROR_IF_ANY), loadTargetResultsType);
    TargetAndErrorIfAny targetAndErrorIfAny = (TargetAndErrorIfAny) loadTargetResults;
    TProcessedTargets processedTargets = processTarget(label, targetAndErrorIfAny);
    // Process deps from attributes.
    Iterable<SkyKey> labelDepKeys = getLabelDepKeys(targetAndErrorIfAny.getTarget());
    Map<SkyKey, ValueOrException2<NoSuchPackageException, NoSuchTargetException>> depMap = env.getValuesOrThrow(labelDepKeys, NoSuchPackageException.class, NoSuchTargetException.class);
    processDeps(processedTargets, env.getListener(), targetAndErrorIfAny, depMap.entrySet());
    if (env.valuesMissing()) {
        return null;
    }
    // Process deps from aspects.
    Iterable<SkyKey> labelAspectKeys = getStrictLabelAspectKeys(targetAndErrorIfAny.getTarget(), depMap, env);
    Set<Entry<SkyKey, ValueOrException2<NoSuchPackageException, NoSuchTargetException>>> labelAspectEntries = env.getValuesOrThrow(labelAspectKeys, NoSuchPackageException.class, NoSuchTargetException.class).entrySet();
    processDeps(processedTargets, env.getListener(), targetAndErrorIfAny, labelAspectEntries);
    if (env.valuesMissing()) {
        return null;
    }
    return computeSkyValue(targetAndErrorIfAny, processedTargets);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) Label(com.google.devtools.build.lib.cmdline.Label) ValueOrException2(com.google.devtools.build.skyframe.ValueOrException2) Entry(java.util.Map.Entry) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException)

Example 4 with NoSuchPackageException

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

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

the class BuildTool method checkTargetEnvironmentRestrictions.

/**
   * Checks that if this is an environment-restricted build, all top-level targets support the
   * expected environments.
   *
   * @param topLevelTargets the build's top-level targets
   * @throws ViewCreationFailedException if constraint enforcement is on, the build declares
   *     environment-restricted top level configurations, and any top-level target doesn't support
   *     the expected environments
   */
private static void checkTargetEnvironmentRestrictions(Iterable<ConfiguredTarget> topLevelTargets, LoadedPackageProvider packageManager) throws ViewCreationFailedException, InterruptedException {
    for (ConfiguredTarget topLevelTarget : topLevelTargets) {
        BuildConfiguration config = topLevelTarget.getConfiguration();
        if (config == null) {
            // TODO(bazel-team): support file targets (they should apply package-default constraints).
            continue;
        } else if (!config.enforceConstraints() || config.getTargetEnvironments().isEmpty()) {
            continue;
        }
        // Parse and collect this configuration's environments.
        EnvironmentCollection.Builder builder = new EnvironmentCollection.Builder();
        for (Label envLabel : config.getTargetEnvironments()) {
            try {
                Target env = packageManager.getLoadedTarget(envLabel);
                builder.put(ConstraintSemantics.getEnvironmentGroup(env), envLabel);
            } catch (NoSuchPackageException | NoSuchTargetException | ConstraintSemantics.EnvironmentLookupException e) {
                throw new ViewCreationFailedException("invalid target environment", e);
            }
        }
        EnvironmentCollection expectedEnvironments = builder.build();
        // Now check the target against those environments.
        SupportedEnvironmentsProvider provider = Verify.verifyNotNull(topLevelTarget.getProvider(SupportedEnvironmentsProvider.class));
        Collection<Label> missingEnvironments = ConstraintSemantics.getUnsupportedEnvironments(provider.getRefinedEnvironments(), expectedEnvironments);
        if (!missingEnvironments.isEmpty()) {
            throw new ViewCreationFailedException(String.format("This is a restricted-environment build. %s does not support" + " required environment%s %s", topLevelTarget.getLabel(), missingEnvironments.size() == 1 ? "" : "s", Joiner.on(", ").join(missingEnvironments)));
        }
    }
}
Also used : Label(com.google.devtools.build.lib.cmdline.Label) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Target(com.google.devtools.build.lib.packages.Target) ViewCreationFailedException(com.google.devtools.build.lib.analysis.ViewCreationFailedException) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) SupportedEnvironmentsProvider(com.google.devtools.build.lib.analysis.constraints.SupportedEnvironmentsProvider) EnvironmentCollection(com.google.devtools.build.lib.analysis.constraints.EnvironmentCollection)

Aggregations

NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)27 SkyKey (com.google.devtools.build.skyframe.SkyKey)21 Package (com.google.devtools.build.lib.packages.Package)13 NoSuchTargetException (com.google.devtools.build.lib.packages.NoSuchTargetException)11 Label (com.google.devtools.build.lib.cmdline.Label)10 Target (com.google.devtools.build.lib.packages.Target)8 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)7 BuildFileContainsErrorsException (com.google.devtools.build.lib.packages.BuildFileContainsErrorsException)6 BuildFileNotFoundException (com.google.devtools.build.lib.packages.BuildFileNotFoundException)6 Nullable (javax.annotation.Nullable)6 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)5 IOException (java.io.IOException)5 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)4 SkyValue (com.google.devtools.build.skyframe.SkyValue)4 ValueOrException2 (com.google.devtools.build.skyframe.ValueOrException2)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Path (com.google.devtools.build.lib.vfs.Path)3 Map (java.util.Map)3 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)2 Attribute (com.google.devtools.build.lib.packages.Attribute)2