Search in sources :

Example 1 with NoSuchTargetException

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

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

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

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

the class TransitiveTargetFunction method computeSkyValue.

@Override
public SkyValue computeSkyValue(TargetAndErrorIfAny targetAndErrorIfAny, TransitiveTargetValueBuilder builder) {
    Target target = targetAndErrorIfAny.getTarget();
    NoSuchTargetException errorLoadingTarget = targetAndErrorIfAny.getErrorLoadingTarget();
    // Get configuration fragments directly required by this rule.
    if (target instanceof Rule) {
        Rule rule = (Rule) target;
        // Declared by the rule class:
        ConfigurationFragmentPolicy configurationFragmentPolicy = rule.getRuleClassObject().getConfigurationFragmentPolicy();
        for (ConfigurationFragmentFactory factory : ruleClassProvider.getConfigurationFragments()) {
            Class<? extends Fragment> fragment = factory.creates();
            // (named) fragments.
            if (configurationFragmentPolicy.isLegalConfigurationFragment(fragment)) {
                addFragmentIfNew(builder, fragment.asSubclass(BuildConfiguration.Fragment.class));
            }
        }
        // Declared by late-bound attributes:
        for (Attribute attr : rule.getAttributes()) {
            if (attr.isLateBound()) {
                addFragmentsIfNew(builder, attr.getLateBoundDefault().getRequiredConfigurationFragments());
            }
        }
        // corresponding fragments in their configurations to properly resolve:
        if (rule.getRuleClass().equals(ConfigSettingRule.RULE_NAME)) {
            addFragmentsIfNew(builder, ConfigSettingRule.requiresConfigurationFragments(rule, optionsToFragmentMap));
        }
        // Fragments to unconditionally include:
        addFragmentIfNew(builder, ruleClassProvider.getUniversalFragment().asSubclass(BuildConfiguration.Fragment.class));
    }
    return builder.build(errorLoadingTarget);
}
Also used : Target(com.google.devtools.build.lib.packages.Target) ConfigurationFragmentPolicy(com.google.devtools.build.lib.packages.ConfigurationFragmentPolicy) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) Attribute(com.google.devtools.build.lib.packages.Attribute) ConfigSettingRule(com.google.devtools.build.lib.analysis.config.ConfigRuleClasses.ConfigSettingRule) Rule(com.google.devtools.build.lib.packages.Rule) ConfigurationFragmentFactory(com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory) Fragment(com.google.devtools.build.lib.analysis.config.BuildConfiguration.Fragment)

Example 5 with NoSuchTargetException

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

the class TransitiveTraversalFunction method processTarget.

@Override
FirstErrorMessageAccumulator processTarget(Label label, TargetAndErrorIfAny targetAndErrorIfAny) {
    NoSuchTargetException errorIfAny = targetAndErrorIfAny.getErrorLoadingTarget();
    String errorMessageIfAny = errorIfAny == null ? null : errorIfAny.getMessage();
    return new FirstErrorMessageAccumulator(errorMessageIfAny);
}
Also used : FirstErrorMessageAccumulator(com.google.devtools.build.lib.skyframe.TransitiveTraversalFunction.FirstErrorMessageAccumulator) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException)

Aggregations

NoSuchTargetException (com.google.devtools.build.lib.packages.NoSuchTargetException)23 SkyKey (com.google.devtools.build.skyframe.SkyKey)13 Label (com.google.devtools.build.lib.cmdline.Label)12 Target (com.google.devtools.build.lib.packages.Target)12 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)9 Package (com.google.devtools.build.lib.packages.Package)9 Test (org.junit.Test)6 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)5 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)4 Attribute (com.google.devtools.build.lib.packages.Attribute)4 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)4 HashMap (java.util.HashMap)4 Nullable (javax.annotation.Nullable)4 Rule (com.google.devtools.build.lib.packages.Rule)3 SkyValue (com.google.devtools.build.skyframe.SkyValue)3 ValueOrException2 (com.google.devtools.build.skyframe.ValueOrException2)3 LinkedHashSet (java.util.LinkedHashSet)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 InconsistentAspectOrderException (com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException)2 MergedConfiguredTarget (com.google.devtools.build.lib.analysis.MergedConfiguredTarget)2