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();
}
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;
}
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);
}
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;
}
};
}
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();
}
Aggregations