Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 import 'dart:io'; | 1 import 'dart:io'; |
| 2 | 2 |
| 3 import 'package:analyzer/dart/element/element.dart'; | 3 import 'package:analyzer/dart/element/element.dart'; |
| 4 import 'package:analyzer/src/generated/engine.dart'; | 4 import 'package:analyzer/src/generated/engine.dart'; |
| 5 import 'package:analyzer/src/generated/java_io.dart'; | 5 import 'package:analyzer/src/generated/java_io.dart'; |
| 6 import 'package:analyzer/src/generated/sdk.dart'; | 6 import 'package:analyzer/src/generated/sdk.dart'; |
| 7 import 'package:analyzer/src/generated/sdk_io.dart'; | 7 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 8 import 'package:analyzer/src/generated/source.dart'; | 8 import 'package:analyzer/src/generated/source.dart'; |
| 9 import 'package:analyzer/src/summary/format.dart'; | 9 import 'package:analyzer/src/summary/format.dart'; |
| 10 import 'package:analyzer/src/summary/summarize_elements.dart'; | 10 import 'package:analyzer/src/summary/summarize_elements.dart'; |
| 11 import 'package:path/path.dart'; | |
| 11 | 12 |
| 12 main(List<String> args) { | 13 main(List<String> args) { |
| 13 if (args.length < 1 || args.length > 2) { | 14 if (args.length < 1 || args.length > 2) { |
| 14 _printUsage(); | 15 _printUsage(); |
| 15 exitCode = 1; | 16 exitCode = 1; |
| 16 return; | 17 return; |
| 17 } | 18 } |
| 18 // | 19 // |
| 19 // Prepare output file path. | 20 // Prepare output file path. |
| 20 // | 21 // |
| 21 String outputFilePath = args[0]; | 22 String outputDirectoryPath = args[0]; |
| 22 if (FileSystemEntity.isDirectorySync(outputFilePath)) { | 23 if (!FileSystemEntity.isDirectorySync(outputDirectoryPath)) { |
| 23 print("'$outputFilePath' is a directory."); | 24 print("'$outputDirectoryPath' is not a directory."); |
| 24 _printUsage(); | 25 _printUsage(); |
| 25 exitCode = 1; | 26 exitCode = 1; |
| 26 return; | 27 return; |
| 27 } | 28 } |
| 28 // | 29 // |
| 29 // Prepare SDK path. | 30 // Prepare SDK path. |
| 30 // | 31 // |
| 31 String sdkPath; | 32 String sdkPath; |
| 32 if (args.length == 2) { | 33 if (args.length == 2) { |
| 33 sdkPath = args[1]; | 34 sdkPath = args[1]; |
| 34 if (!FileSystemEntity.isDirectorySync('$sdkPath/lib')) { | 35 if (!FileSystemEntity.isDirectorySync('$sdkPath/lib')) { |
| 35 print("'$sdkPath/lib' does not exist."); | 36 print("'$sdkPath/lib' does not exist."); |
| 36 _printUsage(); | 37 _printUsage(); |
| 37 exitCode = 1; | 38 exitCode = 1; |
| 38 return; | 39 return; |
| 39 } | 40 } |
| 40 } else { | 41 } else { |
| 41 sdkPath = DirectoryBasedDartSdk.defaultSdkDirectory.getAbsolutePath(); | 42 sdkPath = DirectoryBasedDartSdk.defaultSdkDirectory.getAbsolutePath(); |
| 42 } | 43 } |
| 43 // | 44 // |
| 45 // Generate spec and strong summaries. | |
| 46 // | |
| 47 _generateSummary(sdkPath, outputDirectoryPath, false); | |
| 48 _generateSummary(sdkPath, outputDirectoryPath, true); | |
| 49 } | |
| 50 | |
| 51 /** | |
| 52 * The name of the SDK summaries builder application. | |
| 53 */ | |
| 54 const BINARY_NAME = "build_sdk_summaries"; | |
| 55 | |
| 56 /** | |
| 57 * Generate a strong or spec mode summary for the Dart SDK at [sdkPath]. | |
| 58 */ | |
| 59 void _generateSummary( | |
| 60 String sdkPath, String outputDirectoryPath, bool strongMode) { | |
| 61 print('Generating ${strongMode ? 'strong' : 'spec'} mode summary.'); | |
|
Paul Berry
2016/02/05 16:53:26
The other day Vijay was referring to spec mode as
| |
| 62 Stopwatch sw = new Stopwatch()..start(); | |
| 63 // | |
| 44 // Prepare SDK. | 64 // Prepare SDK. |
| 45 // | 65 // |
| 46 DirectoryBasedDartSdk sdk = new DirectoryBasedDartSdk(new JavaFile(sdkPath)); | 66 DirectoryBasedDartSdk sdk = new DirectoryBasedDartSdk(new JavaFile(sdkPath)); |
| 47 AnalysisContext context = sdk.context; | 67 AnalysisContext context = sdk.context; |
| 68 context.analysisOptions = new AnalysisOptionsImpl()..strongMode = strongMode; | |
| 48 // | 69 // |
| 49 // Serialize each SDK library. | 70 // Serialize each SDK library. |
| 50 // | 71 // |
| 51 List<String> linkedLibraryUris = <String>[]; | 72 List<String> linkedLibraryUris = <String>[]; |
| 52 List<LinkedLibraryBuilder> linkedLibraries = <LinkedLibraryBuilder>[]; | 73 List<LinkedLibraryBuilder> linkedLibraries = <LinkedLibraryBuilder>[]; |
| 53 List<String> unlinkedUnitUris = <String>[]; | 74 List<String> unlinkedUnitUris = <String>[]; |
| 54 List<UnlinkedUnitBuilder> unlinkedUnits = <UnlinkedUnitBuilder>[]; | 75 List<UnlinkedUnitBuilder> unlinkedUnits = <UnlinkedUnitBuilder>[]; |
| 55 for (SdkLibrary lib in sdk.sdkLibraries) { | 76 for (SdkLibrary lib in sdk.sdkLibraries) { |
| 56 print('Resolving and serializing: ${lib.shortName}'); | |
| 57 Source librarySource = sdk.mapDartUri(lib.shortName); | 77 Source librarySource = sdk.mapDartUri(lib.shortName); |
| 58 LibraryElement libraryElement = | 78 LibraryElement libraryElement = |
| 59 context.computeLibraryElement(librarySource); | 79 context.computeLibraryElement(librarySource); |
| 60 // TODO(paulberry): also build a summary of the SDK in strong mode. | |
| 61 LibrarySerializationResult libraryResult = | 80 LibrarySerializationResult libraryResult = |
| 62 serializeLibrary(libraryElement, context.typeProvider, false); | 81 serializeLibrary(libraryElement, context.typeProvider, strongMode); |
| 63 linkedLibraryUris.add(lib.shortName); | 82 linkedLibraryUris.add(lib.shortName); |
| 64 linkedLibraries.add(libraryResult.linked); | 83 linkedLibraries.add(libraryResult.linked); |
| 65 unlinkedUnitUris.addAll(libraryResult.unitUris); | 84 unlinkedUnitUris.addAll(libraryResult.unitUris); |
| 66 unlinkedUnits.addAll(libraryResult.unlinkedUnits); | 85 unlinkedUnits.addAll(libraryResult.unlinkedUnits); |
| 67 } | 86 } |
| 68 // | 87 // |
| 69 // Write the whole SDK bundle. | 88 // Write the whole SDK bundle. |
| 70 // | 89 // |
| 71 SdkBundleBuilder sdkBundle = new SdkBundleBuilder( | 90 SdkBundleBuilder sdkBundle = new SdkBundleBuilder( |
| 72 linkedLibraryUris: linkedLibraryUris, | 91 linkedLibraryUris: linkedLibraryUris, |
| 73 linkedLibraries: linkedLibraries, | 92 linkedLibraries: linkedLibraries, |
| 74 unlinkedUnitUris: unlinkedUnitUris, | 93 unlinkedUnitUris: unlinkedUnitUris, |
| 75 unlinkedUnits: unlinkedUnits); | 94 unlinkedUnits: unlinkedUnits); |
| 95 String outputFilePath = | |
| 96 join(outputDirectoryPath, strongMode ? 'strong.sum' : 'spec.sum'); | |
| 76 File file = new File(outputFilePath); | 97 File file = new File(outputFilePath); |
| 77 file.writeAsBytesSync(sdkBundle.toBuffer(), mode: FileMode.WRITE_ONLY); | 98 file.writeAsBytesSync(sdkBundle.toBuffer(), mode: FileMode.WRITE_ONLY); |
| 99 // | |
| 100 // Done. | |
| 101 // | |
| 102 print('\tDone in ${sw.elapsedMilliseconds} ms.'); | |
| 78 } | 103 } |
| 79 | 104 |
| 80 /** | 105 /** |
| 81 * The name of the SDK summary builder application. | |
| 82 */ | |
| 83 const BINARY_NAME = "build_sdk_summary"; | |
| 84 | |
| 85 /** | |
| 86 * Print information about how to use the SDK summary builder. | 106 * Print information about how to use the SDK summary builder. |
| 87 */ | 107 */ |
| 88 void _printUsage() { | 108 void _printUsage() { |
| 89 print('Usage: $BINARY_NAME output_file_path [sdk_path]'); | 109 print('Usage: $BINARY_NAME output_directory_path [sdk_path]'); |
| 110 print('Generate files spec.sum and strong.sum in the output directory.'); | |
| 90 } | 111 } |
| OLD | NEW |