aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/android/ResourceFilter.java
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-07-26 20:52:55 +0200
committerGravatar Jakob Buchgraber <buchgr@google.com>2017-07-27 09:05:17 +0200
commitab39f78d88bd0bfcf0664d95b06125416dd04033 (patch)
treefc93da5fbb0d5539f21434fe4f9dd2388b7f2e5c /src/main/java/com/google/devtools/build/lib/rules/android/ResourceFilter.java
parent43bc4923e5b2219924ae95f17ffe8b9f35f32fce (diff)
Resource filtering should preserve all matching artifacts, despite shared names
Before this change, density-based resource filtering tracked resources by qualifiers and name. Resources with density qualifiers specified would go into this code, but only one resource would be chosen from each each (qualifier, name) pair. Instead, track the resource using its entire path, this tracking resources with the same name seperately. Also, in case multiple resource are passed to the resource processing action, resource filtering only ignores a file if its name was in the list of resources to ignore *and* it does not exist. Otherwise, legitimate resources with the same name as a filtered resource might be ignored. RELNOTES: none PiperOrigin-RevId: 163235681
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/android/ResourceFilter.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ResourceFilter.java10
1 files changed, 9 insertions, 1 deletions
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 52f155a3f6..14624286de 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
@@ -33,6 +33,7 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.packages.AttributeMap;
import com.google.devtools.build.lib.packages.RuleErrorConsumer;
import com.google.devtools.build.lib.syntax.Type;
+import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.common.options.EnumConverter;
import com.google.devtools.common.options.OptionsParsingException;
import java.util.ArrayList;
@@ -501,8 +502,15 @@ public class ResourceFilter {
// We want to find a single best artifact for each combination of non-density qualifiers and
// filename. Combine those two values to create a single unique key.
+ // We also need to include the path to the resource, otherwise resource conflicts (multiple
+ // resources with the same name but different locations) might accidentally get resolved here
+ // (possibly incorrectly). Resource conflicts should be resolve during merging in execution
+ // instead.
config.setDensityQualifier(null);
- String nameAndConfiguration = config.getUniqueKey() + "/" + artifact.getFilename();
+ Path qualifierDir = artifact.getPath().getParentDirectory();
+ String resourceDir = qualifierDir.getParentDirectory().toString();
+ String nameAndConfiguration =
+ Joiner.on('/').join(resourceDir, config.getUniqueKey(), artifact.getFilename());
Artifact currentBest = nameAndConfigurationToBestArtifact.get(nameAndConfiguration);