Search in sources :

Example 1 with ConfiguredAspect

use of com.google.devtools.build.lib.analysis.ConfiguredAspect in project bazel by bazelbuild.

the class DexArchiveAspect method create.

@Override
public ConfiguredAspect create(ConfiguredTarget base, RuleContext ruleContext, AspectParameters params) throws InterruptedException {
    ConfiguredAspect.Builder result = new ConfiguredAspect.Builder(this, params, ruleContext);
    Function<Artifact, Artifact> desugaredJars = desugarJarsIfRequested(base, ruleContext, result);
    TriState incrementalAttr = TriState.valueOf(params.getOnlyValueOfAttribute("incremental_dexing"));
    if (incrementalAttr == TriState.NO || (getAndroidConfig(ruleContext).getIncrementalDexingBinaries().isEmpty() && incrementalAttr != TriState.YES)) {
        // Dex archives will never be used, so don't bother setting them up.
        return result.build();
    }
    if (JavaCommon.isNeverLink(ruleContext)) {
        return result.addProvider(DexArchiveProvider.NEVERLINK).build();
    }
    DexArchiveProvider.Builder dexArchives = new DexArchiveProvider.Builder().addTransitiveProviders(collectPrerequisites(ruleContext, DexArchiveProvider.class));
    Iterable<Artifact> runtimeJars = getProducedRuntimeJars(base, ruleContext);
    if (runtimeJars != null) {
        boolean basenameClash = checkBasenameClash(runtimeJars);
        Set<Set<String>> aspectDexopts = aspectDexopts(ruleContext);
        for (Artifact jar : runtimeJars) {
            for (Set<String> incrementalDexopts : aspectDexopts) {
                // Since we're potentially dexing the same jar multiple times with different flags, we
                // need to write unique artifacts for each flag combination. Here, it is convenient to
                // distinguish them by putting the flags that were used for creating the artifacts into
                // their filenames.
                String uniqueFilename = (basenameClash ? jar.getRootRelativePathString() : jar.getFilename()) + Joiner.on("").join(incrementalDexopts) + ".dex.zip";
                Artifact dexArchive = createDexArchiveAction(ruleContext, ASPECT_DEXBUILDER_PREREQ, desugaredJars.apply(jar), incrementalDexopts, AndroidBinary.getDxArtifact(ruleContext, uniqueFilename));
                dexArchives.addDexArchive(incrementalDexopts, dexArchive, jar);
            }
        }
    }
    return result.addProvider(dexArchives.build()).build();
}
Also used : ConfiguredAspect(com.google.devtools.build.lib.analysis.ConfiguredAspect) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) NestedSet(com.google.devtools.build.lib.collect.nestedset.NestedSet) Artifact(com.google.devtools.build.lib.actions.Artifact) TriState(com.google.devtools.build.lib.packages.TriState)

Example 2 with ConfiguredAspect

use of com.google.devtools.build.lib.analysis.ConfiguredAspect in project bazel by bazelbuild.

the class AspectFunction method getBaseTargetAndCollectPath.

/**
   * Merges aspects defined by {@code aspectKeys} into the {@code target} using
   * previously computed {@code values}.
   *
   * Also populates {@code aspectPath}.
   *
   * @return A {@link ConfiguredTarget} that is a result of a merge.
   * @throws DuplicateException if there is a duplicate provider provided by aspects.
   */
private ConfiguredTarget getBaseTargetAndCollectPath(ConfiguredTarget target, ImmutableList<AspectKey> aspectKeys, Map<SkyKey, SkyValue> values, ImmutableList.Builder<Aspect> aspectPath) throws DuplicateException {
    ArrayList<ConfiguredAspect> aspectValues = new ArrayList<>();
    for (AspectKey aspectKey : aspectKeys) {
        SkyKey skyAspectKey = aspectKey.getSkyKey();
        AspectValue aspectValue = (AspectValue) values.get(skyAspectKey);
        ConfiguredAspect configuredAspect = aspectValue.getConfiguredAspect();
        aspectValues.add(configuredAspect);
        aspectPath.add(aspectValue.getAspect());
    }
    return MergedConfiguredTarget.of(target, aspectValues);
}
Also used : ConfiguredAspect(com.google.devtools.build.lib.analysis.ConfiguredAspect) SkyKey(com.google.devtools.build.skyframe.SkyKey) AspectKey(com.google.devtools.build.lib.skyframe.AspectValue.AspectKey) ArrayList(java.util.ArrayList)

Example 3 with ConfiguredAspect

use of com.google.devtools.build.lib.analysis.ConfiguredAspect in project bazel by bazelbuild.

the class AspectFunction method createAspect.

@Nullable
private AspectValue createAspect(Environment env, AspectKey key, ImmutableList<Aspect> aspectPath, Aspect aspect, ConfiguredAspectFactory aspectFactory, ConfiguredTarget associatedTarget, BuildConfiguration aspectConfiguration, ImmutableMap<Label, ConfigMatchingProvider> configConditions, OrderedSetMultimap<Attribute, ConfiguredTarget> directDeps, NestedSetBuilder<Package> transitivePackages) throws AspectFunctionException, InterruptedException {
    SkyframeBuildView view = buildViewProvider.getSkyframeBuildView();
    StoredEventHandler events = new StoredEventHandler();
    CachingAnalysisEnvironment analysisEnvironment = view.createAnalysisEnvironment(key, false, events, env, aspectConfiguration);
    if (env.valuesMissing()) {
        return null;
    }
    ConfiguredAspect configuredAspect;
    if (ConfiguredTargetFunction.aspectMatchesConfiguredTarget(associatedTarget, aspect)) {
        configuredAspect = view.getConfiguredTargetFactory().createAspect(analysisEnvironment, associatedTarget, aspectPath, aspectFactory, aspect, directDeps, configConditions, aspectConfiguration, view.getHostConfiguration(aspectConfiguration));
    } else {
        configuredAspect = ConfiguredAspect.forNonapplicableTarget(aspect.getDescriptor());
    }
    events.replayOn(env.getListener());
    if (events.hasErrors()) {
        analysisEnvironment.disable(associatedTarget.getTarget());
        throw new AspectFunctionException(new AspectCreationException("Analysis of target '" + associatedTarget.getLabel() + "' failed; build aborted"));
    }
    Preconditions.checkState(!analysisEnvironment.hasErrors(), "Analysis environment hasError() but no errors reported");
    if (env.valuesMissing()) {
        return null;
    }
    analysisEnvironment.disable(associatedTarget.getTarget());
    Preconditions.checkNotNull(configuredAspect);
    return new AspectValue(key, aspect, associatedTarget.getLabel(), associatedTarget.getTarget().getLocation(), configuredAspect, ImmutableList.copyOf(analysisEnvironment.getRegisteredActions()), transitivePackages.build());
}
Also used : ConfiguredAspect(com.google.devtools.build.lib.analysis.ConfiguredAspect) StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) CachingAnalysisEnvironment(com.google.devtools.build.lib.analysis.CachingAnalysisEnvironment) Nullable(javax.annotation.Nullable)

Example 4 with ConfiguredAspect

use of com.google.devtools.build.lib.analysis.ConfiguredAspect in project bazel by bazelbuild.

the class ObjcProtoAspect method create.

@Override
public ConfiguredAspect create(ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException {
    ConfiguredAspect.Builder aspectBuilder = new ConfiguredAspect.Builder(this, parameters, ruleContext);
    ObjcProtoProvider.Builder aspectObjcProtoProvider = new ObjcProtoProvider.Builder();
    if (ruleContext.attributes().has("deps", BuildType.LABEL_LIST)) {
        Iterable<ObjcProtoProvider> depObjcProtoProviders = ruleContext.getPrerequisites("deps", Mode.TARGET, ObjcProtoProvider.class);
        aspectObjcProtoProvider.addTransitive(depObjcProtoProviders);
    }
    // Validation for the correct target attributes is done in ProtoSupport.java.
    if (ruleContext.attributes().isAttributeValueExplicitlySpecified(ObjcProtoLibraryRule.PORTABLE_PROTO_FILTERS_ATTR)) {
        aspectObjcProtoProvider.addPortableProtoFilters(PrerequisiteArtifacts.nestedSet(ruleContext, ObjcProtoLibraryRule.PORTABLE_PROTO_FILTERS_ATTR, Mode.HOST));
        // Gather up all the dependency protos depended by this target.
        Iterable<ProtoSourcesProvider> protoProviders = ruleContext.getPrerequisites("deps", Mode.TARGET, ProtoSourcesProvider.class);
        for (ProtoSourcesProvider protoProvider : protoProviders) {
            aspectObjcProtoProvider.addProtoGroup(protoProvider.getTransitiveProtoSources());
        }
        // Propagate protobuf's headers and search paths so the BinaryLinkingTargetFactory subclasses
        // (i.e. objc_binary) don't have to depend on it.
        ObjcProvider protobufObjcProvider = ruleContext.getPrerequisite(ObjcRuleClasses.PROTO_LIB_ATTR, Mode.TARGET, ObjcProvider.class);
        aspectObjcProtoProvider.addProtobufHeaders(protobufObjcProvider.get(ObjcProvider.HEADER));
        aspectObjcProtoProvider.addProtobufHeaderSearchPaths(protobufObjcProvider.get(ObjcProvider.INCLUDE));
    }
    // Only add the provider if it has any values, otherwise skip it.
    if (!aspectObjcProtoProvider.isEmpty()) {
        aspectBuilder.addProvider(aspectObjcProtoProvider.build());
    }
    return aspectBuilder.build();
}
Also used : ConfiguredAspect(com.google.devtools.build.lib.analysis.ConfiguredAspect) ProtoSourcesProvider(com.google.devtools.build.lib.rules.proto.ProtoSourcesProvider)

Example 5 with ConfiguredAspect

use of com.google.devtools.build.lib.analysis.ConfiguredAspect in project bazel by bazelbuild.

the class JavaLiteProtoAspect method create.

@Override
public ConfiguredAspect create(ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException {
    ConfiguredAspect.Builder aspect = new ConfiguredAspect.Builder(this, parameters, ruleContext);
    // Get SupportData, which is provided by the proto_library rule we attach to.
    SupportData supportData = checkNotNull(base.getProvider(ProtoSupportDataProvider.class)).getSupportData();
    Impl impl = new Impl(ruleContext, supportData, javaSemantics);
    impl.addProviders(aspect);
    return aspect.build();
}
Also used : ConfiguredAspect(com.google.devtools.build.lib.analysis.ConfiguredAspect) SupportData(com.google.devtools.build.lib.rules.proto.SupportData) ProtoCompileActionBuilder(com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)

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