diff options
author | Benoit Lamarche <benoitlamarche@google.com> | 2015-05-29 12:57:12 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-05-29 12:57:13 +0000 |
commit | 49ff78ab658d73b7647af2df12465ab02f0f5773 (patch) | |
tree | 78590d0c2a6f8ec1ab8608925ea642322dbf9330 | |
parent | 623c827ba2f55a54bf40fbc3ce0ed10e5f38954a (diff) | |
parent | edfcedaf3de656690374ae7c56e74235d406298b (diff) | |
download | toolchain_jack-49ff78ab658d73b7647af2df12465ab02f0f5773.zip toolchain_jack-49ff78ab658d73b7647af2df12465ab02f0f5773.tar.gz toolchain_jack-49ff78ab658d73b7647af2df12465ab02f0f5773.tar.bz2 |
Merge "Always close the Jack output library" into ub-jack-brest
5 files changed, 179 insertions, 153 deletions
diff --git a/jack/src/com/android/jack/Jack.java b/jack/src/com/android/jack/Jack.java index 0bf5664..cbc3d11 100644 --- a/jack/src/com/android/jack/Jack.java +++ b/jack/src/com/android/jack/Jack.java @@ -91,7 +91,6 @@ import com.android.jack.library.InputJackLibrary; import com.android.jack.library.InputLibrary; import com.android.jack.library.LibraryIOException; import com.android.jack.library.LibraryReadingException; -import com.android.jack.library.OutputLibrary; import com.android.jack.lookup.CommonTypes; import com.android.jack.lookup.JPhantomLookup; import com.android.jack.meta.LibraryMetaWriter; @@ -431,184 +430,187 @@ public abstract class Jack { ConfigPrinterFactory.getConfigPrinter().printConfig(config); - JSession session = buildSession(options, hooks); + JSession session = getSession(); - if (config.get(Options.GENERATE_JACK_LIBRARY).booleanValue()) { - session.setJackOutputLibrary(session.getInputFilter().getOutputJackLibrary()); - } - - Request request = createInitialRequest(); - request.addFeature(PreProcessor.class); - - request.addFeature(Resources.class); + try { + buildSession(session, options, hooks); - JavaVersion sourceVersion = config.get(Options.JAVA_SOURCE_VERSION); - if (sourceVersion.compareTo(JavaVersion.JAVA_7) >= 0) { - request.addFeature(SourceVersion7.class); - } + if (config.get(Options.GENERATE_JACK_LIBRARY).booleanValue()) { + session.setJackOutputLibrary(session.getInputFilter().getOutputJackLibrary()); + } - if (config.get(Options.DROP_METHOD_BODY).booleanValue()) { - request.addFeature(DropMethodBody.class); - } + Request request = createInitialRequest(); + request.addFeature(PreProcessor.class); - if (config.get(Options.ENABLE_COMPILED_FILES_STATISTICS).booleanValue()) { - request.addFeature(CompiledTypeStats.class); - request.addFeature(CodeStats.class); - } + request.addFeature(Resources.class); - if (config.get(Options.SANITY_CHECKS).booleanValue()) { - request.addFeature(SanityChecks.class); - } - if (config.get(PackageRenamer.JARJAR_ENABLED).booleanValue()) { - request.addFeature(Jarjar.class); - } - if (config.get(VisibilityBridgeAdder.VISIBILITY_BRIDGE).booleanValue()) { - request.addFeature(VisibilityBridge.class); - } - if (options.flags != null) { - if (options.flags.shrink()) { - request.addFeature(Shrinking.class); - } - if (options.flags.obfuscate()) { - request.addFeature(Obfuscation.class); - } - if (options.flags.printSeeds()) { - request.addProduction(SeedFile.class); + JavaVersion sourceVersion = config.get(Options.JAVA_SOURCE_VERSION); + if (sourceVersion.compareTo(JavaVersion.JAVA_7) >= 0) { + request.addFeature(SourceVersion7.class); } - if (!options.flags.keepAttribute("EnclosingMethod")) { - request.addFeature(RemoveEnclosingMethod.class); + + if (config.get(Options.DROP_METHOD_BODY).booleanValue()) { + request.addFeature(DropMethodBody.class); } - if (!options.flags.keepAttribute("InnerClasses")) { - request.addFeature(RemoveEnclosingType.class); + + if (config.get(Options.ENABLE_COMPILED_FILES_STATISTICS).booleanValue()) { + request.addFeature(CompiledTypeStats.class); + request.addFeature(CodeStats.class); } - if (!options.flags.keepAttribute("Signature")) { - request.addFeature(RemoveGenericSignature.class); + + if (config.get(Options.SANITY_CHECKS).booleanValue()) { + request.addFeature(SanityChecks.class); } - if (!options.flags.keepAttribute("AnnotationDefault")) { - request.addFeature(RemoveAnnotationDefaultValue.class); + if (config.get(PackageRenamer.JARJAR_ENABLED).booleanValue()) { + request.addFeature(Jarjar.class); } - if (!options.flags.keepAttribute("LocalVariableTypeTable")) { - request.addFeature(RemoveLocalVariableGenericSignature.class); + if (config.get(VisibilityBridgeAdder.VISIBILITY_BRIDGE).booleanValue()) { + request.addFeature(VisibilityBridge.class); } - if (!options.flags.keepAttribute("Exceptions")) { - request.addFeature(RemoveThrownException.class); + if (options.flags != null) { + if (options.flags.shrink()) { + request.addFeature(Shrinking.class); + } + if (options.flags.obfuscate()) { + request.addFeature(Obfuscation.class); + } + if (options.flags.printSeeds()) { + request.addProduction(SeedFile.class); + } + if (!options.flags.keepAttribute("EnclosingMethod")) { + request.addFeature(RemoveEnclosingMethod.class); + } + if (!options.flags.keepAttribute("InnerClasses")) { + request.addFeature(RemoveEnclosingType.class); + } + if (!options.flags.keepAttribute("Signature")) { + request.addFeature(RemoveGenericSignature.class); + } + if (!options.flags.keepAttribute("AnnotationDefault")) { + request.addFeature(RemoveAnnotationDefaultValue.class); + } + if (!options.flags.keepAttribute("LocalVariableTypeTable")) { + request.addFeature(RemoveLocalVariableGenericSignature.class); + } + if (!options.flags.keepAttribute("Exceptions")) { + request.addFeature(RemoveThrownException.class); + } + if (!options.flags.keepAttribute("SourceFile")) { + request.addFeature(RemoveSourceFile.class); + } + if (!options.flags.keepAttribute("LineNumberTable")) { + request.addFeature(RemoveLineNumber.class); + } + if (!options.flags.getKeepParameterNames()) { + request.addFeature(RemoveParameterName.class); + } + if (options.flags.getRenameSourceFileAttribute() != null) { + request.addFeature(SourceFileRenaming.class); + } + if (options.flags.getAdaptResourceFileContents() != null) { + request.addFeature(AdaptResourceFileContent.class); + } } - if (!options.flags.keepAttribute("SourceFile")) { - request.addFeature(RemoveSourceFile.class); + if (config.get(MappingPrinter.MAPPING_OUTPUT_ENABLED).booleanValue()) { + request.addProduction(Mapping.class); } - if (!options.flags.keepAttribute("LineNumberTable")) { - request.addFeature(RemoveLineNumber.class); + if (config.get(ShrinkStructurePrinter.STRUCTURE_PRINTING).booleanValue()) { + request.addProduction(StructurePrinting.class); } - if (!options.flags.getKeepParameterNames()) { - request.addFeature(RemoveParameterName.class); + if (config.get(MultiDexLegacy.MULTIDEX_LEGACY).booleanValue()) { + request.addFeature(MultiDexLegacy.class); } - if (options.flags.getRenameSourceFileAttribute() != null) { - request.addFeature(SourceFileRenaming.class); + if (config.get(Options.INCREMENTAL_MODE).booleanValue()) { + request.addFeature(Incremental.class); } - if (options.flags.getAdaptResourceFileContents() != null) { - request.addFeature(AdaptResourceFileContent.class); + if (config.get(Options.GENERATE_LIBRARY_FROM_INCREMENTAL_FOLDER).booleanValue()) { + request.addFeature(GenerateLibraryFromIncrementalFolder.class); } - } - if (config.get(MappingPrinter.MAPPING_OUTPUT_ENABLED).booleanValue()) { - request.addProduction(Mapping.class); - } - if (config.get(ShrinkStructurePrinter.STRUCTURE_PRINTING).booleanValue()) { - request.addProduction(StructurePrinting.class); - } - if (config.get(MultiDexLegacy.MULTIDEX_LEGACY).booleanValue()) { - request.addFeature(MultiDexLegacy.class); - } - if (config.get(Options.INCREMENTAL_MODE).booleanValue()) { - request.addFeature(Incremental.class); - } - if (config.get(Options.GENERATE_LIBRARY_FROM_INCREMENTAL_FOLDER).booleanValue()) { - request.addFeature(GenerateLibraryFromIncrementalFolder.class); - } - - request.addInitialTagsOrMarkers(getJavaSourceInitialTagSet()); - request.addInitialTagsOrMarkers(getJackFormatInitialTagSet()); - if (config.get(Options.GENERATE_DEX_IN_LIBRARY).booleanValue()) { - request.addProduction(DexInLibraryProduct.class); - } + request.addInitialTagsOrMarkers(getJavaSourceInitialTagSet()); + request.addInitialTagsOrMarkers(getJackFormatInitialTagSet()); - if (config.get(Options.GENERATE_DEX_FILE).booleanValue()) { - request.addProduction(DexFileProduct.class); - session.addGeneratedFileType(FileType.DEX); - } + if (config.get(Options.GENERATE_DEX_IN_LIBRARY).booleanValue()) { + request.addProduction(DexInLibraryProduct.class); + } - if (config.get(Options.GENERATE_JAYCE_IN_LIBRARY).booleanValue()) { - request.addProduction(JayceInLibraryProduct.class); - } + if (config.get(Options.GENERATE_DEX_FILE).booleanValue()) { + request.addProduction(DexFileProduct.class); + session.addGeneratedFileType(FileType.DEX); + } - if (config.get(Options.GENERATE_DEPENDENCIES_IN_LIBRARY).booleanValue()) { - request.addProduction(DependencyInLibraryProduct.class); - } + if (config.get(Options.GENERATE_JAYCE_IN_LIBRARY).booleanValue()) { + request.addProduction(JayceInLibraryProduct.class); + } - if (config.get(TypeDefRemover.REMOVE_TYPEDEF).booleanValue()) { - request.addFeature(TypeDefRemover.RemoveTypeDef.class); - } + if (config.get(Options.GENERATE_DEPENDENCIES_IN_LIBRARY).booleanValue()) { + request.addProduction(DependencyInLibraryProduct.class); + } - ProductionSet targetProduction = request.getTargetProductions(); - FeatureSet features = request.getFeatures(); - PlanBuilder<JSession> planBuilder; - try { - planBuilder = request.getPlanBuilder(JSession.class); - } catch (IllegalRequestException e) { - throw new AssertionError(e); - } + if (config.get(TypeDefRemover.REMOVE_TYPEDEF).booleanValue()) { + request.addFeature(TypeDefRemover.RemoveTypeDef.class); + } - planBuilder.append(PreProcessorApplier.class); + ProductionSet targetProduction = request.getTargetProductions(); + FeatureSet features = request.getFeatures(); + PlanBuilder<JSession> planBuilder; + try { + planBuilder = request.getPlanBuilder(JSession.class); + } catch (IllegalRequestException e) { + throw new AssertionError(e); + } - fillDexPlan(planBuilder); - if (targetProduction.contains(DexFileProduct.class)) { - planBuilder.append(DexFileWriter.class); - } + planBuilder.append(PreProcessorApplier.class); - if (features.contains(Resources.class)) { + fillDexPlan(planBuilder); if (targetProduction.contains(DexFileProduct.class)) { - planBuilder.append(ResourceWriter.class); + planBuilder.append(DexFileWriter.class); } - if (targetProduction.contains(JayceInLibraryProduct.class)) { - planBuilder.append(LibraryResourceWriter.class); + + if (features.contains(Resources.class)) { + if (targetProduction.contains(DexFileProduct.class)) { + planBuilder.append(ResourceWriter.class); + } + if (targetProduction.contains(JayceInLibraryProduct.class)) { + planBuilder.append(LibraryResourceWriter.class); + } } - } - if (targetProduction.contains(JayceInLibraryProduct.class)) { - planBuilder.append(LibraryMetaWriter.class); - } + if (targetProduction.contains(JayceInLibraryProduct.class)) { + planBuilder.append(LibraryMetaWriter.class); + } - Plan<JSession> plan; - try { - // Try to build an automatic plan ... + Plan<JSession> plan; try { - plan = request.buildPlan(JSession.class); - } catch (PlanNotFoundException e) { - throw new AssertionError(e); - } catch (IllegalRequestException e) { - throw new AssertionError(e); + // Try to build an automatic plan ... + try { + plan = request.buildPlan(JSession.class); + } catch (PlanNotFoundException e) { + throw new AssertionError(e); + } catch (IllegalRequestException e) { + throw new AssertionError(e); + } + } catch (UnsupportedOperationException e) { + // ... but use a manual one if not supported + plan = planBuilder.getPlan(); + + assert !targetProduction.contains(JayceInLibraryProduct.class) + || targetProduction.contains(DexFileProduct.class) || (plan.computeFinalTagsOrMarkers( + request.getInitialTags()).contains(JackFormatIr.class) + && !targetProduction.contains(DexInLibraryProduct.class)) || ( + targetProduction.contains(DexInLibraryProduct.class) + && targetProduction.contains(JayceInLibraryProduct.class)); } - } catch (UnsupportedOperationException e) { - // ... but use a manual one if not supported - plan = planBuilder.getPlan(); - - assert !targetProduction.contains(JayceInLibraryProduct.class) - || targetProduction.contains(DexFileProduct.class) || (plan.computeFinalTagsOrMarkers( - request.getInitialTags()).contains(JackFormatIr.class) - && !targetProduction.contains(DexInLibraryProduct.class)) || ( - targetProduction.contains(DexInLibraryProduct.class) - && targetProduction.contains(JayceInLibraryProduct.class)); - } - PlanPrinterFactory.getPlanPrinter().printPlan(plan); - try { + PlanPrinterFactory.getPlanPrinter().printPlan(plan); + plan.getScheduleInstance().process(session); } finally { try { - OutputLibrary jackOutputLibrary = session.getJackOutputLibrary(); - if (jackOutputLibrary != null) { - jackOutputLibrary.close(); + if (session.getInputFilter() != null) { + session.getInputFilter().getOutputJackLibrary().close(); } + // TODO(jack-team): auto-close if (config.get(Options.GENERATE_DEX_FILE).booleanValue() && config.get(Options.DEX_OUTPUT_CONTAINER_TYPE) == Container.ZIP) { @@ -656,11 +658,17 @@ public abstract class Jack { } @Nonnull - static JSession buildSession(@Nonnull Options options, @Nonnull RunnableHooks hooks) - throws JackUserException { - Tracer tracer = TracerFactory.getTracer(); + static JSession buildSession(@Nonnull Options options, + @Nonnull RunnableHooks hooks) throws JackUserException { + JSession session = getSession(); + buildSession(session, options, hooks); + return session; + } - JSession session = getSession(); + @Nonnull + private static void buildSession(@Nonnull JSession session, @Nonnull Options options, + @Nonnull RunnableHooks hooks) throws JackUserException { + Tracer tracer = TracerFactory.getTracer(); session.setHooks(hooks); @@ -762,8 +770,6 @@ public abstract class Jack { MethodIdDuplicateRemover methodIdDupRemover = new MethodIdDuplicateRemover(); methodIdDupRemover.accept(session.getTypesToEmit()); } - - return session; } private static void addPackageLoaderForLibrary(JSession session, diff --git a/jack/src/com/android/jack/incremental/IncrementalInputFilter.java b/jack/src/com/android/jack/incremental/IncrementalInputFilter.java index 1330ada..98eb61c 100644 --- a/jack/src/com/android/jack/incremental/IncrementalInputFilter.java +++ b/jack/src/com/android/jack/incremental/IncrementalInputFilter.java @@ -153,6 +153,9 @@ public class IncrementalInputFilter extends CommonFilter implements InputFilter @Nonnull private final File incrementalFolder; + @Nonnull + private final OutputJackLibrary outputJackLibrary; + public IncrementalInputFilter(@Nonnull Options options) { Config config = ThreadConfig.getConfig(); incrementalFolder = new File(config.get(Options.LIBRARY_OUTPUT_DIR).getPath()); @@ -196,6 +199,8 @@ public class IncrementalInputFilter extends CommonFilter implements InputFilter session.getLibraryDependencies().addLibrariesOnClasspath(librariesOnClasspathFromCommandLine); filesToRecompile = getInternalFileNamesToCompile(); + outputJackLibrary = createOutputJackLibrary(); + if (config.get(INCREMENTAL_LOG).booleanValue()) { IncrementalLogWriter incLog; try { @@ -463,9 +468,9 @@ public class IncrementalInputFilter extends CommonFilter implements InputFilter return inputLibraries; } - @Override @Nonnull - public OutputJackLibrary getOutputJackLibrary() { + private OutputJackLibrary createOutputJackLibrary() { + if (ThreadConfig.get(Options.GENERATE_LIBRARY_FROM_INCREMENTAL_FOLDER).booleanValue()) { VFS dirVFS = ThreadConfig.get(Options.LIBRARY_OUTPUT_DIR); ReadWriteZipFS zipVFS = (ReadWriteZipFS) ThreadConfig.get(Options.LIBRARY_OUTPUT_ZIP); @@ -481,4 +486,10 @@ public class IncrementalInputFilter extends CommonFilter implements InputFilter } } } + + @Override + @Nonnull + public OutputJackLibrary getOutputJackLibrary() { + return outputJackLibrary; + } } diff --git a/jack/src/com/android/jack/incremental/NoInputFilter.java b/jack/src/com/android/jack/incremental/NoInputFilter.java index 2dad78d..3813e89 100644 --- a/jack/src/com/android/jack/incremental/NoInputFilter.java +++ b/jack/src/com/android/jack/incremental/NoInputFilter.java @@ -50,6 +50,9 @@ public class NoInputFilter extends CommonFilter implements InputFilter { @Nonnull private final List<? extends InputLibrary> librariesOnClasspathFromCommandLine; + @Nonnull + private final OutputJackLibrary outputJackLibrary; + public NoInputFilter(@Nonnull Options options) { this.options = options; this.fileNamesToCompile = getJavaFileNamesSpecifiedOnCommandLine(options); @@ -64,6 +67,8 @@ public class NoInputFilter extends CommonFilter implements InputFilter { LibraryDependencies libraryDependencies = session.getLibraryDependencies(); libraryDependencies.addImportedLibraries(importedLibrariesFromCommandLine); libraryDependencies.addLibrariesOnClasspath(librariesOnClasspathFromCommandLine); + + outputJackLibrary = getOutputJackLibraryFromVfs(); } @Override @@ -87,6 +92,6 @@ public class NoInputFilter extends CommonFilter implements InputFilter { @Override @Nonnull public OutputJackLibrary getOutputJackLibrary() { - return getOutputJackLibraryFromVfs(); + return outputJackLibrary; } } diff --git a/jack/src/com/android/jack/ir/ast/JSession.java b/jack/src/com/android/jack/ir/ast/JSession.java index a83ae03..ec72e2e 100644 --- a/jack/src/com/android/jack/ir/ast/JSession.java +++ b/jack/src/com/android/jack/ir/ast/JSession.java @@ -123,9 +123,8 @@ public class JSession extends JNode { phantomLookup = new JPhantomLookup(lookup); } - @Nonnull + @CheckForNull public InputFilter getInputFilter() { - assert inputFilter != null; return inputFilter; } diff --git a/jack/tests/com/android/jack/frontend/OrderedInputFilter.java b/jack/tests/com/android/jack/frontend/OrderedInputFilter.java index 5d1be70..9b3ee59 100644 --- a/jack/tests/com/android/jack/frontend/OrderedInputFilter.java +++ b/jack/tests/com/android/jack/frontend/OrderedInputFilter.java @@ -56,6 +56,9 @@ public class OrderedInputFilter extends CommonFilter implements InputFilter { @Nonnull private final List<? extends InputLibrary> librariesOnClasspathFromCommandLine; + @Nonnull + private final OutputJackLibrary outputJackLibrary; + public OrderedInputFilter(@Nonnull Options options) { this.options = options; this.fileNamesToCompile = getJavaFileNamesSpecifiedOnCommandLine(options); @@ -70,6 +73,8 @@ public class OrderedInputFilter extends CommonFilter implements InputFilter { LibraryDependencies libraryDependencies = session.getLibraryDependencies(); libraryDependencies.addImportedLibraries(importedLibrariesFromCommandLine); libraryDependencies.addLibrariesOnClasspath(librariesOnClasspathFromCommandLine); + + outputJackLibrary = getOutputJackLibraryFromVfs(); } @Override @@ -93,7 +98,7 @@ public class OrderedInputFilter extends CommonFilter implements InputFilter { @Override @Nonnull public OutputJackLibrary getOutputJackLibrary() { - return getOutputJackLibraryFromVfs(); + return outputJackLibrary; } @Override |