use of com.google.devtools.build.lib.packages.ConfigurationFragmentPolicy.MissingFragmentPolicy 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