aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools/android/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2018-01-10 13:10:47 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-01-10 13:12:55 -0800
commitee28bc3a15a7eeeccf21b39b3d307b64ae8acee4 (patch)
tree744dd777fafa131fe1d644da0b5d4a4637fd9c03 /src/tools/android/java/com/google/devtools/build
parentea41dc4f5179533c3c54a786848157cc17dccac2 (diff)
Fix parsing for some aapt2-generated resources.
RELNOTES: none PiperOrigin-RevId: 181506851
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build')
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/AndroidCompiledDataDeserializer.java17
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java31
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java3
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/xml/StyleXmlResourceValue.java14
4 files changed, 43 insertions, 22 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledDataDeserializer.java b/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledDataDeserializer.java
index 265d938fea..232eaa5576 100644
--- a/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledDataDeserializer.java
+++ b/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledDataDeserializer.java
@@ -171,13 +171,16 @@ public class AndroidCompiledDataDeserializer implements AndroidDataDeserializer
}
for (CompiledFile.Symbol exportedSymbol : compiledFile.getExportedSymbolList()) {
- FullyQualifiedName symbolFqn =
- fqnFactory.create(
- ResourceType.ID, exportedSymbol.getResourceName().replaceFirst("id/", ""));
-
- DataResourceXml dataResourceXml =
- DataResourceXml.from(null, dataSource, ResourceType.ID, null);
- consumers.combiningConsumer.accept(symbolFqn, dataResourceXml);
+ if (!exportedSymbol.getResourceName().startsWith("android:")) {
+ // Skip writing resource xml's for resources in the sdk
+ FullyQualifiedName symbolFqn =
+ fqnFactory.create(
+ ResourceType.ID, exportedSymbol.getResourceName().replaceFirst("id/", ""));
+
+ DataResourceXml dataResourceXml =
+ DataResourceXml.from(null, dataSource, ResourceType.ID, null);
+ consumers.combiningConsumer.accept(symbolFqn, dataResourceXml);
+ }
}
}
diff --git a/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java b/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java
index 50c5ff5b13..75ac26a993 100644
--- a/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java
+++ b/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java
@@ -215,17 +215,34 @@ public class ResourceCompiler {
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
// Ignore directories and "hidden" files that start with .
if (!Files.isDirectory(file) && !file.getFileName().toString().startsWith(".")) {
+ // Creates a relative output path based on the input path under the
+ // compiledResources path.
+ Path outputDirectory = Files.createDirectories(
+ compiledResources.resolve(
+ (file.isAbsolute() ? file.getRoot().relativize(file) : file)
+ .getParent()
+ .getParent()));
+
+ String resFolder = file.getParent().getFileName().toString().toLowerCase();
+
+ // Aapt cannot interpret these regions so we rename them to get them to compile
+ String renamedResFolder = resFolder
+ .replaceFirst("sr[_\\-]r?latn", "b+sr+Latn")
+ .replaceFirst("es[_\\-]419", "b+es+419");
+
+ if (!renamedResFolder.equals(resFolder)) {
+ file = Files.copy(
+ file,
+ Files.createDirectory(
+ outputDirectory.resolve(renamedResFolder))
+ .resolve(file.getFileName()));
+ }
+
tasks.add(
executorService.submit(
new CompileTask(
file,
- // Creates a relative output path based on the input path under the
- // compiledResources path.
- Files.createDirectories(
- compiledResources.resolve(
- (file.isAbsolute() ? file.getRoot().relativize(file) : file)
- .getParent()
- .getParent())),
+ outputDirectory,
aapt2,
buildToolsVersion)));
}
diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java
index 9b9285621a..cab46c7186 100644
--- a/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java
+++ b/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java
@@ -258,7 +258,8 @@ public class SimpleXmlResourceValue implements XmlResourceValue {
} else if (resourceType == ResourceType.BOOL && item.hasPrim()) {
stringValue = item.getPrim().getData() == 0 ? "false" : "true";
} else if (resourceType == ResourceType.FRACTION
- || resourceType == ResourceType.DIMEN) {
+ || resourceType == ResourceType.DIMEN
+ || resourceType == ResourceType.STRING) {
stringValue = Integer.toString(item.getPrim().getData());
} else {
throw new IllegalArgumentException(
diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/StyleXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/StyleXmlResourceValue.java
index 0f6369d68b..5cd0f6e0a5 100644
--- a/src/tools/android/java/com/google/devtools/build/android/xml/StyleXmlResourceValue.java
+++ b/src/tools/android/java/com/google/devtools/build/android/xml/StyleXmlResourceValue.java
@@ -75,11 +75,6 @@ public class StyleXmlResourceValue implements XmlResourceValue {
return of(proto.hasValue() ? proto.getValue() : null, proto.getMappedStringValue());
}
- private StyleXmlResourceValue(@Nullable String parent, ImmutableMap<String, String> values) {
- this.parent = parent;
- this.values = values;
- }
-
public static XmlResourceValue from(Value proto) {
Style style = proto.getCompoundValue().getStyle();
String parent = "";
@@ -87,7 +82,7 @@ public class StyleXmlResourceValue implements XmlResourceValue {
if (style.hasParent()) {
parent = proto.getCompoundValue().getStyle().getParent().getName();
if (parent.startsWith("style/")) {
- //Aapt2 compile breaks when style parent references are prepended with 'style/'
+ // Aapt2 compile breaks when style parent references are prepended with 'style/'
parent = parent.substring(6);
}
}
@@ -97,6 +92,11 @@ public class StyleXmlResourceValue implements XmlResourceValue {
return of(parent, items);
}
+ private StyleXmlResourceValue(@Nullable String parent, ImmutableMap<String, String> values) {
+ this.parent = parent;
+ this.values = values;
+ }
+
private static Map<String, String> itemMapFromProto(Style style) {
Map<String, String> result = new HashMap<>();
@@ -112,7 +112,7 @@ public class StyleXmlResourceValue implements XmlResourceValue {
itemValue = "@null";
}
} else {
- throw new IllegalArgumentException("Could not parse item value from Style resource.");
+ itemValue = styleEntry.getItem().getStr().getValue();
}
result.put(itemName, itemValue);
}