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

Side by Side Diff: pkg/analyzer/tool/summary/build_sdk_summaries.dart

Issue 2055543002: SDK summary creation generalization (pt 1). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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 | « pkg/analyzer/lib/src/summary/summary_file_builder.dart ('k') | 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/ast/ast.dart';
4 import 'package:analyzer/dart/element/element.dart';
5 import 'package:analyzer/src/generated/engine.dart';
6 import 'package:analyzer/src/generated/java_io.dart';
7 import 'package:analyzer/src/generated/sdk.dart';
8 import 'package:analyzer/src/generated/sdk_io.dart'; 3 import 'package:analyzer/src/generated/sdk_io.dart';
9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:analyzer/src/summary/flat_buffers.dart' as fb; 4 import 'package:analyzer/src/summary/flat_buffers.dart' as fb;
11 import 'package:analyzer/src/summary/index_unit.dart'; 5 import 'package:analyzer/src/summary/summary_file_builder.dart';
12 import 'package:analyzer/src/summary/summarize_elements.dart';
13 import 'package:path/path.dart';
14 6
15 main(List<String> args) { 7 main(List<String> args) {
16 if (args.length < 1) { 8 if (args.length < 1) {
17 _printUsage(); 9 _printUsage();
18 exitCode = 1; 10 exitCode = 1;
19 return; 11 return;
20 } 12 }
21 String command = args[0]; 13 String command = args[0];
22 if ((command == 'multiple-outputs' || command == 'strong-outputs') && 14 if ((command == 'multiple-outputs' || command == 'strong-outputs') &&
23 args.length >= 2 && 15 args.length >= 2 &&
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // 109 //
118 if (sdkPath != null) { 110 if (sdkPath != null) {
119 if (!FileSystemEntity.isDirectorySync('$sdkPath/lib')) { 111 if (!FileSystemEntity.isDirectorySync('$sdkPath/lib')) {
120 print("'$sdkPath/lib' does not exist."); 112 print("'$sdkPath/lib' does not exist.");
121 _printUsage(); 113 _printUsage();
122 return null; 114 return null;
123 } 115 }
124 } else { 116 } else {
125 sdkPath = DirectoryBasedDartSdk.defaultSdkDirectory.getAbsolutePath(); 117 sdkPath = DirectoryBasedDartSdk.defaultSdkDirectory.getAbsolutePath();
126 } 118 }
119
127 // 120 //
128 // Build spec and strong outputs. 121 // Build spec and strong outputs.
129 // 122 //
130 _BuilderOutput spec = 123 BuilderOutput spec = includeSpec ? _buildOutput(sdkPath, false) : null;
131 includeSpec ? new _Builder(sdkPath, false).build() : null; 124 BuilderOutput strong = _buildOutput(sdkPath, true);
132 _BuilderOutput strong = new _Builder(sdkPath, true).build();
133 return new _Output(spec, strong); 125 return new _Output(spec, strong);
134 } 126 }
135 127
128 BuilderOutput _buildOutput(String sdkPath, bool strongMode) {
129 String modeName = strongMode ? 'strong' : 'spec';
130 print('Generating $modeName mode summary and index.');
131 Stopwatch sw = new Stopwatch()..start();
132 BuilderOutput output = new SummaryBuilder.forSdk(sdkPath, strongMode).build();
133 print('\tDone in ${sw.elapsedMilliseconds} ms.');
134 return output;
135 }
136
136 /** 137 /**
137 * Open the flat buffer in [inputPath] and extract the byte array in the [field] 138 * Open the flat buffer in [inputPath] and extract the byte array in the [field]
138 * into the [outputPath] file. 139 * into the [outputPath] file.
139 */ 140 */
140 void _extractSingleOutput(String inputPath, int field, String outputPath) { 141 void _extractSingleOutput(String inputPath, int field, String outputPath) {
141 List<int> bytes = new File(inputPath).readAsBytesSync(); 142 List<int> bytes = new File(inputPath).readAsBytesSync();
142 fb.BufferContext root = new fb.BufferContext.fromBytes(bytes); 143 fb.BufferContext root = new fb.BufferContext.fromBytes(bytes);
143 int tableOffset = root.derefObject(0); 144 int tableOffset = root.derefObject(0);
144 List<int> fieldBytes = 145 List<int> fieldBytes =
145 const fb.Uint8ListReader().vTableGet(root, tableOffset, field); 146 const fb.Uint8ListReader().vTableGet(root, tableOffset, field);
(...skipping 16 matching lines...) Expand all
162 print(' extract-spec-sum input_file output_file'); 163 print(' extract-spec-sum input_file output_file');
163 print(' Extract the spec-mode summary file.'); 164 print(' Extract the spec-mode summary file.');
164 print(' extract-strong-sum input_file output_file'); 165 print(' extract-strong-sum input_file output_file');
165 print(' Extract the strong-mode summary file.'); 166 print(' Extract the strong-mode summary file.');
166 print(' extract-spec-index input_file output_file'); 167 print(' extract-spec-index input_file output_file');
167 print(' Extract the spec-mode index file.'); 168 print(' Extract the spec-mode index file.');
168 print(' extract-strong-index input_file output_file'); 169 print(' extract-strong-index input_file output_file');
169 print(' Extract the strong-mode index file.'); 170 print(' Extract the strong-mode index file.');
170 } 171 }
171 172
172 class _Builder {
173 final String sdkPath;
174 final bool strongMode;
175
176 AnalysisContext context;
177 final Set<Source> processedSources = new Set<Source>();
178
179 final PackageBundleAssembler bundleAssembler = new PackageBundleAssembler();
180 final PackageIndexAssembler indexAssembler = new PackageIndexAssembler();
181
182 _Builder(this.sdkPath, this.strongMode);
183
184 /**
185 * Build a strong or spec mode summary for the Dart SDK at [sdkPath].
186 */
187 _BuilderOutput build() {
188 String modeName = strongMode ? 'strong' : 'spec';
189 print('Generating $modeName mode summary and index.');
190 Stopwatch sw = new Stopwatch()..start();
191 //
192 // Prepare SDK.
193 //
194 DirectoryBasedDartSdk sdk =
195 new DirectoryBasedDartSdk(new JavaFile(sdkPath), strongMode);
196 sdk.useSummary = false;
197 sdk.analysisOptions = new AnalysisOptionsImpl()..strongMode = strongMode;
198 context = sdk.context;
199 //
200 // Prepare 'dart:' URIs to serialize.
201 //
202 Set<String> uriSet =
203 sdk.sdkLibraries.map((SdkLibrary library) => library.shortName).toSet();
204 if (!strongMode) {
205 uriSet.add('dart:html/nativewrappers.dart');
206 }
207 uriSet.add('dart:html_common/html_common_dart2js.dart');
208 //
209 // Serialize each SDK library.
210 //
211 for (String uri in uriSet) {
212 Source libSource = sdk.mapDartUri(uri);
213 _serializeLibrary(libSource);
214 }
215 //
216 // Assemble the output.
217 //
218 List<int> sumBytes = bundleAssembler.assemble().toBuffer();
219 List<int> indexBytes = indexAssembler.assemble().toBuffer();
220 print('\tDone in ${sw.elapsedMilliseconds} ms.');
221 return new _BuilderOutput(sumBytes, indexBytes);
222 }
223
224 /**
225 * Serialize the library with the given [source] and all its direct or
226 * indirect imports and exports.
227 */
228 void _serializeLibrary(Source source) {
229 if (!processedSources.add(source)) {
230 return;
231 }
232 LibraryElement element = context.computeLibraryElement(source);
233 bundleAssembler.serializeLibraryElement(element);
234 element.importedLibraries.forEach((e) => _serializeLibrary(e.source));
235 element.exportedLibraries.forEach((e) => _serializeLibrary(e.source));
236 // Index every unit of the library.
237 for (CompilationUnitElement unitElement in element.units) {
238 Source unitSource = unitElement.source;
239 CompilationUnit unit =
240 context.resolveCompilationUnit2(unitSource, source);
241 indexAssembler.indexUnit(unit);
242 }
243 }
244 }
245
246 class _BuilderOutput {
247 final List<int> sum;
248 final List<int> index;
249
250 _BuilderOutput(this.sum, this.index);
251
252 void writeMultiple(String outputDirectoryPath, String modeName) {
253 // Write summary.
254 {
255 String outputPath = join(outputDirectoryPath, '$modeName.sum');
256 File file = new File(outputPath);
257 file.writeAsBytesSync(sum, mode: FileMode.WRITE_ONLY);
258 }
259 // Write index.
260 {
261 String outputPath = join(outputDirectoryPath, '$modeName.index');
262 File file = new File(outputPath);
263 file.writeAsBytesSync(index, mode: FileMode.WRITE_ONLY);
264 }
265 }
266 }
267
268 class _Output { 173 class _Output {
269 final _BuilderOutput spec; 174 final BuilderOutput spec;
270 final _BuilderOutput strong; 175 final BuilderOutput strong;
271 176
272 _Output(this.spec, this.strong); 177 _Output(this.spec, this.strong);
273 } 178 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summary_file_builder.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698