aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-08-21 18:48:13 +0200
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-08-22 09:13:27 +0200
commitd795133a34fd2a61177be3febb9c61c83b10f3c2 (patch)
tree5213503e8af0891bb796d87b325d9b671a60aaf8 /src/main/java/com/google
parent3ff87f79c6a579272532bc676acdf924db1e8b59 (diff)
Resource filtering properly handles pseudolocales
Pseudolocalized resources are generated by aapt in response to their locales being passed to aapt. However, when filtering in analysis, we attempted to save time by not passing any filters to aapt. Fix this by passing the filters if pseudolocales were specified. RELNOTES: none PiperOrigin-RevId: 165939670
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ResourceFilter.java48
2 files changed, 49 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java
index 5605a04d6f..dd28572c62 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java
@@ -451,7 +451,7 @@ public class AndroidResourcesProcessorBuilder {
builder.addExecPath("--packagePath", apkOut);
outs.add(apkOut);
}
- if (resourceFilter.hasConfigurationFilters() && !resourceFilter.isPrefiltering()) {
+ if (resourceFilter.shouldPropagateConfigs(ruleContext)) {
builder.add("--resourceConfigs", resourceFilter.getConfigurationFilterString());
}
if (resourceFilter.hasDensities() && !resourceFilter.isPrefiltering()) {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceFilter.java b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceFilter.java
index b8a25b19df..3b828a146f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceFilter.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceFilter.java
@@ -15,6 +15,7 @@ package com.google.devtools.build.lib.rules.android;
import com.android.ide.common.resources.configuration.DensityQualifier;
import com.android.ide.common.resources.configuration.FolderConfiguration;
+import com.android.ide.common.resources.configuration.LocaleQualifier;
import com.android.ide.common.resources.configuration.VersionQualifier;
import com.android.resources.Density;
import com.android.resources.ResourceFolderType;
@@ -60,6 +61,23 @@ public class ResourceFilter {
public static final String RESOURCE_CONFIGURATION_FILTERS_NAME = "resource_configuration_filters";
public static final String DENSITIES_NAME = "densities";
+ /**
+ * Locales used for pseudolocation.
+ *
+ * <p>These are special resources that can be used to test how apps handles special cases (such as
+ * particularly long text, accents, or left-to-right text). These resources are not provided like
+ * other resources; instead, when the appropriate filters are passed in, aapt generates them based
+ * on the default resources.
+ *
+ * <p>When these locales are specified in the configuration filters, even if we are filtering in
+ * analysis, we need to pass *all* configuration filters to aapt - the pseudolocalization filters
+ * themselves to trigger pseudolocalization, and the other filters to prevent aapt from filtering
+ * matching resources out.
+ */
+ private static final ImmutableSet<LocaleQualifier> PSEUDOLOCATION_LOCALES =
+ ImmutableSet.of(
+ LocaleQualifier.getQualifier("en-rXA"), LocaleQualifier.getQualifier("ar-rXB"));
+
@VisibleForTesting
static enum FilterBehavior {
/**
@@ -699,6 +717,36 @@ public class ResourceFilter {
return filterBehavior == FilterBehavior.FILTER_IN_ANALYSIS_WITH_DYNAMIC_CONFIGURATION;
}
+ /**
+ * @return whether resource configuration filters should be propagated to the resource processing
+ * action and eventually to aapt.
+ */
+ public boolean shouldPropagateConfigs(RuleErrorConsumer ruleErrorConsumer) {
+ if (!hasConfigurationFilters()) {
+ // There are no filters to propagate
+ return false;
+ }
+
+ if (!isPrefiltering()) {
+ // The filters were not applied in analysis and must be applied in execution
+ return true;
+ }
+
+ for (FolderConfiguration config : getConfigurationFilters((ruleErrorConsumer))) {
+ for (LocaleQualifier pseudoLocale : PSEUDOLOCATION_LOCALES) {
+ if (pseudoLocale.equals(config.getLocaleQualifier())) {
+ // A pseudolocale was used, and needs to be propagated to aapt. Propagate all
+ // configuration values so that aapt does not filter out those that were skipped.
+ return true;
+ }
+ }
+ }
+
+ // Filtering already happened, and there's no reason to have aapt waste its time trying to
+ // filter again. Don't propagate the filters.
+ return false;
+ }
+
/*
* TODO: Stop tracking these once {@link FilterBehavior#FILTER_IN_ANALYSIS} is fully replaced by
* {@link FilterBehavior#FILTER_IN_ANALYSIS_WITH_DYNAMIC_CONFIGURATION}.