| OLD | NEW |
| 1 import 'dart:io'; | 1 import 'dart:io'; |
| 2 | 2 |
| 3 import 'package:analyzer/dart/ast/ast.dart'; |
| 3 import 'package:analyzer/dart/element/element.dart'; | 4 import 'package:analyzer/dart/element/element.dart'; |
| 4 import 'package:analyzer/src/generated/engine.dart'; | 5 import 'package:analyzer/src/generated/engine.dart'; |
| 5 import 'package:analyzer/src/generated/java_io.dart'; | 6 import 'package:analyzer/src/generated/java_io.dart'; |
| 6 import 'package:analyzer/src/generated/sdk.dart'; | 7 import 'package:analyzer/src/generated/sdk.dart'; |
| 7 import 'package:analyzer/src/generated/sdk_io.dart'; | 8 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 8 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
| 9 import 'package:analyzer/src/summary/format.dart'; | 10 import 'package:analyzer/src/summary/format.dart'; |
| 11 import 'package:analyzer/src/summary/index_unit.dart'; |
| 10 import 'package:analyzer/src/summary/summarize_elements.dart'; | 12 import 'package:analyzer/src/summary/summarize_elements.dart'; |
| 11 import 'package:path/path.dart'; | 13 import 'package:path/path.dart'; |
| 12 | 14 |
| 13 main(List<String> args) { | 15 main(List<String> args) { |
| 14 if (args.length < 1 || args.length > 2) { | 16 if (args.length < 1 || args.length > 2) { |
| 15 _printUsage(); | 17 _printUsage(); |
| 16 exitCode = 1; | 18 exitCode = 1; |
| 17 return; | 19 return; |
| 18 } | 20 } |
| 19 // | 21 // |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } | 64 } |
| 63 | 65 |
| 64 class _Builder { | 66 class _Builder { |
| 65 final String sdkPath; | 67 final String sdkPath; |
| 66 final String outputDirectoryPath; | 68 final String outputDirectoryPath; |
| 67 final bool strongMode; | 69 final bool strongMode; |
| 68 | 70 |
| 69 AnalysisContext context; | 71 AnalysisContext context; |
| 70 final Set<Source> processedSources = new Set<Source>(); | 72 final Set<Source> processedSources = new Set<Source>(); |
| 71 | 73 |
| 72 final PackageBundleAssembler assembler = new PackageBundleAssembler(); | 74 final PackageBundleAssembler bundleAssembler = new PackageBundleAssembler(); |
| 75 final PackageIndexAssembler indexAssembler = new PackageIndexAssembler(); |
| 73 | 76 |
| 74 _Builder(this.sdkPath, this.outputDirectoryPath, this.strongMode); | 77 _Builder(this.sdkPath, this.outputDirectoryPath, this.strongMode); |
| 75 | 78 |
| 76 /** | 79 /** |
| 77 * Build a strong or spec mode summary for the Dart SDK at [sdkPath]. | 80 * Build a strong or spec mode summary for the Dart SDK at [sdkPath]. |
| 78 */ | 81 */ |
| 79 void build() { | 82 void build() { |
| 80 print('Generating ${strongMode ? 'strong' : 'spec'} mode summary.'); | 83 String modeName = strongMode ? 'strong' : 'spec'; |
| 84 print('Generating $modeName mode summary and index.'); |
| 81 Stopwatch sw = new Stopwatch()..start(); | 85 Stopwatch sw = new Stopwatch()..start(); |
| 82 // | 86 // |
| 83 // Prepare SDK. | 87 // Prepare SDK. |
| 84 // | 88 // |
| 85 DirectoryBasedDartSdk sdk = | 89 DirectoryBasedDartSdk sdk = |
| 86 new DirectoryBasedDartSdk(new JavaFile(sdkPath)); | 90 new DirectoryBasedDartSdk(new JavaFile(sdkPath)); |
| 87 sdk.useSummary = false; | 91 sdk.useSummary = false; |
| 88 context = sdk.context; | 92 context = sdk.context; |
| 89 context.analysisOptions = new AnalysisOptionsImpl() | 93 context.analysisOptions = new AnalysisOptionsImpl() |
| 90 ..strongMode = strongMode; | 94 ..strongMode = strongMode; |
| 91 // | 95 // |
| 92 // Prepare 'dart:' URIs to serialize. | 96 // Prepare 'dart:' URIs to serialize. |
| 93 // | 97 // |
| 94 Set<String> uriSet = | 98 Set<String> uriSet = |
| 95 sdk.sdkLibraries.map((SdkLibrary library) => library.shortName).toSet(); | 99 sdk.sdkLibraries.map((SdkLibrary library) => library.shortName).toSet(); |
| 96 uriSet.add('dart:html/nativewrappers.dart'); | 100 uriSet.add('dart:html/nativewrappers.dart'); |
| 97 uriSet.add('dart:html_common/html_common_dart2js.dart'); | 101 uriSet.add('dart:html_common/html_common_dart2js.dart'); |
| 98 // | 102 // |
| 99 // Serialize each SDK library. | 103 // Serialize each SDK library. |
| 100 // | 104 // |
| 101 for (String uri in uriSet) { | 105 for (String uri in uriSet) { |
| 102 Source libSource = sdk.mapDartUri(uri); | 106 Source libSource = sdk.mapDartUri(uri); |
| 103 _serializeLibrary(libSource); | 107 _serializeLibrary(libSource); |
| 104 } | 108 } |
| 105 // | 109 // |
| 106 // Write the whole SDK bundle. | 110 // Write the whole SDK bundle. |
| 107 // | 111 // |
| 108 PackageBundleBuilder sdkBundle = assembler.assemble(); | 112 { |
| 109 String outputFilePath = | 113 PackageBundleBuilder bundle = bundleAssembler.assemble(); |
| 110 join(outputDirectoryPath, strongMode ? 'strong.sum' : 'spec.sum'); | 114 String outputPath = join(outputDirectoryPath, '$modeName.sum'); |
| 111 File file = new File(outputFilePath); | 115 File file = new File(outputPath); |
| 112 file.writeAsBytesSync(sdkBundle.toBuffer(), mode: FileMode.WRITE_ONLY); | 116 file.writeAsBytesSync(bundle.toBuffer(), mode: FileMode.WRITE_ONLY); |
| 117 } |
| 118 // |
| 119 // Write the whole SDK index. |
| 120 // |
| 121 { |
| 122 PackageIndexBuilder index = indexAssembler.assemble(); |
| 123 String outputPath = join(outputDirectoryPath, '$modeName.index'); |
| 124 File file = new File(outputPath); |
| 125 file.writeAsBytesSync(index.toBuffer(), mode: FileMode.WRITE_ONLY); |
| 126 } |
| 113 // | 127 // |
| 114 // Done. | 128 // Done. |
| 115 // | 129 // |
| 116 print('\tDone in ${sw.elapsedMilliseconds} ms.'); | 130 print('\tDone in ${sw.elapsedMilliseconds} ms.'); |
| 117 } | 131 } |
| 118 | 132 |
| 119 /** | 133 /** |
| 120 * Serialize the library with the given [source] and all its direct or | 134 * Serialize the library with the given [source] and all its direct or |
| 121 * indirect imports and exports. | 135 * indirect imports and exports. |
| 122 */ | 136 */ |
| 123 void _serializeLibrary(Source source) { | 137 void _serializeLibrary(Source source) { |
| 124 if (!processedSources.add(source)) { | 138 if (!processedSources.add(source)) { |
| 125 return; | 139 return; |
| 126 } | 140 } |
| 127 LibraryElement element = context.computeLibraryElement(source); | 141 LibraryElement element = context.computeLibraryElement(source); |
| 128 assembler.serializeLibraryElement(element); | 142 bundleAssembler.serializeLibraryElement(element); |
| 129 element.importedLibraries.forEach((e) => _serializeLibrary(e.source)); | 143 element.importedLibraries.forEach((e) => _serializeLibrary(e.source)); |
| 130 element.exportedLibraries.forEach((e) => _serializeLibrary(e.source)); | 144 element.exportedLibraries.forEach((e) => _serializeLibrary(e.source)); |
| 145 // Index every unit of the library. |
| 146 for (CompilationUnitElement unitElement in element.units) { |
| 147 Source unitSource = unitElement.source; |
| 148 CompilationUnit unit = |
| 149 context.resolveCompilationUnit2(unitSource, source); |
| 150 indexAssembler.index(unit); |
| 151 } |
| 131 } | 152 } |
| 132 } | 153 } |
| OLD | NEW |