use of com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException in project bazel by bazelbuild.
the class CcProtoAspect method create.
@Override
public ConfiguredAspect create(ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException {
// Get SupportData, which is provided by the proto_library rule we attach to.
SupportData supportData = checkNotNull(base.getProvider(ProtoSupportDataProvider.class)).getSupportData();
try {
ConfiguredAspect.Builder result = new ConfiguredAspect.Builder(this, parameters, ruleContext);
new Impl(ruleContext, supportData, cppSemantics).addProviders(result);
return result.build();
} catch (RuleErrorException e) {
ruleContext.ruleError(e.getMessage());
return null;
}
}
use of com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException in project bazel by bazelbuild.
the class J2ObjcAspect method buildAspect.
private ConfiguredAspect buildAspect(ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters, J2ObjcSource j2ObjcSource, J2ObjcMappingFileProvider directJ2ObjcMappingFileProvider, Iterable<Attribute> depAttributes) throws InterruptedException {
ConfiguredAspect.Builder builder = new ConfiguredAspect.Builder(this, parameters, ruleContext);
ObjcCommon common;
XcodeProvider xcodeProvider;
if (!Iterables.isEmpty(j2ObjcSource.getObjcSrcs())) {
common = common(ruleContext, j2ObjcSource.getObjcSrcs(), j2ObjcSource.getObjcHdrs(), j2ObjcSource.getHeaderSearchPaths(), depAttributes);
xcodeProvider = xcodeProvider(ruleContext, common, j2ObjcSource.getObjcHdrs(), j2ObjcSource.getHeaderSearchPaths(), depAttributes);
try {
CcToolchainProvider ccToolchain = CppHelper.getToolchain(ruleContext, ":j2objc_cc_toolchain");
FdoSupportProvider fdoSupport = CppHelper.getFdoSupport(ruleContext, ":j2objc_cc_toolchain");
CompilationSupport compilationSupport = CompilationSupport.createWithSelectedImplementation(ruleContext, ruleContext.getConfiguration(), ObjcRuleClasses.j2objcIntermediateArtifacts(ruleContext), CompilationAttributes.Builder.fromRuleContext(ruleContext).build());
compilationSupport.registerCompileAndArchiveActions(common.getCompilationArtifacts().get(), common.getObjcProvider(), EXTRA_COMPILE_ARGS, ImmutableList.<PathFragment>of(), ccToolchain, fdoSupport).registerFullyLinkAction(common.getObjcProvider(), ruleContext.getImplicitOutputArtifact(CompilationSupport.FULLY_LINKED_LIB), ccToolchain, fdoSupport);
} catch (RuleErrorException e) {
ruleContext.ruleError(e.getMessage());
}
} else {
common = common(ruleContext, ImmutableList.<Artifact>of(), ImmutableList.<Artifact>of(), ImmutableList.<PathFragment>of(), depAttributes);
xcodeProvider = xcodeProvider(ruleContext, common, ImmutableList.<Artifact>of(), ImmutableList.<PathFragment>of(), depAttributes);
}
return builder.addProvider(exportedJ2ObjcMappingFileProvider(base, ruleContext, directJ2ObjcMappingFileProvider)).addProvider(common.getObjcProvider()).addProvider(xcodeProvider).build();
}
use of com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException 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