| Index: pkg/analyzer/tool/summary/build_sdk_summary.dart
|
| diff --git a/pkg/analyzer/tool/summary/build_sdk_summary.dart b/pkg/analyzer/tool/summary/build_sdk_summary.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6bfcf1e3f77d557d39a2b7f812a285363404b177
|
| --- /dev/null
|
| +++ b/pkg/analyzer/tool/summary/build_sdk_summary.dart
|
| @@ -0,0 +1,84 @@
|
| +import 'dart:io';
|
| +
|
| +import 'package:analyzer/dart/element/element.dart';
|
| +import 'package:analyzer/src/generated/engine.dart';
|
| +import 'package:analyzer/src/generated/java_io.dart';
|
| +import 'package:analyzer/src/generated/sdk.dart';
|
| +import 'package:analyzer/src/generated/sdk_io.dart';
|
| +import 'package:analyzer/src/generated/source.dart';
|
| +import 'package:analyzer/src/summary/builder.dart';
|
| +import 'package:analyzer/src/summary/format.dart';
|
| +import 'package:analyzer/src/summary/summarize_elements.dart';
|
| +
|
| +main(List<String> args) {
|
| + if (args.length < 1 || args.length > 2) {
|
| + _printUsage();
|
| + return;
|
| + }
|
| + //
|
| + // Prepare output file path.
|
| + //
|
| + String outputFilePath = args[0];
|
| + if (FileSystemEntity.isDirectorySync(outputFilePath)) {
|
| + print("'$outputFilePath' is a directory.");
|
| + _printUsage();
|
| + return;
|
| + }
|
| + //
|
| + // Prepare SDK path.
|
| + //
|
| + String sdkPath;
|
| + if (args.length == 2) {
|
| + sdkPath = args[1];
|
| + if (!FileSystemEntity.isDirectorySync('$sdkPath/lib')) {
|
| + print("'$sdkPath/lib' does not exist.");
|
| + _printUsage();
|
| + return;
|
| + }
|
| + } else {
|
| + sdkPath = DirectoryBasedDartSdk.defaultSdkDirectory.getAbsolutePath();
|
| + }
|
| + //
|
| + // Prepare SDK.
|
| + //
|
| + DirectoryBasedDartSdk sdk = new DirectoryBasedDartSdk(new JavaFile(sdkPath));
|
| + AnalysisContext context = sdk.context;
|
| + //
|
| + // Serialize each SDK library.
|
| + //
|
| + BuilderContext builderContext = new BuilderContext();
|
| + List<SdkBundleLibraryBuilder> libraryBuilders = <SdkBundleLibraryBuilder>[];
|
| + for (SdkLibrary lib in sdk.sdkLibraries) {
|
| + print('Resolving and serializing: ${lib.shortName}');
|
| + Source librarySource = sdk.mapDartUri(lib.shortName);
|
| + LibraryElement libraryElement =
|
| + context.computeLibraryElement(librarySource);
|
| + LibrarySerializationResult libraryResult =
|
| + serializeLibrary(builderContext, libraryElement, context.typeProvider);
|
| + SdkBundleLibraryBuilder libraryBuilder = encodeSdkBundleLibrary(
|
| + builderContext,
|
| + uri: lib.shortName,
|
| + prelinked: libraryResult.prelinked,
|
| + unlinkedUnits: libraryResult.unlinkedUnits);
|
| + libraryBuilders.add(libraryBuilder);
|
| + }
|
| + //
|
| + // Write the whole SDK bundle.
|
| + //
|
| + SdkBundleBuilder sdkBundle =
|
| + encodeSdkBundle(builderContext, libraries: libraryBuilders);
|
| + File file = new File(outputFilePath);
|
| + file.writeAsBytesSync(sdkBundle.toBuffer(), mode: FileMode.WRITE_ONLY);
|
| +}
|
| +
|
| +/**
|
| + * The name of the SDK summary builder application.
|
| + */
|
| +const BINARY_NAME = "build_sdk_summary";
|
| +
|
| +/**
|
| + * Print information about how to use the SDK summary builder.
|
| + */
|
| +void _printUsage() {
|
| + print('Usage: $BINARY_NAME output_file_path [sdk_path]');
|
| +}
|
|
|