use of com.google.devtools.build.lib.packages.TriState 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.packages.TriState in project bazel by bazelbuild.
the class AndroidBinary method getEffectiveIncrementalDexing.
private static ImmutableSet<AndroidBinaryType> getEffectiveIncrementalDexing(RuleContext ruleContext, List<String> dexopts, boolean isBinaryProguarded) {
TriState override = ruleContext.attributes().get("incremental_dexing", BuildType.TRISTATE);
// raise an error if proguard is enabled (b/c incompatible with incremental dexing ATM).
if (isBinaryProguarded && override == TriState.YES) {
ruleContext.attributeError("incremental_dexing", "target cannot be incrementally dexed because it uses Proguard");
return ImmutableSet.of();
}
if (isBinaryProguarded || override == TriState.NO) {
return ImmutableSet.of();
}
ImmutableSet<AndroidBinaryType> result = override == TriState.YES ? ImmutableSet.copyOf(AndroidBinaryType.values()) : AndroidCommon.getAndroidConfig(ruleContext).getIncrementalDexingBinaries();
if (!result.isEmpty()) {
Iterable<String> blacklistedDexopts = Iterables.filter(dexopts, new FlagMatcher(AndroidCommon.getAndroidConfig(ruleContext).getTargetDexoptsThatPreventIncrementalDexing()));
if (!Iterables.isEmpty(blacklistedDexopts)) {
// incrementally dex anyway. Otherwise, just don't incrementally dex.
if (override == TriState.YES) {
Iterable<String> ignored = Iterables.filter(blacklistedDexopts, Predicates.not(Predicates.in(AndroidCommon.getAndroidConfig(ruleContext).getDexoptsSupportedInIncrementalDexing())));
ruleContext.attributeWarning("incremental_dexing", String.format("Using incremental dexing even though dexopts %s indicate this target " + "may be unsuitable for incremental dexing for the moment.%s", blacklistedDexopts, Iterables.isEmpty(ignored) ? "" : " These will be ignored: " + ignored));
} else {
result = ImmutableSet.of();
}
}
}
return result;
}
use of com.google.devtools.build.lib.packages.TriState in project bazel by bazelbuild.
the class AndroidBinary method shouldShrinkResources.
/** Returns {@code true} if resource shrinking should be performed. */
private static boolean shouldShrinkResources(RuleContext ruleContext) {
TriState state = ruleContext.attributes().get("shrink_resources", BuildType.TRISTATE);
if (state == TriState.AUTO) {
boolean globalShrinkResources = ruleContext.getFragment(AndroidConfiguration.class).useAndroidResourceShrinking();
state = (globalShrinkResources) ? TriState.YES : TriState.NO;
}
return (state == TriState.YES);
}
use of com.google.devtools.build.lib.packages.TriState in project bazel by bazelbuild.
the class ProtoCommon method areDepsStrict.
/**
* Decides whether this proto_library should check for strict proto deps.
*
* <p>Takes into account command-line flags, package-level attributes and rule attributes.
*/
@VisibleForTesting
public static boolean areDepsStrict(RuleContext ruleContext) {
BuildConfiguration.StrictDepsMode flagValue = ruleContext.getFragment(ProtoConfiguration.class).strictProtoDeps();
if (flagValue == BuildConfiguration.StrictDepsMode.OFF) {
return false;
}
if (flagValue == BuildConfiguration.StrictDepsMode.ERROR || flagValue == BuildConfiguration.StrictDepsMode.WARN) {
return true;
}
TriState attrValue = ruleContext.attributes().get("strict_proto_deps", TRISTATE);
if (attrValue == TriState.NO) {
return false;
}
if (attrValue == TriState.YES) {
return true;
}
ImmutableSet<String> pkgFeatures = ruleContext.getRule().getPackage().getFeatures();
if (pkgFeatures.contains("disable_strict_proto_deps_NO")) {
return false;
}
if (pkgFeatures.contains("disable_strict_proto_deps_YES")) {
return true;
}
return (flagValue == BuildConfiguration.StrictDepsMode.STRICT);
}
Aggregations