diff options
author | corysmith <corysmith@google.com> | 2018-07-31 09:28:07 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-07-31 09:29:56 -0700 |
commit | 0a635c5236ce30ea84b765ce752267992733a649 (patch) | |
tree | 7d12075435331b820bfe88f4efbee69dbcbcd7c2 /src/tools/android/java/com/google/devtools/build/android/Aapt2ResourceShrinkingAction.java | |
parent | a0f77be2887cc69ea43991dfb5a58934eb539c65 (diff) |
Automated rollback of commit 8fe0f45852a620a078013310989396caed273342.
*** Reason for rollback ***
Breaks a couple of builds due to a bad merge.
*** Original change description ***
Add apk converted to proto and all attributes from CompiledResources to ResourcesZip.
Add new proto format for tool attributes stored in the AndroidDataXml for storing them in the resources.zip.
RELNOTES:None
PiperOrigin-RevId: 206774364
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/Aapt2ResourceShrinkingAction.java')
-rw-r--r-- | src/tools/android/java/com/google/devtools/build/android/Aapt2ResourceShrinkingAction.java | 127 |
1 files changed, 45 insertions, 82 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/Aapt2ResourceShrinkingAction.java b/src/tools/android/java/com/google/devtools/build/android/Aapt2ResourceShrinkingAction.java index 8d1be26dab..af2a98ab2f 100644 --- a/src/tools/android/java/com/google/devtools/build/android/Aapt2ResourceShrinkingAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/Aapt2ResourceShrinkingAction.java @@ -25,16 +25,12 @@ import com.google.devtools.build.android.aapt2.CompiledResources; import com.google.devtools.build.android.aapt2.ResourceCompiler; import com.google.devtools.build.android.aapt2.ResourceLinker; import com.google.devtools.build.android.aapt2.StaticLibrary; -import com.google.devtools.common.options.Option; -import com.google.devtools.common.options.OptionDocumentationCategory; -import com.google.devtools.common.options.OptionEffectTag; -import com.google.devtools.common.options.OptionsBase; import com.google.devtools.common.options.OptionsParser; import com.google.devtools.common.options.ShellQuotedParamsFilePreProcessor; +import java.io.Closeable; import java.io.File; import java.nio.file.FileSystems; import java.nio.file.Path; -import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.function.Function; @@ -57,101 +53,68 @@ import java.util.function.Function; */ public class Aapt2ResourceShrinkingAction { - /** Aapt2 shrinking specific options */ - public static final class Aapt2ShrinkOptions extends OptionsBase { - @Option( - name = "useProtoApk", - defaultValue = "false", - category = "config", - documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, - effectTags = {OptionEffectTag.UNKNOWN}, - help = "Path to the shrunk jar from a Proguard run with shrinking enabled.") - public boolean useProtoApk; - } - public static void main(String[] args) throws Exception { final Profiler profiler = LoggingProfiler.createAndStart("shrink").startTask("flags"); // Parse arguments. OptionsParser optionsParser = - OptionsParser.newOptionsParser( - ImmutableList.of(Options.class, Aapt2ConfigOptions.class, Aapt2ShrinkOptions.class)); + OptionsParser.newOptionsParser(Options.class, Aapt2ConfigOptions.class); optionsParser.enableParamsFileSupport( new ShellQuotedParamsFilePreProcessor(FileSystems.getDefault())); optionsParser.parseAndExitUponError(args); Aapt2ConfigOptions aapt2ConfigOptions = optionsParser.getOptions(Aapt2ConfigOptions.class); Options options = optionsParser.getOptions(Options.class); - Aapt2ShrinkOptions aapt2ShrinkOptions = optionsParser.getOptions(Aapt2ShrinkOptions.class); profiler.recordEndOf("flags").startTask("setup"); + final ListeningExecutorService executorService = ExecutorServiceCloser.createDefaultService(); try (ScopedTemporaryDirectory scopedTmp = new ScopedTemporaryDirectory("android_resources_tmp"); - ExecutorServiceCloser executorService = ExecutorServiceCloser.createWithFixedPoolOf(15)) { + Closeable closer = ExecutorServiceCloser.createWith(executorService)) { + + Path workingResourcesDirectory = scopedTmp.subDirectoryOf("resources"); + final ResourceCompiler resourceCompiler = + ResourceCompiler.create( + executorService, + workingResourcesDirectory, + aapt2ConfigOptions.aapt2, + aapt2ConfigOptions.buildToolsVersion, + aapt2ConfigOptions.generatePseudoLocale); + profiler.recordEndOf("setup").startTask("compile"); final ResourcesZip resourcesZip = ResourcesZip.createFrom( options.resourcesZip, scopedTmp.subDirectoryOf("merged-resources")); - Path workingResourcesDirectory = scopedTmp.subDirectoryOf("resources"); - final ResourceLinker linker = - ResourceLinker.create( - aapt2ConfigOptions.aapt2, executorService, scopedTmp.subDirectoryOf("linking")) - .profileUsing(profiler); - - final Set<String> packages = - options - .dependencyManifests - .stream() - .map(Path::toFile) - .map(manifestToPackageUsing(executorService)) - .map(futureToString()) - .collect(toSet()); + final CompiledResources compiled = + resourcesZip + .shrink( + options + .dependencyManifests + .stream() + .map(Path::toFile) + .map(manifestToPackageUsing(executorService)) + .map(futureToString()) + .collect(toSet()), + options.rTxt, + options.shrunkJar, + options.primaryManifest, + options.proguardMapping, + options.log, + scopedTmp.subDirectoryOf("shrunk-resources")) + .writeArchiveTo(options.shrunkResources, false) + .compile(resourceCompiler, workingResourcesDirectory); + profiler.recordEndOf("compile"); - if (aapt2ShrinkOptions.useProtoApk) { - resourcesZip - .shrinkUsingProto( - packages, - options.rTxt, - options.shrunkJar, - options.primaryManifest, - options.proguardMapping, - options.log, - scopedTmp.subDirectoryOf("shrunk-resources")) - .writeBinaryTo(linker, options.shrunkApk) - .writeReportTo(options.log) - .writeResourceToZip(options.shrunkResources); - } else { - final ResourceCompiler resourceCompiler = - ResourceCompiler.create( - executorService, - workingResourcesDirectory, - aapt2ConfigOptions.aapt2, - aapt2ConfigOptions.buildToolsVersion, - aapt2ConfigOptions.generatePseudoLocale); - profiler.recordEndOf("setup").startTask("compile"); - - final CompiledResources compiled = - resourcesZip - .shrink( - packages, - options.rTxt, - options.shrunkJar, - options.primaryManifest, - options.proguardMapping, - options.log, - scopedTmp.subDirectoryOf("shrunk-resources")) - .writeArchiveTo(options.shrunkResources, false) - .compile(resourceCompiler, workingResourcesDirectory); - profiler.recordEndOf("compile"); - linker - .dependencies(ImmutableList.of(StaticLibrary.from(aapt2ConfigOptions.androidJar))) - .profileUsing(profiler) - .outputAsProto(aapt2ConfigOptions.resourceTableAsProto) - .buildVersion(aapt2ConfigOptions.buildToolsVersion) - .includeOnlyConfigs(aapt2ConfigOptions.resourceConfigs) - .debug(aapt2ConfigOptions.debug) - .link(compiled) - .copyPackageTo(options.shrunkApk) - .copyRTxtTo(options.rTxtOutput); - } + ResourceLinker.create( + aapt2ConfigOptions.aapt2, executorService, scopedTmp.subDirectoryOf("linking")) + .profileUsing(profiler) + .dependencies(ImmutableList.of(StaticLibrary.from(aapt2ConfigOptions.androidJar))) + .profileUsing(profiler) + .outputAsProto(aapt2ConfigOptions.resourceTableAsProto) + .buildVersion(aapt2ConfigOptions.buildToolsVersion) + .includeOnlyConfigs(aapt2ConfigOptions.resourceConfigs) + .debug(aapt2ConfigOptions.debug) + .link(compiled) + .copyPackageTo(options.shrunkApk) + .copyRTxtTo(options.rTxtOutput); profiler.recordEndOf("shrink"); } } |