Search in sources :

Example 1 with Dependency

use of com.google.devtools.build.lib.analysis.Dependency in project bazel by bazelbuild.

the class SkyframeExecutor method getConfigurations.

/**
   * Retrieves the configurations needed for the given deps. If {@link
   * BuildConfiguration.Options#trimConfigurations()} is true, trims their fragments to only those
   * needed by their transitive closures. Else unconditionally includes all fragments.
   *
   * <p>Skips targets with loading phase errors.
   */
public Multimap<Dependency, BuildConfiguration> getConfigurations(ExtendedEventHandler eventHandler, BuildOptions fromOptions, Iterable<Dependency> keys) {
    Multimap<Dependency, BuildConfiguration> builder = ArrayListMultimap.<Dependency, BuildConfiguration>create();
    Set<Dependency> depsToEvaluate = new HashSet<>();
    // Check: if !Configuration.useDynamicConfigs then just return the original configs.
    Set<Class<? extends BuildConfiguration.Fragment>> allFragments = null;
    if (useUntrimmedDynamicConfigs(fromOptions)) {
        allFragments = ((ConfiguredRuleClassProvider) ruleClassProvider).getAllFragments();
    }
    // Get the fragments needed for dynamic configuration nodes.
    final List<SkyKey> transitiveFragmentSkyKeys = new ArrayList<>();
    Map<Label, Set<Class<? extends BuildConfiguration.Fragment>>> fragmentsMap = new HashMap<>();
    Set<Label> labelsWithErrors = new HashSet<>();
    for (Dependency key : keys) {
        if (key.hasStaticConfiguration()) {
            builder.put(key, key.getConfiguration());
        } else if (useUntrimmedDynamicConfigs(fromOptions)) {
            fragmentsMap.put(key.getLabel(), allFragments);
        } else {
            depsToEvaluate.add(key);
            transitiveFragmentSkyKeys.add(TransitiveTargetValue.key(key.getLabel()));
        }
    }
    EvaluationResult<SkyValue> fragmentsResult = evaluateSkyKeys(eventHandler, transitiveFragmentSkyKeys, /*keepGoing=*/
    true);
    for (Map.Entry<SkyKey, ErrorInfo> entry : fragmentsResult.errorMap().entrySet()) {
        reportCycles(eventHandler, entry.getValue().getCycleInfo(), entry.getKey());
    }
    for (Dependency key : keys) {
        if (!depsToEvaluate.contains(key)) {
        // No fragments to compute here.
        } else if (fragmentsResult.getError(TransitiveTargetValue.key(key.getLabel())) != null) {
            labelsWithErrors.add(key.getLabel());
        } else {
            TransitiveTargetValue ttv = (TransitiveTargetValue) fragmentsResult.get(TransitiveTargetValue.key(key.getLabel()));
            fragmentsMap.put(key.getLabel(), ttv.getTransitiveConfigFragments().toSet());
        }
    }
    // Now get the configurations.
    final List<SkyKey> configSkyKeys = new ArrayList<>();
    for (Dependency key : keys) {
        if (labelsWithErrors.contains(key.getLabel()) || key.hasStaticConfiguration()) {
            continue;
        }
        Set<Class<? extends BuildConfiguration.Fragment>> depFragments = fragmentsMap.get(key.getLabel());
        if (depFragments != null) {
            for (BuildOptions toOptions : ConfiguredTargetFunction.getDynamicTransitionOptions(fromOptions, key.getTransition(), depFragments, ruleClassProvider, true)) {
                configSkyKeys.add(BuildConfigurationValue.key(depFragments, toOptions));
            }
        }
    }
    EvaluationResult<SkyValue> configsResult = evaluateSkyKeys(eventHandler, configSkyKeys, /*keepGoing=*/
    true);
    for (Dependency key : keys) {
        if (labelsWithErrors.contains(key.getLabel()) || key.hasStaticConfiguration()) {
            continue;
        }
        Set<Class<? extends BuildConfiguration.Fragment>> depFragments = fragmentsMap.get(key.getLabel());
        if (depFragments != null) {
            for (BuildOptions toOptions : ConfiguredTargetFunction.getDynamicTransitionOptions(fromOptions, key.getTransition(), depFragments, ruleClassProvider, true)) {
                SkyKey configKey = BuildConfigurationValue.key(depFragments, toOptions);
                builder.put(key, ((BuildConfigurationValue) configsResult.get(configKey)).getConfiguration());
            }
        }
    }
    return builder;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) Set(java.util.Set) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ImmutableSet(com.google.common.collect.ImmutableSet) HashSet(java.util.HashSet) ModifiedFileSet(com.google.devtools.build.lib.vfs.ModifiedFileSet) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) ArrayList(java.util.ArrayList) Label(com.google.devtools.build.lib.cmdline.Label) Dependency(com.google.devtools.build.lib.analysis.Dependency) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) SkyValue(com.google.devtools.build.skyframe.SkyValue) BuildOptions(com.google.devtools.build.lib.analysis.config.BuildOptions) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 2 with Dependency

use of com.google.devtools.build.lib.analysis.Dependency in project bazel by bazelbuild.

the class PostConfiguredTargetFunction method compute.

@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException {
    ImmutableMap<ActionAnalysisMetadata, ConflictException> badActions = PrecomputedValue.BAD_ACTIONS.get(env);
    ConfiguredTargetValue ctValue = (ConfiguredTargetValue) env.getValue(ConfiguredTargetValue.key((ConfiguredTargetKey) skyKey.argument()));
    if (env.valuesMissing()) {
        return null;
    }
    for (ActionAnalysisMetadata action : ctValue.getActions()) {
        if (badActions.containsKey(action)) {
            throw new ActionConflictFunctionException(badActions.get(action));
        }
    }
    ConfiguredTarget ct = ctValue.getConfiguredTarget();
    TargetAndConfiguration ctgValue = new TargetAndConfiguration(ct.getTarget(), ct.getConfiguration());
    ImmutableMap<Label, ConfigMatchingProvider> configConditions = getConfigurableAttributeConditions(ctgValue, env);
    if (configConditions == null) {
        return null;
    }
    OrderedSetMultimap<Attribute, Dependency> deps;
    try {
        BuildConfiguration hostConfiguration = buildViewProvider.getSkyframeBuildView().getHostConfiguration(ct.getConfiguration());
        SkyframeDependencyResolver resolver = buildViewProvider.getSkyframeBuildView().createDependencyResolver(env);
        // We don't track root causes here - this function is only invoked for successfully analyzed
        // targets - as long as we redo the exact same steps here as in ConfiguredTargetFunction, this
        // can never fail.
        deps = resolver.dependentNodeMap(ctgValue, hostConfiguration, /*aspect=*/
        null, configConditions);
        if (ct.getConfiguration() != null && ct.getConfiguration().useDynamicConfigurations()) {
            deps = ConfiguredTargetFunction.getDynamicConfigurations(env, ctgValue, deps, hostConfiguration, ruleClassProvider);
        }
    } catch (EvalException | ConfiguredTargetFunction.DependencyEvaluationException | InvalidConfigurationException | InconsistentAspectOrderException e) {
        throw new PostConfiguredTargetFunctionException(e);
    }
    env.getValues(Iterables.transform(deps.values(), TO_KEYS));
    if (env.valuesMissing()) {
        return null;
    }
    return new PostConfiguredTargetValue(ct);
}
Also used : ConflictException(com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.ConflictException) Attribute(com.google.devtools.build.lib.packages.Attribute) Label(com.google.devtools.build.lib.cmdline.Label) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) Dependency(com.google.devtools.build.lib.analysis.Dependency) EvalException(com.google.devtools.build.lib.syntax.EvalException) InconsistentAspectOrderException(com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException) InvalidConfigurationException(com.google.devtools.build.lib.analysis.config.InvalidConfigurationException) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) TargetAndConfiguration(com.google.devtools.build.lib.analysis.TargetAndConfiguration) ConfigMatchingProvider(com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider) Nullable(javax.annotation.Nullable)

Example 3 with Dependency

use of com.google.devtools.build.lib.analysis.Dependency in project bazel by bazelbuild.

the class ConfigurationsForTargetsWithDynamicConfigurationsTest method getTestFilterOptionValue.

/**
   * Returns the value of {@link BuildConfiguration.Options#testFilter} in the output
   * {@link BuildOptions} the given transition applier returns in its current state.
   */
private List<String> getTestFilterOptionValue(BuildConfiguration.TransitionApplier applier) throws Exception {
    Dependency dep = Iterables.getOnlyElement(applier.getDependencies(Label.create("some", "target"), AspectCollection.EMPTY));
    ImmutableList.Builder<String> outValues = ImmutableList.builder();
    for (BuildOptions toOptions : ConfiguredTargetFunction.getDynamicTransitionOptions(getTargetConfiguration().getOptions(), dep.getTransition(), ruleClassProvider.getAllFragments(), ruleClassProvider, false)) {
        outValues.add(toOptions.get(BuildConfiguration.Options.class).testFilter);
    }
    return outValues.build();
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) BuildOptions(com.google.devtools.build.lib.analysis.config.BuildOptions) ImmutableList(com.google.common.collect.ImmutableList) Dependency(com.google.devtools.build.lib.analysis.Dependency)

Example 4 with Dependency

use of com.google.devtools.build.lib.analysis.Dependency in project bazel by bazelbuild.

the class SkyframeExecutor method getConfiguredTargetMap.

/**
   * Returns a map from {@link Dependency} inputs to the {@link ConfiguredTarget}s corresponding to
   * those dependencies.
   *
   * <p>For use for legacy support and tests calling through {@code BuildView} only.
   *
   * <p>If a requested configured target is in error, the corresponding value is omitted from the
   * returned list.
   */
@ThreadSafety.ThreadSafe
public ImmutableMultimap<Dependency, ConfiguredTarget> getConfiguredTargetMap(ExtendedEventHandler eventHandler, BuildConfiguration originalConfig, Iterable<Dependency> keys, boolean useOriginalConfig) {
    checkActive();
    Multimap<Dependency, BuildConfiguration> configs;
    if (originalConfig != null) {
        if (useOriginalConfig) {
            // This flag is used because of some unfortunate complexity in the configuration machinery:
            // Most callers of this method pass a <Label, Configuration> pair to directly create a
            // ConfiguredTarget from, but happen to use the Dependency data structure to pass that
            // info (even though the data has nothing to do with dependencies). If this configuration
            // includes a split transition, a dynamic configuration created from it will *not*
            // include that transition (because dynamic configurations don't embed transitions to
            // other configurations. In that case, we need to preserve the original configuration.
            // TODO(bazel-team); make this unnecessary once split transition logic is properly ported
            // out of configurations.
            configs = ArrayListMultimap.<Dependency, BuildConfiguration>create();
            configs.put(Iterables.getOnlyElement(keys), originalConfig);
        } else {
            configs = getConfigurations(eventHandler, originalConfig.getOptions(), keys);
        }
    } else {
        configs = ArrayListMultimap.<Dependency, BuildConfiguration>create();
        for (Dependency key : keys) {
            configs.put(key, null);
        }
    }
    final List<SkyKey> skyKeys = new ArrayList<>();
    for (Dependency key : keys) {
        if (!configs.containsKey(key)) {
            // it couldn't be loaded). Exclude it from the results.
            continue;
        }
        for (BuildConfiguration depConfig : configs.get(key)) {
            skyKeys.add(ConfiguredTargetValue.key(key.getLabel(), depConfig));
            for (AspectDescriptor aspectDescriptor : key.getAspects().getAllAspects()) {
                skyKeys.add(ActionLookupValue.key(AspectValue.createAspectKey(key.getLabel(), depConfig, aspectDescriptor, depConfig)));
            }
        }
    }
    EvaluationResult<SkyValue> result = evaluateSkyKeys(eventHandler, skyKeys);
    for (Map.Entry<SkyKey, ErrorInfo> entry : result.errorMap().entrySet()) {
        reportCycles(eventHandler, entry.getValue().getCycleInfo(), entry.getKey());
    }
    ImmutableMultimap.Builder<Dependency, ConfiguredTarget> cts = ImmutableMultimap.<Dependency, ConfiguredTarget>builder();
    DependentNodeLoop: for (Dependency key : keys) {
        if (!configs.containsKey(key)) {
            // it couldn't be loaded). Exclude it from the results.
            continue;
        }
        for (BuildConfiguration depConfig : configs.get(key)) {
            SkyKey configuredTargetKey = ConfiguredTargetValue.key(key.getLabel(), depConfig);
            if (result.get(configuredTargetKey) == null) {
                continue;
            }
            ConfiguredTarget configuredTarget = ((ConfiguredTargetValue) result.get(configuredTargetKey)).getConfiguredTarget();
            List<ConfiguredAspect> configuredAspects = new ArrayList<>();
            for (AspectDescriptor aspectDescriptor : key.getAspects().getAllAspects()) {
                SkyKey aspectKey = ActionLookupValue.key(AspectValue.createAspectKey(key.getLabel(), depConfig, aspectDescriptor, depConfig));
                if (result.get(aspectKey) == null) {
                    continue DependentNodeLoop;
                }
                configuredAspects.add(((AspectValue) result.get(aspectKey)).getConfiguredAspect());
            }
            try {
                cts.put(key, MergedConfiguredTarget.of(configuredTarget, configuredAspects));
            } catch (DuplicateException e) {
                throw new IllegalStateException(String.format("Error creating %s", configuredTarget.getTarget().getLabel()), e);
            }
        }
    }
    return cts.build();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) ArrayList(java.util.ArrayList) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) MergedConfiguredTarget(com.google.devtools.build.lib.analysis.MergedConfiguredTarget) Dependency(com.google.devtools.build.lib.analysis.Dependency) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) SkyValue(com.google.devtools.build.skyframe.SkyValue) DuplicateException(com.google.devtools.build.lib.analysis.MergedConfiguredTarget.DuplicateException) AspectDescriptor(com.google.devtools.build.lib.packages.AspectDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 5 with Dependency

use of com.google.devtools.build.lib.analysis.Dependency in project bazel by bazelbuild.

the class ConfiguredTargetFunction method resolveAspectDependencies.

/**
   * Given a list of {@link Dependency} objects, returns a multimap from the {@link SkyKey} of the
   * dependency to the {@link ConfiguredAspect} instances that should be merged into it.
   *
   * <p>Returns null if the required aspects are not computed yet.
   */
@Nullable
private static OrderedSetMultimap<SkyKey, ConfiguredAspect> resolveAspectDependencies(Environment env, Map<SkyKey, ConfiguredTarget> configuredTargetMap, Iterable<Dependency> deps, NestedSetBuilder<Package> transitivePackages) throws AspectCreationException, InterruptedException {
    OrderedSetMultimap<SkyKey, ConfiguredAspect> result = OrderedSetMultimap.create();
    Set<SkyKey> allAspectKeys = new HashSet<>();
    for (Dependency dep : deps) {
        allAspectKeys.addAll(getAspectKeys(dep).values());
    }
    Map<SkyKey, ValueOrException2<AspectCreationException, NoSuchThingException>> depAspects = env.getValuesOrThrow(allAspectKeys, AspectCreationException.class, NoSuchThingException.class);
    for (Dependency dep : deps) {
        SkyKey depKey = TO_KEYS.apply(dep);
        // twice.
        if (result.containsKey(depKey)) {
            continue;
        }
        Map<AspectDescriptor, SkyKey> aspectToKeys = getAspectKeys(dep);
        ConfiguredTarget depConfiguredTarget = configuredTargetMap.get(depKey);
        for (AspectDeps depAspect : dep.getAspects().getVisibleAspects()) {
            SkyKey aspectKey = aspectToKeys.get(depAspect.getAspect());
            AspectValue aspectValue;
            try {
                // TODO(ulfjack): Catch all thrown AspectCreationException and NoSuchThingException
                // instances and merge them into a single Exception to get full root cause data.
                aspectValue = (AspectValue) depAspects.get(aspectKey).get();
            } catch (NoSuchThingException e) {
                throw new AspectCreationException(String.format("Evaluation of aspect %s on %s failed: %s", depAspect.getAspect().getAspectClass().getName(), dep.getLabel(), e.toString()));
            }
            if (aspectValue == null) {
                // Dependent aspect has either not been computed yet or is in error.
                return null;
            }
            if (!aspectMatchesConfiguredTarget(depConfiguredTarget, aspectValue.getAspect())) {
                continue;
            }
            result.put(depKey, aspectValue.getConfiguredAspect());
            transitivePackages.addTransitive(aspectValue.getTransitivePackages());
        }
    }
    return result;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ConfiguredAspect(com.google.devtools.build.lib.analysis.ConfiguredAspect) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) MergedConfiguredTarget(com.google.devtools.build.lib.analysis.MergedConfiguredTarget) Dependency(com.google.devtools.build.lib.analysis.Dependency) ValueOrException2(com.google.devtools.build.skyframe.ValueOrException2) AspectCreationException(com.google.devtools.build.lib.skyframe.AspectFunction.AspectCreationException) NoSuchThingException(com.google.devtools.build.lib.packages.NoSuchThingException) AspectDeps(com.google.devtools.build.lib.analysis.AspectCollection.AspectDeps) AspectDescriptor(com.google.devtools.build.lib.packages.AspectDescriptor) HashSet(java.util.HashSet) Nullable(javax.annotation.Nullable)

Aggregations

Dependency (com.google.devtools.build.lib.analysis.Dependency)8 SkyKey (com.google.devtools.build.skyframe.SkyKey)6 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)5 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)5 LinkedHashMap (java.util.LinkedHashMap)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 MergedConfiguredTarget (com.google.devtools.build.lib.analysis.MergedConfiguredTarget)4 Attribute (com.google.devtools.build.lib.packages.Attribute)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Nullable (javax.annotation.Nullable)4 BuildOptions (com.google.devtools.build.lib.analysis.config.BuildOptions)3 Label (com.google.devtools.build.lib.cmdline.Label)3 ArrayList (java.util.ArrayList)3 InconsistentAspectOrderException (com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException)2 ConfigMatchingProvider (com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider)2 InvalidConfigurationException (com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)2 AspectDescriptor (com.google.devtools.build.lib.packages.AspectDescriptor)2 ErrorInfo (com.google.devtools.build.skyframe.ErrorInfo)2