Search in sources :

Example 11 with ConfiguredAspect

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();
}
Also used : ConfiguredAspect(com.google.devtools.build.lib.analysis.ConfiguredAspect) RuleErrorException(com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) ProtoCompileActionBuilder(com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder) FdoSupportProvider(com.google.devtools.build.lib.rules.cpp.FdoSupportProvider) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) CcToolchainProvider(com.google.devtools.build.lib.rules.cpp.CcToolchainProvider) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 12 with ConfiguredAspect

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;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ConfiguredAspect(com.google.devtools.build.lib.analysis.ConfiguredAspect) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) MergedConfiguredTarget(com.google.devtools.build.lib.analysis.MergedConfiguredTarget) Dependency(com.google.devtools.build.lib.analysis.Dependency) ValueOrException2(com.google.devtools.build.skyframe.ValueOrException2) AspectCreationException(com.google.devtools.build.lib.skyframe.AspectFunction.AspectCreationException) NoSuchThingException(com.google.devtools.build.lib.packages.NoSuchThingException) AspectDeps(com.google.devtools.build.lib.analysis.AspectCollection.AspectDeps) AspectDescriptor(com.google.devtools.build.lib.packages.AspectDescriptor) HashSet(java.util.HashSet) Nullable(javax.annotation.Nullable)

Aggregations

ConfiguredAspect (com.google.devtools.build.lib.analysis.ConfiguredAspect)12 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)5 Artifact (com.google.devtools.build.lib.actions.Artifact)4 ProtoCompileActionBuilder (com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder)4 SupportData (com.google.devtools.build.lib.rules.proto.SupportData)3 RuleErrorException (com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException)2 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)2 SkyKey (com.google.devtools.build.skyframe.SkyKey)2 HashSet (java.util.HashSet)2 Nullable (javax.annotation.Nullable)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 AspectDeps (com.google.devtools.build.lib.analysis.AspectCollection.AspectDeps)1 CachingAnalysisEnvironment (com.google.devtools.build.lib.analysis.CachingAnalysisEnvironment)1 Builder (com.google.devtools.build.lib.analysis.ConfiguredAspect.Builder)1 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)1 Dependency (com.google.devtools.build.lib.analysis.Dependency)1 MergedConfiguredTarget (com.google.devtools.build.lib.analysis.MergedConfiguredTarget)1 OutputGroupProvider (com.google.devtools.build.lib.analysis.OutputGroupProvider)1 NestedSet (com.google.devtools.build.lib.collect.nestedset.NestedSet)1 Location (com.google.devtools.build.lib.events.Location)1