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();
}
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);
}
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());
}
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();
}
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();
}
Aggregations