aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainerConverter.java
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2016-08-29 17:06:53 +0000
committerGravatar Klaus Aehlig <aehlig@google.com>2016-08-30 08:32:45 +0000
commit5963ae7407f32cf25ebbe7e046f5bc5d0240aae3 (patch)
tree99a600b92832aaa12d52ee46b05ed1045ff60261 /src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainerConverter.java
parent012b06b0a89ae76e623f8844da3a787841da757c (diff)
Add a lightweight resource merge action.
Part 2 of the 3 new proposed android_library res processing actions. The primary and deps are all assumed to be parsed+summarized in a protobuf. Represent that with a new class (similar to DependencyAndroidData but w/out R.txt). Avoid having "manifest" artifacts as deps input, and instead use "label", since that is only used in a warning. DepAD still uses the manifest for #asSymbolFileProvider, so we keep it there. Move loading the primary out of the merge function so that we can share the merge function with this style of primary data, and the existing style of of primary data (UnvalidatedAndroidData). This produces an R class.jar and a zip file to pass along to a future validation action. Images are stubbed out since they are irrelevant to the validation action. -- MOS_MIGRATED_REVID=131604421
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainerConverter.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainerConverter.java77
1 files changed, 70 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainerConverter.java b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainerConverter.java
index b271e90861..d86ada91c5 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainerConverter.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainerConverter.java
@@ -17,6 +17,7 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
@@ -42,24 +43,44 @@ public class ResourceContainerConverter {
return new Builder();
}
- interface ToArg extends Function<ResourceContainer, String> {}
+ interface ToArg extends Function<ResourceContainer, String> {
- interface ToArtifacts extends Function<ResourceContainer, NestedSet<Artifact>> {}
+ String listSeparator();
+ }
+
+ interface ToArtifacts extends Function<ResourceContainer, NestedSet<Artifact>> {
+
+ }
static class Builder {
private boolean includeResourceRoots;
+ private boolean includeLabel;
private boolean includeManifest;
private boolean includeRTxt;
private boolean includeSymbolsBin;
+ private SeparatorType separatorType;
+ private Joiner argJoiner;
+ private Function<String, String> escaper = Functions.identity();
+
+ enum SeparatorType {
+ COLON_COMMA,
+ SEMICOLON_AMPERSAND
+ }
- Builder() {}
+ Builder() {
+ }
Builder includeResourceRoots() {
includeResourceRoots = true;
return this;
}
+ Builder includeLabel() {
+ includeLabel = true;
+ return this;
+ }
+
Builder includeManifest() {
includeManifest = true;
return this;
@@ -75,9 +96,35 @@ public class ResourceContainerConverter {
return this;
}
- private static final Joiner ARG_JOINER = Joiner.on(":");
+ Builder withSeparator(SeparatorType type) {
+ separatorType = type;
+ return this;
+ }
ToArg toArgConverter() {
+ switch (separatorType) {
+ case COLON_COMMA:
+ argJoiner = Joiner.on(":");
+ // We currently use ":" to separate components of an argument and "," to separate
+ // arguments in a list of arguments. Those characters require escaping if used in a label
+ // (part of the set of allowed characters in a label).
+ if (includeLabel) {
+ escaper = new Function<String, String>() {
+ @Override
+ public String apply(String input) {
+ return input.replace(":", "\\:").replace(",", "\\,");
+ }
+ };
+ }
+ break;
+ case SEMICOLON_AMPERSAND:
+ argJoiner = Joiner.on(";");
+ break;
+ default:
+ Preconditions.checkState(false, "Unknown separator type " + separatorType);
+ break;
+ }
+
return new ToArg() {
@Override
public String apply(ResourceContainer container) {
@@ -86,6 +133,9 @@ public class ResourceContainerConverter {
cmdPieces.add(convertRoots(container, ResourceType.RESOURCES));
cmdPieces.add(convertRoots(container, ResourceType.ASSETS));
}
+ if (includeLabel) {
+ cmdPieces.add(escaper.apply(container.getLabel().toString()));
+ }
if (includeManifest) {
cmdPieces.add(container.getManifest().getExecPathString());
}
@@ -99,7 +149,20 @@ public class ResourceContainerConverter {
? ""
: container.getSymbolsTxt().getExecPathString());
}
- return ARG_JOINER.join(cmdPieces.build());
+ return argJoiner.join(cmdPieces.build());
+ }
+
+ @Override
+ public String listSeparator() {
+ switch (separatorType) {
+ case COLON_COMMA:
+ return ",";
+ case SEMICOLON_AMPERSAND:
+ return "&";
+ default:
+ Preconditions.checkState(false, "Unknown separator type " + separatorType);
+ return null;
+ }
}
};
}
@@ -161,7 +224,7 @@ public class ResourceContainerConverter {
if (!dependencies.getTransitiveResources().isEmpty()) {
cmdBuilder.addJoinStrings(
"--data",
- ",",
+ toArg.listSeparator(),
Iterables.unmodifiableIterable(
Iterables.transform(dependencies.getTransitiveResources(), toArg)));
}
@@ -170,7 +233,7 @@ public class ResourceContainerConverter {
if (!dependencies.getDirectResources().isEmpty()) {
cmdBuilder.addJoinStrings(
"--directData",
- ",",
+ toArg.listSeparator(),
Iterables.unmodifiableIterable(
Iterables.transform(dependencies.getDirectResources(), toArg)));
}