Search in sources :

Example 1 with TriState

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

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;
}
Also used : AndroidBinaryType(com.google.devtools.build.lib.rules.android.AndroidConfiguration.AndroidBinaryType) TriState(com.google.devtools.build.lib.packages.TriState)

Example 3 with TriState

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);
}
Also used : TriState(com.google.devtools.build.lib.packages.TriState)

Example 4 with TriState

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);
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) TriState(com.google.devtools.build.lib.packages.TriState) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

TriState (com.google.devtools.build.lib.packages.TriState)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 ConfiguredAspect (com.google.devtools.build.lib.analysis.ConfiguredAspect)1 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)1 NestedSet (com.google.devtools.build.lib.collect.nestedset.NestedSet)1 AndroidBinaryType (com.google.devtools.build.lib.rules.android.AndroidConfiguration.AndroidBinaryType)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1