Search in sources :

Example 1 with BuildConfiguration

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) AppleCrosstoolSplitTransition(com.google.devtools.build.lib.rules.objc.AppleCrosstoolSplitTransition) SplitTransition(com.google.devtools.build.lib.packages.Attribute.SplitTransition) Transitions(com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection.Transitions) AppleCrosstoolSplitTransition(com.google.devtools.build.lib.rules.objc.AppleCrosstoolSplitTransition) LipoTransition(com.google.devtools.build.lib.rules.cpp.CppRuleClasses.LipoTransition) ConfigurationTransition(com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition) SplitTransition(com.google.devtools.build.lib.packages.Attribute.SplitTransition) AppleCrosstoolTransition(com.google.devtools.build.lib.rules.objc.AppleCrosstoolTransition) Transition(com.google.devtools.build.lib.packages.Attribute.Transition) ConfigurationHolder(com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection.ConfigurationHolder) ConfigurationTransition(com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition)

Example 2 with BuildConfiguration

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)));
        }
    }
}
Also used : Label(com.google.devtools.build.lib.cmdline.Label) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Target(com.google.devtools.build.lib.packages.Target) ViewCreationFailedException(com.google.devtools.build.lib.analysis.ViewCreationFailedException) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) SupportedEnvironmentsProvider(com.google.devtools.build.lib.analysis.constraints.SupportedEnvironmentsProvider) EnvironmentCollection(com.google.devtools.build.lib.analysis.constraints.EnvironmentCollection)

Example 3 with BuildConfiguration

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);
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) Root(com.google.devtools.build.lib.actions.Root) PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 4 with BuildConfiguration

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);
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) ConfiguredTargetKey(com.google.devtools.build.lib.skyframe.ConfiguredTargetKey) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with BuildConfiguration

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();
}
Also used : Attribute(com.google.devtools.build.lib.packages.Attribute) ImmutableList(com.google.common.collect.ImmutableList) Label(com.google.devtools.build.lib.cmdline.Label) LinkedHashMap(java.util.LinkedHashMap) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) Target(com.google.devtools.build.lib.packages.Target) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)51 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)13 Label (com.google.devtools.build.lib.cmdline.Label)12 Artifact (com.google.devtools.build.lib.actions.Artifact)11 ImmutableList (com.google.common.collect.ImmutableList)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 Test (org.junit.Test)8 Attribute (com.google.devtools.build.lib.packages.Attribute)7 BuildOptions (com.google.devtools.build.lib.analysis.config.BuildOptions)6 InvalidConfigurationException (com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)6 Rule (com.google.devtools.build.lib.packages.Rule)6 Target (com.google.devtools.build.lib.packages.Target)6 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)6 SkyKey (com.google.devtools.build.skyframe.SkyKey)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 Nullable (javax.annotation.Nullable)6 Root (com.google.devtools.build.lib.actions.Root)5 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)5 HashMap (java.util.HashMap)5