diff options
Diffstat (limited to 'src')
5 files changed, 121 insertions, 33 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/Aapt2ResourcePackagingAction.java b/src/tools/android/java/com/google/devtools/build/android/Aapt2ResourcePackagingAction.java index 408f7314e6..83b628cd9e 100644 --- a/src/tools/android/java/com/google/devtools/build/android/Aapt2ResourcePackagingAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/Aapt2ResourcePackagingAction.java @@ -18,7 +18,6 @@ import static java.util.stream.Collectors.toList; import com.android.utils.StdLogger; import com.google.common.collect.ImmutableList; -import com.google.common.util.concurrent.ListeningExecutorService; import com.google.devtools.build.android.AndroidResourceProcessingAction.Options; import com.google.devtools.build.android.aapt2.Aapt2ConfigOptions; import com.google.devtools.build.android.aapt2.CompiledResources; @@ -29,7 +28,6 @@ import com.google.devtools.build.android.aapt2.StaticLibrary; import com.google.devtools.common.options.OptionsParser; import com.google.devtools.common.options.ShellQuotedParamsFilePreProcessor; import com.google.devtools.common.options.TriState; -import java.io.Closeable; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; @@ -73,7 +71,8 @@ public class Aapt2ResourcePackagingAction { options = optionsParser.getOptions(Options.class); try (ScopedTemporaryDirectory scopedTmp = - new ScopedTemporaryDirectory("android_resources_tmp")) { + new ScopedTemporaryDirectory("android_resources_tmp"); + ExecutorServiceCloser executorService = ExecutorServiceCloser.createWithFixedPoolOf(15)) { final Path tmp = scopedTmp.getPath(); final Path mergedAssets = tmp.resolve("merged_assets"); final Path mergedResources = tmp.resolve("merged_resources"); @@ -87,10 +86,15 @@ public class Aapt2ResourcePackagingAction { final Path compiledResources = Files.createDirectories(tmp.resolve("compiled")); final Path linkedOut = Files.createDirectories(tmp.resolve("linked")); - - // TODO(b/72995408): Remove the densitiesForManifest option once it is no longer being passed. - final List<String> densities = - options.densities.isEmpty() ? options.densitiesForManifest : options.densities; + final List<String> densities; + if (options.densities.isEmpty()) { + // aapt2 always needs to filter on densities, as the resource filtering from analysis is + // disregarded. + // TODO(b/70335064): Remove this once we never filter in analysis when building for aapt2. + densities = options.densitiesForManifest; + } else { + densities = options.densities; + } profiler.recordEndOf("setup").startTask("merging"); @@ -113,15 +117,15 @@ public class Aapt2ResourcePackagingAction { options.symbolsOut, null /* rclassWriter */, dataDeserializer, - options.throwOnResourceConflict) + options.throwOnResourceConflict, + executorService) .filter( new DensitySpecificResourceFilter(densities, filteredResources, mergedResources), new DensitySpecificManifestProcessor(densities, densityManifest)); profiler.recordEndOf("merging"); - final ListeningExecutorService executorService = ExecutorServiceCloser.createDefaultService(); - try (final Closeable closeable = ExecutorServiceCloser.createWith(executorService)) { + profiler.startTask("compile"); final ResourceCompiler compiler = ResourceCompiler.create( @@ -201,5 +205,3 @@ public class Aapt2ResourcePackagingAction { } } } - -} diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledResourceMergingAction.java b/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledResourceMergingAction.java index 155d7b39d7..3fe61a32df 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledResourceMergingAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledResourceMergingAction.java @@ -61,7 +61,8 @@ public class AndroidCompiledResourceMergingAction { Preconditions.checkNotNull(options.classJarOutput); try (ScopedTemporaryDirectory scopedTmp = - new ScopedTemporaryDirectory("android_resource_merge_tmp")) { + new ScopedTemporaryDirectory("android_resource_merge_tmp"); + ExecutorServiceCloser executorService = ExecutorServiceCloser.createWithFixedPoolOf(15)) { Path tmp = scopedTmp.getPath(); Path generatedSources = tmp.resolve("generated_resources"); Path processedManifest = tmp.resolve("manifest-processed/AndroidManifest.xml"); @@ -86,7 +87,8 @@ public class AndroidCompiledResourceMergingAction { options.directData, options.transitiveData, resourceClassWriter, - options.throwOnResourceConflict); + options.throwOnResourceConflict, + executorService); logger.fine(String.format("Merging finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS))); AndroidResourceOutputs.createClassJar(generatedSources, options.classJarOutput); diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceMerger.java b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceMerger.java index 1257def88a..a6e97b9161 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceMerger.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceMerger.java @@ -18,12 +18,9 @@ import com.android.builder.core.VariantType; import com.android.ide.common.internal.PngCruncher; import com.google.common.base.Stopwatch; import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; -import java.io.Closeable; import java.io.IOException; import java.nio.file.Path; import java.util.List; -import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; @@ -65,11 +62,10 @@ public class AndroidResourceMerger { @Nullable final Path symbolsOut, @Nullable AndroidResourceClassWriter rclassWriter, AndroidDataDeserializer deserializer, - boolean throwOnResourceConflict) { + boolean throwOnResourceConflict, + ListeningExecutorService executorService) { Stopwatch timer = Stopwatch.createStarted(); - final ListeningExecutorService executorService = - MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(15)); - try (Closeable closeable = ExecutorServiceCloser.createWith(executorService)) { + try { UnwrittenMergedAndroidData merged = mergeData( executorService, @@ -148,7 +144,7 @@ public class AndroidResourceMerger { @Nullable final Path symbolsOut, final List<String> filteredResources, boolean throwOnResourceConflict) { - try { + try (ExecutorServiceCloser executorService = ExecutorServiceCloser.createWithFixedPoolOf(15)) { final ParsedAndroidData parsedPrimary = ParsedAndroidData.from(primary); return mergeData( parsedPrimary, @@ -162,7 +158,8 @@ public class AndroidResourceMerger { symbolsOut, null /* rclassWriter */, AndroidParsedDataDeserializer.withFilteredResources(filteredResources), - throwOnResourceConflict); + throwOnResourceConflict, + executorService); } catch (IOException e) { throw MergingException.wrapException(e); } @@ -183,7 +180,8 @@ public class AndroidResourceMerger { final VariantType type, @Nullable final Path symbolsOut, @Nullable final AndroidResourceClassWriter rclassWriter, - boolean throwOnResourceConflict) { + boolean throwOnResourceConflict, + ListeningExecutorService executorService) { final ParsedAndroidData.Builder primaryBuilder = ParsedAndroidData.Builder.newBuilder(); final AndroidDataDeserializer deserializer = AndroidParsedDataDeserializer.create(); primary.deserialize(deserializer, primaryBuilder.consumers()); @@ -200,7 +198,8 @@ public class AndroidResourceMerger { symbolsOut, rclassWriter, deserializer, - throwOnResourceConflict); + throwOnResourceConflict, + executorService); } /** @@ -213,15 +212,14 @@ public class AndroidResourceMerger { final List<? extends SerializedAndroidData> direct, final List<? extends SerializedAndroidData> transitive, @Nullable final AndroidResourceClassWriter rclassWriter, - boolean throwOnResourceConflict) { + boolean throwOnResourceConflict, + ListeningExecutorService executorService) { final ParsedAndroidData.Builder primaryBuilder = ParsedAndroidData.Builder.newBuilder(); final AndroidDataDeserializer deserializer = AndroidCompiledDataDeserializer.create(); primary.deserialize(deserializer, primaryBuilder.consumers()); ParsedAndroidData primaryData = primaryBuilder.build(); - Stopwatch timer = Stopwatch.createStarted(); - final ListeningExecutorService executorService = ExecutorServiceCloser.createDefaultService(); - try (Closeable closeable = ExecutorServiceCloser.createWith(executorService)) { + try { UnwrittenMergedAndroidData merged = mergeData( executorService, diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceMergingAction.java b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceMergingAction.java index ceda631537..c67806088f 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceMergingAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceMergingAction.java @@ -209,7 +209,8 @@ public class AndroidResourceMergingAction { Preconditions.checkNotNull(options.primaryManifest); try (ScopedTemporaryDirectory scopedTmp = - new ScopedTemporaryDirectory("android_resource_merge_tmp")) { + new ScopedTemporaryDirectory("android_resource_merge_tmp"); + ExecutorServiceCloser executorService = ExecutorServiceCloser.createWithFixedPoolOf(15)) { Path tmp = scopedTmp.getPath(); Path mergedAssets = tmp.resolve("merged_assets"); Path mergedResources = tmp.resolve("merged_resources"); @@ -243,7 +244,8 @@ public class AndroidResourceMergingAction { packageType, options.symbolsBinOut, resourceClassWriter, - options.throwOnResourceConflict); + options.throwOnResourceConflict, + executorService); logger.fine(String.format("Merging finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS))); diff --git a/src/tools/android/java/com/google/devtools/build/android/ExecutorServiceCloser.java b/src/tools/android/java/com/google/devtools/build/android/ExecutorServiceCloser.java index 24d7739782..0384f9f619 100644 --- a/src/tools/android/java/com/google/devtools/build/android/ExecutorServiceCloser.java +++ b/src/tools/android/java/com/google/devtools/build/android/ExecutorServiceCloser.java @@ -13,15 +13,22 @@ // limitations under the License. package com.google.devtools.build.android; +import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; import java.io.Closeable; import java.io.IOException; +import java.util.Collection; import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; /** Shutdowns and verifies that no tasks are running in the executor service. */ -final class ExecutorServiceCloser implements Closeable { +final class ExecutorServiceCloser implements Closeable, ListeningExecutorService { private final ListeningExecutorService executorService; private ExecutorServiceCloser(ListeningExecutorService executorService) { @@ -37,7 +44,12 @@ final class ExecutorServiceCloser implements Closeable { } } - public static Closeable createWith(ListeningExecutorService executorService) { + public static ExecutorServiceCloser createWithFixedPoolOf(int numThreads) { + return new ExecutorServiceCloser( + MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numThreads))); + } + + public static ExecutorServiceCloser createWith(ListeningExecutorService executorService) { return new ExecutorServiceCloser(executorService); } @@ -54,4 +66,76 @@ final class ExecutorServiceCloser implements Closeable { MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numThreads)); return executorService; } + + // Delegate methods below + + @Override + public <T> ListenableFuture<T> submit(Callable<T> task) { + return executorService.submit(task); + } + + @Override + public ListenableFuture<?> submit(Runnable task) { + return executorService.submit(task); + } + + @Override + public <T> ListenableFuture<T> submit(Runnable task, T result) { + return executorService.submit(task, result); + } + + @Override + public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) + throws InterruptedException { + return executorService.invokeAll(tasks); + } + + @Override + public <T> List<Future<T>> invokeAll( + Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) + throws InterruptedException { + return executorService.invokeAll(tasks, timeout, unit); + } + + @Override + public void shutdown() { + executorService.shutdown(); + } + + @Override + public List<Runnable> shutdownNow() { + return executorService.shutdownNow(); + } + + @Override + public boolean isShutdown() { + return executorService.isShutdown(); + } + + @Override + public boolean isTerminated() { + return executorService.isTerminated(); + } + + @Override + public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { + return executorService.awaitTermination(timeout, unit); + } + + @Override + public <T> T invokeAny(Collection<? extends Callable<T>> tasks) + throws InterruptedException, ExecutionException { + return executorService.invokeAny(tasks); + } + + @Override + public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) + throws InterruptedException, ExecutionException, TimeoutException { + return executorService.invokeAny(tasks, timeout, unit); + } + + @Override + public void execute(Runnable command) { + executorService.execute(command); + } } |