aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainerConverter.java
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2017-09-14 21:44:08 +0200
committerGravatar Philipp Wollermann <philwo@google.com>2017-09-15 11:28:33 +0200
commitf38b433bf5d311a5bd914b8ef7ea497fd3b09941 (patch)
treed6b1049804c9f95271f34fc6ac0c19abe6b9f2d9 /src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainerConverter.java
parentd9b141def7aa7737dc09d5c490222c101630df77 (diff)
Do not flatten resource artifacts in Android rules.
This involves rather tediously rolling up each artifact type in its own individual nested set. PiperOrigin-RevId: 168729120
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.java88
1 files changed, 12 insertions, 76 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 16a8c2845a..22037439d4 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
@@ -18,17 +18,11 @@ 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.Iterators;
-import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.VectorArg;
-import com.google.devtools.build.lib.collect.nestedset.NestedSet;
-import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.rules.android.ResourceContainer.ResourceType;
-import javax.annotation.Nullable;
/**
* Factory for functions to convert a {@link ResourceContainer} to a commandline argument, or a
@@ -47,10 +41,6 @@ public class ResourceContainerConverter {
String listSeparator();
}
- interface ToArtifacts extends Function<ResourceContainer, NestedSet<Artifact>> {
-
- }
-
static class Builder {
private boolean includeResourceRoots;
@@ -183,41 +173,6 @@ public class ResourceContainerConverter {
}
};
}
-
- ToArtifacts toArtifactConverter() {
- return new ToArtifacts() {
- @Override
- public NestedSet<Artifact> apply(ResourceContainer container) {
- NestedSetBuilder<Artifact> artifacts = NestedSetBuilder.naiveLinkOrder();
- if (includeResourceRoots) {
- artifacts.addAll(container.getArtifacts());
- }
- if (includeManifest) {
- addIfNotNull(container.getManifest(), artifacts);
- }
- if (includeRTxt) {
- addIfNotNull(container.getRTxt(), artifacts);
- }
- if (includeSymbolsBin) {
- addIfNotNull(container.getSymbols(), artifacts);
- }
- if (includeAapt2RTxt) {
- addIfNotNull(container.getAapt2RTxt(), artifacts);
- }
- if (includeStaticLibrary) {
- addIfNotNull(container.getStaticLibrary(), artifacts);
- }
- return artifacts.build();
- }
- };
- }
- }
-
- private static void addIfNotNull(
- @Nullable Artifact artifact, NestedSetBuilder<Artifact> artifacts) {
- if (artifact != null) {
- artifacts.add(artifact);
- }
}
@VisibleForTesting
@@ -232,36 +187,17 @@ public class ResourceContainerConverter {
* Convert ResourceDependencies to commandline args and artifacts, assuming the commandline
* arguments should be split into direct deps and transitive deps.
*/
- static void convertDependencies(
- ResourceDependencies dependencies,
- CustomCommandLine.Builder cmdBuilder,
- NestedSetBuilder<Artifact> inputs,
- ToArg toArg,
- ToArtifacts toArtifacts) {
-
- if (dependencies != null) {
- if (!dependencies.getTransitiveResources().isEmpty()) {
- cmdBuilder.addAll(
- "--data",
- VectorArg.join(toArg.listSeparator())
- .each(dependencies.getTransitiveResources())
- .mapped(toArg));
- }
- if (!dependencies.getDirectResources().isEmpty()) {
- cmdBuilder.addAll(
- "--directData",
- VectorArg.join(toArg.listSeparator())
- .each(dependencies.getDirectResources())
- .mapped(toArg));
- }
- // This flattens the nested set. Since each ResourceContainer needs to be transformed into
- // Artifacts, and the NestedSetBuilder.wrap doesn't support lazy Iterator evaluation
- // and SpawnActionBuilder.addInputs evaluates Iterables, it becomes necessary to make the
- // best effort and let it get flattened.
- inputs.addTransitive(
- NestedSetBuilder.wrap(
- Order.NAIVE_LINK_ORDER,
- FluentIterable.from(dependencies.getResources()).transformAndConcat(toArtifacts)));
- }
+ static void addToCommandLine(
+ ResourceDependencies dependencies, CustomCommandLine.Builder cmdBuilder, ToArg toArg) {
+ cmdBuilder.addAll(
+ "--data",
+ VectorArg.join(toArg.listSeparator())
+ .each(dependencies.getTransitiveResources())
+ .mapped(toArg));
+ cmdBuilder.addAll(
+ "--directData",
+ VectorArg.join(toArg.listSeparator())
+ .each(dependencies.getDirectResources())
+ .mapped(toArg));
}
}