| OLD | NEW |
| (Empty) |
| 1 import 'dart:io'; | |
| 2 | |
| 3 import 'package:analyzer/dart/element/element.dart'; | |
| 4 import 'package:analyzer/src/generated/engine.dart'; | |
| 5 import 'package:analyzer/src/generated/java_io.dart'; | |
| 6 import 'package:analyzer/src/generated/sdk.dart'; | |
| 7 import 'package:analyzer/src/generated/sdk_io.dart'; | |
| 8 import 'package:analyzer/src/generated/source.dart'; | |
| 9 import 'package:analyzer/src/summary/format.dart'; | |
| 10 import 'package:analyzer/src/summary/summarize_elements.dart'; | |
| 11 | |
| 12 main(List<String> args) { | |
| 13 if (args.length < 1 || args.length > 2) { | |
| 14 _printUsage(); | |
| 15 exitCode = 1; | |
| 16 return; | |
| 17 } | |
| 18 // | |
| 19 // Prepare output file path. | |
| 20 // | |
| 21 String outputFilePath = args[0]; | |
| 22 if (FileSystemEntity.isDirectorySync(outputFilePath)) { | |
| 23 print("'$outputFilePath' is a directory."); | |
| 24 _printUsage(); | |
| 25 exitCode = 1; | |
| 26 return; | |
| 27 } | |
| 28 // | |
| 29 // Prepare SDK path. | |
| 30 // | |
| 31 String sdkPath; | |
| 32 if (args.length == 2) { | |
| 33 sdkPath = args[1]; | |
| 34 if (!FileSystemEntity.isDirectorySync('$sdkPath/lib')) { | |
| 35 print("'$sdkPath/lib' does not exist."); | |
| 36 _printUsage(); | |
| 37 exitCode = 1; | |
| 38 return; | |
| 39 } | |
| 40 } else { | |
| 41 sdkPath = DirectoryBasedDartSdk.defaultSdkDirectory.getAbsolutePath(); | |
| 42 } | |
| 43 // | |
| 44 // Prepare SDK. | |
| 45 // | |
| 46 DirectoryBasedDartSdk sdk = new DirectoryBasedDartSdk(new JavaFile(sdkPath)); | |
| 47 AnalysisContext context = sdk.context; | |
| 48 // | |
| 49 // Serialize each SDK library. | |
| 50 // | |
| 51 List<String> linkedLibraryUris = <String>[]; | |
| 52 List<LinkedLibraryBuilder> linkedLibraries = <LinkedLibraryBuilder>[]; | |
| 53 List<String> unlinkedUnitUris = <String>[]; | |
| 54 List<UnlinkedUnitBuilder> unlinkedUnits = <UnlinkedUnitBuilder>[]; | |
| 55 for (SdkLibrary lib in sdk.sdkLibraries) { | |
| 56 print('Resolving and serializing: ${lib.shortName}'); | |
| 57 Source librarySource = sdk.mapDartUri(lib.shortName); | |
| 58 LibraryElement libraryElement = | |
| 59 context.computeLibraryElement(librarySource); | |
| 60 // TODO(paulberry): also build a summary of the SDK in strong mode. | |
| 61 LibrarySerializationResult libraryResult = | |
| 62 serializeLibrary(libraryElement, context.typeProvider, false); | |
| 63 linkedLibraryUris.add(lib.shortName); | |
| 64 linkedLibraries.add(libraryResult.linked); | |
| 65 unlinkedUnitUris.addAll(libraryResult.unitUris); | |
| 66 unlinkedUnits.addAll(libraryResult.unlinkedUnits); | |
| 67 } | |
| 68 // | |
| 69 // Write the whole SDK bundle. | |
| 70 // | |
| 71 SdkBundleBuilder sdkBundle = new SdkBundleBuilder( | |
| 72 linkedLibraryUris: linkedLibraryUris, | |
| 73 linkedLibraries: linkedLibraries, | |
| 74 unlinkedUnitUris: unlinkedUnitUris, | |
| 75 unlinkedUnits: unlinkedUnits); | |
| 76 File file = new File(outputFilePath); | |
| 77 file.writeAsBytesSync(sdkBundle.toBuffer(), mode: FileMode.WRITE_ONLY); | |
| 78 } | |
| 79 | |
| 80 /** | |
| 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. | |
| 87 */ | |
| 88 void _printUsage() { | |
| 89 print('Usage: $BINARY_NAME output_file_path [sdk_path]'); | |
| 90 } | |
| OLD | NEW |