Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Unified Diff: pkg/analyzer/tool/summary/build_sdk_summaries.dart

Issue 1681853002: Find and serialize other libraries next to the libraries described in libraries.dart meta. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Walk imports/exports instead of file system. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/tool/summary/build_sdk_summaries.dart
diff --git a/pkg/analyzer/tool/summary/build_sdk_summaries.dart b/pkg/analyzer/tool/summary/build_sdk_summaries.dart
index 2e680da75498f4f4d0462e3769b5c43795da1a08..ed0d95e67f9235f3d912335c3b324c35963981bb 100644
--- a/pkg/analyzer/tool/summary/build_sdk_summaries.dart
+++ b/pkg/analyzer/tool/summary/build_sdk_summaries.dart
@@ -44,8 +44,8 @@ main(List<String> args) {
//
// Build spec and strong summaries.
//
- _buildSummary(sdkPath, outputDirectoryPath, false);
- _buildSummary(sdkPath, outputDirectoryPath, true);
+ new _Builder(sdkPath, outputDirectoryPath, false).build();
+ new _Builder(sdkPath, outputDirectoryPath, true).build();
}
/**
@@ -54,58 +54,91 @@ main(List<String> args) {
const BINARY_NAME = "build_sdk_summaries";
/**
- * Build a strong or spec mode summary for the Dart SDK at [sdkPath].
+ * Print information about how to use the SDK summaries builder.
*/
-void _buildSummary(
- String sdkPath, String outputDirectoryPath, bool strongMode) {
- print('Generating ${strongMode ? 'strong' : 'spec'} mode summary.');
- Stopwatch sw = new Stopwatch()..start();
- //
- // Prepare SDK.
- //
- DirectoryBasedDartSdk sdk = new DirectoryBasedDartSdk(new JavaFile(sdkPath));
- AnalysisContext context = sdk.context;
- context.analysisOptions = new AnalysisOptionsImpl()..strongMode = strongMode;
- //
- // Serialize each SDK library.
- //
- List<String> linkedLibraryUris = <String>[];
- List<LinkedLibraryBuilder> linkedLibraries = <LinkedLibraryBuilder>[];
- List<String> unlinkedUnitUris = <String>[];
- List<UnlinkedUnitBuilder> unlinkedUnits = <UnlinkedUnitBuilder>[];
- for (SdkLibrary lib in sdk.sdkLibraries) {
- Source librarySource = sdk.mapDartUri(lib.shortName);
- LibraryElement libraryElement =
- context.computeLibraryElement(librarySource);
+void _printUsage() {
+ print('Usage: $BINARY_NAME output_directory_path [sdk_path]');
+ print('Build files spec.sum and strong.sum in the output directory.');
+}
+
+class _Builder {
+ final String sdkPath;
Brian Wilkerson 2016/02/09 17:16:40 As a future enhancement, we'll probably want to pa
+ final String outputDirectoryPath;
+ final bool strongMode;
+
+ AnalysisContext context;
+ final Set<Source> processedSources = new Set<Source>();
+
+ final List<String> linkedLibraryUris = <String>[];
+ final List<LinkedLibraryBuilder> linkedLibraries = <LinkedLibraryBuilder>[];
+ final List<String> unlinkedUnitUris = <String>[];
+ final List<UnlinkedUnitBuilder> unlinkedUnits = <UnlinkedUnitBuilder>[];
+
+ _Builder(this.sdkPath, this.outputDirectoryPath, this.strongMode);
+
+ /**
+ * Build a strong or spec mode summary for the Dart SDK at [sdkPath].
+ */
+ void build() {
+ print('Generating ${strongMode ? 'strong' : 'spec'} mode summary.');
+ Stopwatch sw = new Stopwatch()..start();
+ //
+ // Prepare SDK.
+ //
+ DirectoryBasedDartSdk sdk =
+ new DirectoryBasedDartSdk(new JavaFile(sdkPath));
+ context = sdk.context;
+ context.analysisOptions = new AnalysisOptionsImpl()
+ ..strongMode = strongMode;
+ //
+ // Serialize each SDK library.
+ //
+ for (SdkLibrary lib in sdk.sdkLibraries) {
+ Source libSource = sdk.mapDartUri(lib.shortName);
+ _serializeLibrary(libSource);
+ }
+ //
+ // Write the whole SDK bundle.
+ //
+ SdkBundleBuilder sdkBundle = new SdkBundleBuilder(
+ linkedLibraryUris: linkedLibraryUris,
+ linkedLibraries: linkedLibraries,
+ unlinkedUnitUris: unlinkedUnitUris,
+ unlinkedUnits: unlinkedUnits);
+ String outputFilePath =
+ join(outputDirectoryPath, strongMode ? 'strong.sum' : 'spec.sum');
+ File file = new File(outputFilePath);
+ file.writeAsBytesSync(sdkBundle.toBuffer(), mode: FileMode.WRITE_ONLY);
+ //
+ // Done.
+ //
+ print('\tDone in ${sw.elapsedMilliseconds} ms.');
+ }
+
+ /**
+ * Serialize the library with the given [source] and all its direct or
+ * indirect imports and exports.
+ */
+ void _serializeLibrary(Source source) {
+ if (!processedSources.add(source)) {
+ return;
+ }
+ LibraryElement element = context.computeLibraryElement(source);
+ _serializeSingleLibrary(element);
+ element.importedLibraries.forEach((e) => _serializeLibrary(e.source));
+ element.exportedLibraries.forEach((e) => _serializeLibrary(e.source));
+ }
+
+ /**
+ * Serialize the library with the given [element].
+ */
+ void _serializeSingleLibrary(LibraryElement element) {
+ String uri = element.source.uri.toString();
LibrarySerializationResult libraryResult =
- serializeLibrary(libraryElement, context.typeProvider, strongMode);
- linkedLibraryUris.add(lib.shortName);
+ serializeLibrary(element, context.typeProvider, strongMode);
+ linkedLibraryUris.add(uri);
linkedLibraries.add(libraryResult.linked);
unlinkedUnitUris.addAll(libraryResult.unitUris);
unlinkedUnits.addAll(libraryResult.unlinkedUnits);
}
- //
- // Write the whole SDK bundle.
- //
- SdkBundleBuilder sdkBundle = new SdkBundleBuilder(
- linkedLibraryUris: linkedLibraryUris,
- linkedLibraries: linkedLibraries,
- unlinkedUnitUris: unlinkedUnitUris,
- unlinkedUnits: unlinkedUnits);
- String outputFilePath =
- join(outputDirectoryPath, strongMode ? 'strong.sum' : 'spec.sum');
- File file = new File(outputFilePath);
- file.writeAsBytesSync(sdkBundle.toBuffer(), mode: FileMode.WRITE_ONLY);
- //
- // Done.
- //
- print('\tDone in ${sw.elapsedMilliseconds} ms.');
-}
-
-/**
- * Print information about how to use the SDK summaries builder.
- */
-void _printUsage() {
- print('Usage: $BINARY_NAME output_directory_path [sdk_path]');
- print('Build files spec.sum and strong.sum in the output directory.');
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698