From f38b433bf5d311a5bd914b8ef7ea497fd3b09941 Mon Sep 17 00:00:00 2001 From: tomlu Date: Thu, 14 Sep 2017 21:44:08 +0200 Subject: 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 --- .../rules/android/ResourceContainerConverter.java | 88 +++------------------- 1 file changed, 12 insertions(+), 76 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainerConverter.java') 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> { - - } - static class Builder { private boolean includeResourceRoots; @@ -183,41 +173,6 @@ public class ResourceContainerConverter { } }; } - - ToArtifacts toArtifactConverter() { - return new ToArtifacts() { - @Override - public NestedSet apply(ResourceContainer container) { - NestedSetBuilder 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 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 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)); } } -- cgit v1.2.3