From 1f1f207573c7b9c3e2d3ca1ffb0780a8fd592214 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 20 Jun 2016 22:08:17 +0000 Subject: Add action to write android_binary and lib R.classes directly For android_binary rules, we regenerate all of the R.java of the libraries to get the final resource IDs. Compiling all of them together can be slow with the normal JavaBuilder, so add a specialized class writer. Example build with many R.java classes: - R.java -> R.class via JavaBuilder: over 80s - ErrorProne takes about 40% of that. So turning off ErrorProne would be projected to be 48s. Some of ErrorProne slowness is from static field checks (e.g., on Flag classes), which may look up the same Type over and over. In comparison, if we write our own bytecode with ASM: - ~16s total - 4.7s to parse R.txt - 4.8s to write class files - 5.8s to copy and compress .jar TODO: clean up SymbolLoader patching (upstream) This only creates the action. We will need to separately wire this up in blaze. NOTE: This also makes the exising R.txt loading used by live code multi-threaded, since that is partly I/O-bound. Something to watch out for (for flakiness, etc.) once this is submitted. -- MOS_MIGRATED_REVID=125384467 --- .../google/devtools/build/android/ResourceShrinkerAction.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/tools/android/java/com/google/devtools/build/android/ResourceShrinkerAction.java') diff --git a/src/tools/android/java/com/google/devtools/build/android/ResourceShrinkerAction.java b/src/tools/android/java/com/google/devtools/build/android/ResourceShrinkerAction.java index 69317a135b..7846844273 100644 --- a/src/tools/android/java/com/google/devtools/build/android/ResourceShrinkerAction.java +++ b/src/tools/android/java/com/google/devtools/build/android/ResourceShrinkerAction.java @@ -160,11 +160,10 @@ public class ResourceShrinkerAction { options = optionsParser.getOptions(Options.class); AndroidResourceProcessor resourceProcessor = new AndroidResourceProcessor(stdLogger); - try { - // Setup temporary working directories. - Path working = Files.createTempDirectory("resource_shrinker_tmp"); - working.toFile().deleteOnExit(); - + // Setup temporary working directories. + try (ScopedTemporaryDirectory scopedTmp = + new ScopedTemporaryDirectory("resource_shrinker_tmp")) { + Path working = scopedTmp.getPath(); final Path resourceFiles = working.resolve("resource_files"); final Path shrunkResources = working.resolve("shrunk_resources"); -- cgit v1.2.3