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