Search in sources :

Example 11 with BuildOptions

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

the class SkyframeDependencyResolver method getConfigurations.

@Nullable
@Override
protected List<BuildConfiguration> getConfigurations(Set<Class<? extends BuildConfiguration.Fragment>> fragments, Iterable<BuildOptions> buildOptions) throws InvalidConfigurationException, InterruptedException {
    List<SkyKey> keys = new ArrayList<>();
    for (BuildOptions options : buildOptions) {
        keys.add(BuildConfigurationValue.key(fragments, options));
    }
    Map<SkyKey, ValueOrException<InvalidConfigurationException>> configValues = env.getValuesOrThrow(keys, InvalidConfigurationException.class);
    if (env.valuesMissing()) {
        return null;
    }
    ImmutableList.Builder<BuildConfiguration> result = ImmutableList.builder();
    for (SkyKey key : keys) {
        result.add(((BuildConfigurationValue) configValues.get(key).get()).getConfiguration());
    }
    return result.build();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) BuildOptions(com.google.devtools.build.lib.analysis.config.BuildOptions) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) ValueOrException(com.google.devtools.build.skyframe.ValueOrException) Nullable(javax.annotation.Nullable)

Example 12 with BuildOptions

use of com.google.devtools.build.lib.analysis.config.BuildOptions 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 13 with BuildOptions

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

the class CommandEnvironment method getConfigurations.

/**
   * This method only exists for the benefit of InfoCommand, which needs to construct a {@link
   * BuildConfigurationCollection} without running a full loading phase. Don't add any more clients;
   * instead, we should change info so that it doesn't need the configuration.
   */
public BuildConfigurationCollection getConfigurations(OptionsProvider optionsProvider) throws InvalidConfigurationException, InterruptedException {
    BuildOptions buildOptions = runtime.createBuildOptions(optionsProvider);
    boolean keepGoing = optionsProvider.getOptions(BuildView.Options.class).keepGoing;
    return getSkyframeExecutor().createConfigurations(reporter, runtime.getConfigurationFactory(), buildOptions, ImmutableSet.<String>of(), keepGoing);
}
Also used : BuildOptions(com.google.devtools.build.lib.analysis.config.BuildOptions) PackageCacheOptions(com.google.devtools.build.lib.pkgcache.PackageCacheOptions) BuildOptions(com.google.devtools.build.lib.analysis.config.BuildOptions)

Example 14 with BuildOptions

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

the class ConfigurationsForTargetsWithDynamicConfigurationsTest method newPatchTransition.

/**
   * Returns a custom {@link PatchTransition} with the given value added to
   * {@link BuildConfiguration.Options#testFilter}.
   */
private static PatchTransition newPatchTransition(final String value) {
    return new PatchTransition() {

        @Override
        public BuildOptions apply(BuildOptions options) {
            BuildOptions toOptions = options.clone();
            BuildConfiguration.Options baseOptions = toOptions.get(BuildConfiguration.Options.class);
            baseOptions.testFilter = (nullToEmpty(baseOptions.testFilter)) + value;
            return toOptions;
        }

        @Override
        public boolean defaultsToSelf() {
            return false;
        }
    };
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) BuildOptions(com.google.devtools.build.lib.analysis.config.BuildOptions) PatchTransition(com.google.devtools.build.lib.analysis.config.PatchTransition)

Example 15 with BuildOptions

use of com.google.devtools.build.lib.analysis.config.BuildOptions 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)

Aggregations

BuildOptions (com.google.devtools.build.lib.analysis.config.BuildOptions)23 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)12 ImmutableList (com.google.common.collect.ImmutableList)6 InvalidConfigurationException (com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)4 SkyKey (com.google.devtools.build.skyframe.SkyKey)4 ArrayList (java.util.ArrayList)4 Dependency (com.google.devtools.build.lib.analysis.Dependency)3 Label (com.google.devtools.build.lib.cmdline.Label)3 Attribute (com.google.devtools.build.lib.packages.Attribute)3 HashSet (java.util.HashSet)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Options (com.google.devtools.build.lib.analysis.config.BuildConfiguration.Options)2 BuildConfigurationCollection (com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection)2 PatchTransition (com.google.devtools.build.lib.analysis.config.PatchTransition)2 InvocationPolicyEnforcer (com.google.devtools.build.lib.flags.InvocationPolicyEnforcer)2 SplitTransition (com.google.devtools.build.lib.packages.Attribute.SplitTransition)2 LoadingResult (com.google.devtools.build.lib.pkgcache.LoadingResult)2 PackageCacheOptions (com.google.devtools.build.lib.pkgcache.PackageCacheOptions)2 ValueOrException (com.google.devtools.build.skyframe.ValueOrException)2