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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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';
(...skipping 26 matching lines...) Expand all
37 _printUsage(); 37 _printUsage();
38 exitCode = 1; 38 exitCode = 1;
39 return; 39 return;
40 } 40 }
41 } else { 41 } else {
42 sdkPath = DirectoryBasedDartSdk.defaultSdkDirectory.getAbsolutePath(); 42 sdkPath = DirectoryBasedDartSdk.defaultSdkDirectory.getAbsolutePath();
43 } 43 }
44 // 44 //
45 // Build spec and strong summaries. 45 // Build spec and strong summaries.
46 // 46 //
47 _buildSummary(sdkPath, outputDirectoryPath, false); 47 new _Builder(sdkPath, outputDirectoryPath, false).build();
48 _buildSummary(sdkPath, outputDirectoryPath, true); 48 new _Builder(sdkPath, outputDirectoryPath, true).build();
49 } 49 }
50 50
51 /** 51 /**
52 * The name of the SDK summaries builder application. 52 * The name of the SDK summaries builder application.
53 */ 53 */
54 const BINARY_NAME = "build_sdk_summaries"; 54 const BINARY_NAME = "build_sdk_summaries";
55 55
56 /** 56 /**
57 * Build a strong or spec mode summary for the Dart SDK at [sdkPath].
58 */
59 void _buildSummary(
60 String sdkPath, String outputDirectoryPath, bool strongMode) {
61 print('Generating ${strongMode ? 'strong' : 'spec'} mode summary.');
62 Stopwatch sw = new Stopwatch()..start();
63 //
64 // Prepare SDK.
65 //
66 DirectoryBasedDartSdk sdk = new DirectoryBasedDartSdk(new JavaFile(sdkPath));
67 AnalysisContext context = sdk.context;
68 context.analysisOptions = new AnalysisOptionsImpl()..strongMode = strongMode;
69 //
70 // Serialize each SDK library.
71 //
72 List<String> linkedLibraryUris = <String>[];
73 List<LinkedLibraryBuilder> linkedLibraries = <LinkedLibraryBuilder>[];
74 List<String> unlinkedUnitUris = <String>[];
75 List<UnlinkedUnitBuilder> unlinkedUnits = <UnlinkedUnitBuilder>[];
76 for (SdkLibrary lib in sdk.sdkLibraries) {
77 Source librarySource = sdk.mapDartUri(lib.shortName);
78 LibraryElement libraryElement =
79 context.computeLibraryElement(librarySource);
80 LibrarySerializationResult libraryResult =
81 serializeLibrary(libraryElement, context.typeProvider, strongMode);
82 linkedLibraryUris.add(lib.shortName);
83 linkedLibraries.add(libraryResult.linked);
84 unlinkedUnitUris.addAll(libraryResult.unitUris);
85 unlinkedUnits.addAll(libraryResult.unlinkedUnits);
86 }
87 //
88 // Write the whole SDK bundle.
89 //
90 SdkBundleBuilder sdkBundle = new SdkBundleBuilder(
91 linkedLibraryUris: linkedLibraryUris,
92 linkedLibraries: linkedLibraries,
93 unlinkedUnitUris: unlinkedUnitUris,
94 unlinkedUnits: unlinkedUnits);
95 String outputFilePath =
96 join(outputDirectoryPath, strongMode ? 'strong.sum' : 'spec.sum');
97 File file = new File(outputFilePath);
98 file.writeAsBytesSync(sdkBundle.toBuffer(), mode: FileMode.WRITE_ONLY);
99 //
100 // Done.
101 //
102 print('\tDone in ${sw.elapsedMilliseconds} ms.');
103 }
104
105 /**
106 * Print information about how to use the SDK summaries builder. 57 * Print information about how to use the SDK summaries builder.
107 */ 58 */
108 void _printUsage() { 59 void _printUsage() {
109 print('Usage: $BINARY_NAME output_directory_path [sdk_path]'); 60 print('Usage: $BINARY_NAME output_directory_path [sdk_path]');
110 print('Build files spec.sum and strong.sum in the output directory.'); 61 print('Build files spec.sum and strong.sum in the output directory.');
111 } 62 }
63
64 class _Builder {
65 final String sdkPath;
Brian Wilkerson 2016/02/09 17:16:40 As a future enhancement, we'll probably want to pa
66 final String outputDirectoryPath;
67 final bool strongMode;
68
69 AnalysisContext context;
70 final Set<Source> processedSources = new Set<Source>();
71
72 final List<String> linkedLibraryUris = <String>[];
73 final List<LinkedLibraryBuilder> linkedLibraries = <LinkedLibraryBuilder>[];
74 final List<String> unlinkedUnitUris = <String>[];
75 final List<UnlinkedUnitBuilder> unlinkedUnits = <UnlinkedUnitBuilder>[];
76
77 _Builder(this.sdkPath, this.outputDirectoryPath, this.strongMode);
78
79 /**
80 * Build a strong or spec mode summary for the Dart SDK at [sdkPath].
81 */
82 void build() {
83 print('Generating ${strongMode ? 'strong' : 'spec'} mode summary.');
84 Stopwatch sw = new Stopwatch()..start();
85 //
86 // Prepare SDK.
87 //
88 DirectoryBasedDartSdk sdk =
89 new DirectoryBasedDartSdk(new JavaFile(sdkPath));
90 context = sdk.context;
91 context.analysisOptions = new AnalysisOptionsImpl()
92 ..strongMode = strongMode;
93 //
94 // Serialize each SDK library.
95 //
96 for (SdkLibrary lib in sdk.sdkLibraries) {
97 Source libSource = sdk.mapDartUri(lib.shortName);
98 _serializeLibrary(libSource);
99 }
100 //
101 // Write the whole SDK bundle.
102 //
103 SdkBundleBuilder sdkBundle = new SdkBundleBuilder(
104 linkedLibraryUris: linkedLibraryUris,
105 linkedLibraries: linkedLibraries,
106 unlinkedUnitUris: unlinkedUnitUris,
107 unlinkedUnits: unlinkedUnits);
108 String outputFilePath =
109 join(outputDirectoryPath, strongMode ? 'strong.sum' : 'spec.sum');
110 File file = new File(outputFilePath);
111 file.writeAsBytesSync(sdkBundle.toBuffer(), mode: FileMode.WRITE_ONLY);
112 //
113 // Done.
114 //
115 print('\tDone in ${sw.elapsedMilliseconds} ms.');
116 }
117
118 /**
119 * Serialize the library with the given [source] and all its direct or
120 * indirect imports and exports.
121 */
122 void _serializeLibrary(Source source) {
123 if (!processedSources.add(source)) {
124 return;
125 }
126 LibraryElement element = context.computeLibraryElement(source);
127 _serializeSingleLibrary(element);
128 element.importedLibraries.forEach((e) => _serializeLibrary(e.source));
129 element.exportedLibraries.forEach((e) => _serializeLibrary(e.source));
130 }
131
132 /**
133 * Serialize the library with the given [element].
134 */
135 void _serializeSingleLibrary(LibraryElement element) {
136 String uri = element.source.uri.toString();
137 LibrarySerializationResult libraryResult =
138 serializeLibrary(element, context.typeProvider, strongMode);
139 linkedLibraryUris.add(uri);
140 linkedLibraries.add(libraryResult.linked);
141 unlinkedUnitUris.addAll(libraryResult.unitUris);
142 unlinkedUnits.addAll(libraryResult.unlinkedUnits);
143 }
144 }
OLDNEW
« 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