use of com.google.devtools.build.lib.analysis.config.BuildConfiguration in project bazel by bazelbuild.
the class BazelConfigurationCollection method setupTransitions.
static BuildConfiguration setupTransitions(BuildConfiguration targetConfiguration, BuildConfiguration dataConfiguration, BuildConfiguration hostConfiguration, ListMultimap<SplitTransition<?>, BuildConfiguration> splitTransitionsTable) {
Set<BuildConfiguration> allConfigurations = new LinkedHashSet<>();
allConfigurations.add(targetConfiguration);
allConfigurations.add(dataConfiguration);
allConfigurations.add(hostConfiguration);
allConfigurations.addAll(splitTransitionsTable.values());
Table<BuildConfiguration, Transition, ConfigurationHolder> transitionBuilder = HashBasedTable.create();
for (BuildConfiguration from : allConfigurations) {
for (ConfigurationTransition transition : ConfigurationTransition.values()) {
BuildConfiguration to;
if (transition == ConfigurationTransition.HOST) {
to = hostConfiguration;
} else if (transition == ConfigurationTransition.DATA && from == targetConfiguration) {
to = dataConfiguration;
} else {
to = from;
}
transitionBuilder.put(from, transition, new ConfigurationHolder(to));
}
}
// collection.
for (BuildConfiguration config : allConfigurations) {
transitionBuilder.put(config, LipoTransition.LIPO_COLLECTOR, new ConfigurationHolder(config));
transitionBuilder.put(config, LipoTransition.TARGET_CONFIG_FOR_LIPO, new ConfigurationHolder(config.isHostConfiguration() ? null : config));
}
for (BuildConfiguration config : allConfigurations) {
// configuration.
if (config.isHostConfiguration() && config.getTransitions() != null) {
continue;
}
boolean isSplitConfig = splitTransitionsTable.values().contains(config);
// the split transition overwrites the cpu, which it usually does.
if (isSplitConfig && config.getTransitions() != null) {
continue;
}
Transitions outgoingTransitions = new BazelTransitions(config, transitionBuilder.row(config), // DependencyResolver.resolveLateBoundAttributes().
isSplitConfig ? ImmutableListMultimap.<SplitTransition<?>, BuildConfiguration>of() : splitTransitionsTable);
config.setConfigurationTransitions(outgoingTransitions);
}
return targetConfiguration;
}
use of com.google.devtools.build.lib.analysis.config.BuildConfiguration 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)));
}
}
}
use of com.google.devtools.build.lib.analysis.config.BuildConfiguration in project bazel by bazelbuild.
the class AndroidStudioInfoAspect method derivedArtifact.
private static Artifact derivedArtifact(ConfiguredTarget base, RuleContext ruleContext, String suffix) {
BuildConfiguration configuration = ruleContext.getConfiguration();
assert configuration != null;
Root binDirectory = configuration.getBinDirectory(ruleContext.getRule().getRepository());
PathFragment derivedFilePath = getOutputFilePath(base, ruleContext, suffix);
return ruleContext.getAnalysisEnvironment().getDerivedArtifact(derivedFilePath, binDirectory);
}
use of com.google.devtools.build.lib.analysis.config.BuildConfiguration in project bazel by bazelbuild.
the class BuildView method getRuleContextForTesting.
/**
* Returns a RuleContext which is the same as the original RuleContext of the target parameter.
*/
@VisibleForTesting
public RuleContext getRuleContextForTesting(ConfiguredTarget target, StoredEventHandler eventHandler, BuildConfigurationCollection configurations) throws EvalException, InvalidConfigurationException, InterruptedException, InconsistentAspectOrderException {
BuildConfiguration targetConfig = target.getConfiguration();
CachingAnalysisEnvironment env = new CachingAnalysisEnvironment(getArtifactFactory(), new ConfiguredTargetKey(target.getLabel(), targetConfig), /*isSystemEnv=*/
false, targetConfig.extendedSanityChecks(), eventHandler, /*skyframeEnv=*/
null, targetConfig.isActionsEnabled());
return getRuleContextForTesting(eventHandler, target, env, configurations);
}
use of com.google.devtools.build.lib.analysis.config.BuildConfiguration in project bazel by bazelbuild.
the class BuildView method getDynamicConfigurations.
/**
* If {@link BuildConfiguration.Options#trimConfigurations()} is true, transforms a collection of
* <Target, Configuration> pairs by trimming each target's configuration to only the fragments the
* target and its transitive dependencies need.
*
* <p>Else returns configurations that unconditionally include all fragments.
*
* <p>Preserves the original input order. Uses original (untrimmed) configurations for targets
* that can't be evaluated (e.g. due to loading phase errors).
*
* <p>This is suitable for feeding {@link ConfiguredTargetValue} keys: as general principle {@link
* ConfiguredTarget}s should have exactly as much information in their configurations as they need
* to evaluate and no more (e.g. there's no need for Android settings in a C++ configured target).
*/
// TODO(bazel-team): error out early for targets that fail - untrimmed configurations should
// never make it through analysis (and especially not seed ConfiguredTargetValues)
private List<TargetAndConfiguration> getDynamicConfigurations(Iterable<TargetAndConfiguration> inputs, ExtendedEventHandler eventHandler) throws InterruptedException {
Map<Label, Target> labelsToTargets = new LinkedHashMap<>();
// We'll get the configs from SkyframeExecutor#getConfigurations, which gets configurations
// for deps including transitions. So to satisfy its API we repackage each target as a
// Dependency with a NONE transition.
Multimap<BuildConfiguration, Dependency> asDeps = ArrayListMultimap.<BuildConfiguration, Dependency>create();
for (TargetAndConfiguration targetAndConfig : inputs) {
labelsToTargets.put(targetAndConfig.getLabel(), targetAndConfig.getTarget());
Attribute.Transition ruleclassTransition = null;
if (targetAndConfig.getTarget().getAssociatedRule() != null) {
ruleclassTransition = targetAndConfig.getTarget().getAssociatedRule().getRuleClassObject().getTransition();
}
if (targetAndConfig.getConfiguration() != null) {
asDeps.put(targetAndConfig.getConfiguration(), Dependency.withTransitionAndAspects(targetAndConfig.getLabel(), ruleclassTransition == null ? Attribute.ConfigurationTransition.NONE : ruleclassTransition, // TODO(bazel-team): support top-level aspects
AspectCollection.EMPTY));
}
}
// Maps <target, originalConfig> pairs to <target, dynamicConfig> pairs for targets that
// could be successfully Skyframe-evaluated.
Map<TargetAndConfiguration, TargetAndConfiguration> successfullyEvaluatedTargets = new LinkedHashMap<>();
if (!asDeps.isEmpty()) {
for (BuildConfiguration fromConfig : asDeps.keySet()) {
Multimap<Dependency, BuildConfiguration> trimmedTargets = skyframeExecutor.getConfigurations(eventHandler, fromConfig.getOptions(), asDeps.get(fromConfig));
for (Map.Entry<Dependency, BuildConfiguration> trimmedTarget : trimmedTargets.entries()) {
Target target = labelsToTargets.get(trimmedTarget.getKey().getLabel());
successfullyEvaluatedTargets.put(new TargetAndConfiguration(target, fromConfig), new TargetAndConfiguration(target, trimmedTarget.getValue()));
}
}
}
ImmutableList.Builder<TargetAndConfiguration> result = ImmutableList.<TargetAndConfiguration>builder();
for (TargetAndConfiguration originalInput : inputs) {
if (successfullyEvaluatedTargets.containsKey(originalInput)) {
// The configuration was successfully trimmed.
result.add(successfullyEvaluatedTargets.get(originalInput));
} else {
// Either the configuration couldn't be determined (e.g. loading phase error) or it's null.
result.add(originalInput);
}
}
return result.build();
}
Aggregations