Search in sources :

Example 1 with ConfigurationFragmentPolicy

use of com.google.devtools.build.lib.packages.ConfigurationFragmentPolicy in project bazel by bazelbuild.

the class TransitiveTargetFunction method computeSkyValue.

@Override
public SkyValue computeSkyValue(TargetAndErrorIfAny targetAndErrorIfAny, TransitiveTargetValueBuilder builder) {
    Target target = targetAndErrorIfAny.getTarget();
    NoSuchTargetException errorLoadingTarget = targetAndErrorIfAny.getErrorLoadingTarget();
    // Get configuration fragments directly required by this rule.
    if (target instanceof Rule) {
        Rule rule = (Rule) target;
        // Declared by the rule class:
        ConfigurationFragmentPolicy configurationFragmentPolicy = rule.getRuleClassObject().getConfigurationFragmentPolicy();
        for (ConfigurationFragmentFactory factory : ruleClassProvider.getConfigurationFragments()) {
            Class<? extends Fragment> fragment = factory.creates();
            // (named) fragments.
            if (configurationFragmentPolicy.isLegalConfigurationFragment(fragment)) {
                addFragmentIfNew(builder, fragment.asSubclass(BuildConfiguration.Fragment.class));
            }
        }
        // Declared by late-bound attributes:
        for (Attribute attr : rule.getAttributes()) {
            if (attr.isLateBound()) {
                addFragmentsIfNew(builder, attr.getLateBoundDefault().getRequiredConfigurationFragments());
            }
        }
        // corresponding fragments in their configurations to properly resolve:
        if (rule.getRuleClass().equals(ConfigSettingRule.RULE_NAME)) {
            addFragmentsIfNew(builder, ConfigSettingRule.requiresConfigurationFragments(rule, optionsToFragmentMap));
        }
        // Fragments to unconditionally include:
        addFragmentIfNew(builder, ruleClassProvider.getUniversalFragment().asSubclass(BuildConfiguration.Fragment.class));
    }
    return builder.build(errorLoadingTarget);
}
Also used : Target(com.google.devtools.build.lib.packages.Target) ConfigurationFragmentPolicy(com.google.devtools.build.lib.packages.ConfigurationFragmentPolicy) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) Attribute(com.google.devtools.build.lib.packages.Attribute) ConfigSettingRule(com.google.devtools.build.lib.analysis.config.ConfigRuleClasses.ConfigSettingRule) Rule(com.google.devtools.build.lib.packages.Rule) ConfigurationFragmentFactory(com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory) Fragment(com.google.devtools.build.lib.analysis.config.BuildConfiguration.Fragment)

Example 2 with ConfigurationFragmentPolicy

use of com.google.devtools.build.lib.packages.ConfigurationFragmentPolicy in project bazel by bazelbuild.

the class ConfiguredTargetFactory method createRule.

/**
   * Factory method: constructs a RuleConfiguredTarget of the appropriate class, based on the rule
   * class. May return null if an error occurred.
   */
@Nullable
private ConfiguredTarget createRule(AnalysisEnvironment env, Rule rule, BuildConfiguration configuration, BuildConfiguration hostConfiguration, OrderedSetMultimap<Attribute, ConfiguredTarget> prerequisiteMap, ImmutableMap<Label, ConfigMatchingProvider> configConditions) throws InterruptedException {
    // Visibility computation and checking is done for every rule.
    RuleContext ruleContext = new RuleContext.Builder(env, rule, ImmutableList.<AspectDescriptor>of(), configuration, hostConfiguration, ruleClassProvider.getPrerequisiteValidator(), rule.getRuleClassObject().getConfigurationFragmentPolicy()).setVisibility(convertVisibility(prerequisiteMap, env.getEventHandler(), rule, null)).setPrerequisites(prerequisiteMap).setConfigConditions(configConditions).setUniversalFragment(ruleClassProvider.getUniversalFragment()).setSkylarkProvidersRegistry(ruleClassProvider.getRegisteredSkylarkProviders()).build();
    if (ruleContext.hasErrors()) {
        return null;
    }
    ConfigurationFragmentPolicy configurationFragmentPolicy = rule.getRuleClassObject().getConfigurationFragmentPolicy();
    MissingFragmentPolicy missingFragmentPolicy = configurationFragmentPolicy.getMissingFragmentPolicy();
    if (missingFragmentPolicy != MissingFragmentPolicy.IGNORE && !configuration.hasAllFragments(configurationFragmentPolicy.getRequiredConfigurationFragments())) {
        if (missingFragmentPolicy == MissingFragmentPolicy.FAIL_ANALYSIS) {
            ruleContext.ruleError(missingFragmentError(ruleContext, configurationFragmentPolicy));
            return null;
        }
        // Otherwise missingFragmentPolicy == MissingFragmentPolicy.CREATE_FAIL_ACTIONS:
        return createFailConfiguredTarget(ruleContext);
    }
    if (rule.getRuleClassObject().isSkylark()) {
        // TODO(bazel-team): maybe merge with RuleConfiguredTargetBuilder?
        return SkylarkRuleConfiguredTargetBuilder.buildRule(ruleContext, rule.getRuleClassObject().getConfiguredTargetFunction(), ruleClassProvider.getRegisteredSkylarkProviders());
    } else {
        RuleClass.ConfiguredTargetFactory<ConfiguredTarget, RuleContext> factory = rule.getRuleClassObject().<ConfiguredTarget, RuleContext>getConfiguredTargetFactory();
        Preconditions.checkNotNull(factory, rule.getRuleClassObject());
        try {
            return factory.create(ruleContext);
        } catch (RuleErrorException ruleErrorException) {
            // inspect ruleContext for multiple errors and output thorough messaging on each.
            return null;
        }
    }
}
Also used : RuleErrorException(com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException) ConfigurationFragmentPolicy(com.google.devtools.build.lib.packages.ConfigurationFragmentPolicy) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) SkylarkRuleConfiguredTargetBuilder(com.google.devtools.build.lib.rules.SkylarkRuleConfiguredTargetBuilder) MissingFragmentPolicy(com.google.devtools.build.lib.packages.ConfigurationFragmentPolicy.MissingFragmentPolicy) RuleClass(com.google.devtools.build.lib.packages.RuleClass) Nullable(javax.annotation.Nullable)

Aggregations

ConfigurationFragmentPolicy (com.google.devtools.build.lib.packages.ConfigurationFragmentPolicy)2 Fragment (com.google.devtools.build.lib.analysis.config.BuildConfiguration.Fragment)1 ConfigSettingRule (com.google.devtools.build.lib.analysis.config.ConfigRuleClasses.ConfigSettingRule)1 ConfigurationFragmentFactory (com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory)1 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)1 Attribute (com.google.devtools.build.lib.packages.Attribute)1 MissingFragmentPolicy (com.google.devtools.build.lib.packages.ConfigurationFragmentPolicy.MissingFragmentPolicy)1 NoSuchTargetException (com.google.devtools.build.lib.packages.NoSuchTargetException)1 Rule (com.google.devtools.build.lib.packages.Rule)1 RuleClass (com.google.devtools.build.lib.packages.RuleClass)1 RuleErrorException (com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException)1 Target (com.google.devtools.build.lib.packages.Target)1 SkylarkRuleConfiguredTargetBuilder (com.google.devtools.build.lib.rules.SkylarkRuleConfiguredTargetBuilder)1 Nullable (javax.annotation.Nullable)1