use of com.google.devtools.build.lib.analysis.ConfiguredAspect 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.analysis.ConfiguredAspect in project bazel by bazelbuild.
the class ConfiguredTargetFunction method resolveAspectDependencies.
/**
* Given a list of {@link Dependency} objects, returns a multimap from the {@link SkyKey} of the
* dependency to the {@link ConfiguredAspect} instances that should be merged into it.
*
* <p>Returns null if the required aspects are not computed yet.
*/
@Nullable
private static OrderedSetMultimap<SkyKey, ConfiguredAspect> resolveAspectDependencies(Environment env, Map<SkyKey, ConfiguredTarget> configuredTargetMap, Iterable<Dependency> deps, NestedSetBuilder<Package> transitivePackages) throws AspectCreationException, InterruptedException {
OrderedSetMultimap<SkyKey, ConfiguredAspect> result = OrderedSetMultimap.create();
Set<SkyKey> allAspectKeys = new HashSet<>();
for (Dependency dep : deps) {
allAspectKeys.addAll(getAspectKeys(dep).values());
}
Map<SkyKey, ValueOrException2<AspectCreationException, NoSuchThingException>> depAspects = env.getValuesOrThrow(allAspectKeys, AspectCreationException.class, NoSuchThingException.class);
for (Dependency dep : deps) {
SkyKey depKey = TO_KEYS.apply(dep);
// twice.
if (result.containsKey(depKey)) {
continue;
}
Map<AspectDescriptor, SkyKey> aspectToKeys = getAspectKeys(dep);
ConfiguredTarget depConfiguredTarget = configuredTargetMap.get(depKey);
for (AspectDeps depAspect : dep.getAspects().getVisibleAspects()) {
SkyKey aspectKey = aspectToKeys.get(depAspect.getAspect());
AspectValue aspectValue;
try {
// TODO(ulfjack): Catch all thrown AspectCreationException and NoSuchThingException
// instances and merge them into a single Exception to get full root cause data.
aspectValue = (AspectValue) depAspects.get(aspectKey).get();
} catch (NoSuchThingException e) {
throw new AspectCreationException(String.format("Evaluation of aspect %s on %s failed: %s", depAspect.getAspect().getAspectClass().getName(), dep.getLabel(), e.toString()));
}
if (aspectValue == null) {
// Dependent aspect has either not been computed yet or is in error.
return null;
}
if (!aspectMatchesConfiguredTarget(depConfiguredTarget, aspectValue.getAspect())) {
continue;
}
result.put(depKey, aspectValue.getConfiguredAspect());
transitivePackages.addTransitive(aspectValue.getTransitivePackages());
}
}
return result;
}
Aggregations