OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer_cli.src.build_mode; | 5 library analyzer_cli.src.build_mode; |
6 | 6 |
7 import 'dart:core'; | 7 import 'dart:core'; |
8 import 'dart:io' as io; | 8 import 'dart:io' as io; |
9 | 9 |
10 import 'package:analyzer/dart/ast/ast.dart' show CompilationUnit; | 10 import 'package:analyzer/dart/ast/ast.dart' show CompilationUnit; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 AnalysisResult analysisResult = context.performAnalysisTask(); | 192 AnalysisResult analysisResult = context.performAnalysisTask(); |
193 if (!analysisResult.hasMoreWork) { | 193 if (!analysisResult.hasMoreWork) { |
194 break; | 194 break; |
195 } | 195 } |
196 } | 196 } |
197 } | 197 } |
198 | 198 |
199 // Write summary. | 199 // Write summary. |
200 assembler = new PackageBundleAssembler(); | 200 assembler = new PackageBundleAssembler(); |
201 if (_shouldOutputSummary) { | 201 if (_shouldOutputSummary) { |
202 _serializeAstBasedSummary(explicitSources); | 202 if (options.buildSummaryOnlyUnlinked) { |
203 for (var src in explicitSources) { | |
204 // Note: This adds the unit to the assembler if it needed to be | |
205 // computed, so we don't need to explicitly do that. | |
206 _unlinkedUnitForUri('${src.uri}'); | |
207 } | |
208 } else { | |
209 _serializeAstBasedSummary(explicitSources); | |
210 assembler.recordDependencies(summaryDataStore); | |
211 } | |
203 // Write the whole package bundle. | 212 // Write the whole package bundle. |
204 assembler.recordDependencies(summaryDataStore); | |
205 PackageBundleBuilder bundle = assembler.assemble(); | 213 PackageBundleBuilder bundle = assembler.assemble(); |
206 if (options.buildSummaryOutput != null) { | 214 if (options.buildSummaryOutput != null) { |
207 io.File file = new io.File(options.buildSummaryOutput); | 215 io.File file = new io.File(options.buildSummaryOutput); |
208 file.writeAsBytesSync(bundle.toBuffer(), mode: io.FileMode.WRITE_ONLY); | 216 file.writeAsBytesSync(bundle.toBuffer(), mode: io.FileMode.WRITE_ONLY); |
209 } | 217 } |
210 if (options.buildSummaryOutputSemantic != null) { | 218 if (options.buildSummaryOutputSemantic != null) { |
211 bundle.flushInformative(); | 219 bundle.flushInformative(); |
212 io.File file = new io.File(options.buildSummaryOutputSemantic); | 220 io.File file = new io.File(options.buildSummaryOutputSemantic); |
213 file.writeAsBytesSync(bundle.toBuffer(), mode: io.FileMode.WRITE_ONLY); | 221 file.writeAsBytesSync(bundle.toBuffer(), mode: io.FileMode.WRITE_ONLY); |
214 } | 222 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 * Serialize the package with the given [sources] into [assembler] using only | 351 * Serialize the package with the given [sources] into [assembler] using only |
344 * their ASTs and [LinkedUnit]s of input packages. | 352 * their ASTs and [LinkedUnit]s of input packages. |
345 */ | 353 */ |
346 void _serializeAstBasedSummary(List<Source> sources) { | 354 void _serializeAstBasedSummary(List<Source> sources) { |
347 Set<String> sourceUris = | 355 Set<String> sourceUris = |
348 sources.map((Source s) => s.uri.toString()).toSet(); | 356 sources.map((Source s) => s.uri.toString()).toSet(); |
349 | 357 |
350 LinkedLibrary _getDependency(String absoluteUri) => | 358 LinkedLibrary _getDependency(String absoluteUri) => |
351 summaryDataStore.linkedMap[absoluteUri]; | 359 summaryDataStore.linkedMap[absoluteUri]; |
352 | 360 |
353 UnlinkedUnit _getUnit(String absoluteUri) { | |
354 // Maybe an input package contains the source. | |
355 { | |
356 UnlinkedUnit unlinkedUnit = summaryDataStore.unlinkedMap[absoluteUri]; | |
357 if (unlinkedUnit != null) { | |
358 return unlinkedUnit; | |
359 } | |
360 } | |
361 // Parse the source and serialize its AST. | |
362 Uri uri = Uri.parse(absoluteUri); | |
363 Source source = context.sourceFactory.forUri2(uri); | |
364 if (!source.exists()) { | |
365 // TODO(paulberry): we should report a warning/error because DDC | |
366 // compilations are unlikely to work. | |
367 return null; | |
368 } | |
369 return uriToUnit.putIfAbsent(uri, () { | |
370 CompilationUnit unit = context.computeResult(source, PARSED_UNIT); | |
371 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit); | |
372 assembler.addUnlinkedUnit(source, unlinkedUnit); | |
373 return unlinkedUnit; | |
374 }); | |
375 } | |
376 | |
377 Map<String, LinkedLibraryBuilder> linkResult = link( | 361 Map<String, LinkedLibraryBuilder> linkResult = link( |
378 sourceUris, | 362 sourceUris, |
379 _getDependency, | 363 _getDependency, |
380 _getUnit, | 364 _unlinkedUnitForUri, |
381 context.declaredVariables.get, | 365 context.declaredVariables.get, |
382 options.strongMode); | 366 options.strongMode); |
383 linkResult.forEach(assembler.addLinkedLibrary); | 367 linkResult.forEach(assembler.addLinkedLibrary); |
384 } | 368 } |
369 | |
370 /** | |
371 * Returns the [UnlinkedUnit] for [absoluteUri], either by computing it or | |
372 * using the stored one in [uriToUnit]. | |
373 * | |
374 * If the [UnlinkedUnit] needed to be computed, it will also be added to the | |
jakemac
2017/04/04 16:44:46
I don't really like this behavior, but I don't see
Paul Berry
2017/04/04 18:30:30
Actually what I would prefer is if we just compute
jakemac
2017/04/04 19:21:06
Acknowledged.
| |
375 * [assembler]. | |
376 */ | |
377 UnlinkedUnit _unlinkedUnitForUri(String absoluteUri) { | |
378 // Maybe an input package contains the source. | |
379 { | |
380 UnlinkedUnit unlinkedUnit = summaryDataStore.unlinkedMap[absoluteUri]; | |
381 if (unlinkedUnit != null) { | |
382 return unlinkedUnit; | |
383 } | |
384 } | |
385 // Parse the source and serialize its AST. | |
386 Uri uri = Uri.parse(absoluteUri); | |
387 Source source = context.sourceFactory.forUri2(uri); | |
388 if (!source.exists()) { | |
389 // TODO(paulberry): we should report a warning/error because DDC | |
390 // compilations are unlikely to work. | |
391 return null; | |
392 } | |
393 return uriToUnit.putIfAbsent(uri, () { | |
394 CompilationUnit unit = context.computeResult(source, PARSED_UNIT); | |
395 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit); | |
396 assembler.addUnlinkedUnit(source, unlinkedUnit); | |
397 return unlinkedUnit; | |
398 }); | |
399 } | |
385 } | 400 } |
386 | 401 |
387 /** | 402 /** |
388 * Instances of the class [ExplicitSourceResolver] map URIs to files on disk | 403 * Instances of the class [ExplicitSourceResolver] map URIs to files on disk |
389 * using a fixed mapping provided at construction time. | 404 * using a fixed mapping provided at construction time. |
390 */ | 405 */ |
391 class ExplicitSourceResolver extends UriResolver { | 406 class ExplicitSourceResolver extends UriResolver { |
392 final Map<Uri, File> uriToFileMap; | 407 final Map<Uri, File> uriToFileMap; |
393 final Map<String, Uri> pathToUriMap; | 408 final Map<String, Uri> pathToUriMap; |
394 | 409 |
(...skipping 25 matching lines...) Expand all Loading... | |
420 * Build the inverse mapping of [uriToSourceMap]. | 435 * Build the inverse mapping of [uriToSourceMap]. |
421 */ | 436 */ |
422 static Map<String, Uri> _computePathToUriMap(Map<Uri, File> uriToSourceMap) { | 437 static Map<String, Uri> _computePathToUriMap(Map<Uri, File> uriToSourceMap) { |
423 Map<String, Uri> pathToUriMap = <String, Uri>{}; | 438 Map<String, Uri> pathToUriMap = <String, Uri>{}; |
424 uriToSourceMap.forEach((Uri uri, File file) { | 439 uriToSourceMap.forEach((Uri uri, File file) { |
425 pathToUriMap[file.path] = uri; | 440 pathToUriMap[file.path] = uri; |
426 }); | 441 }); |
427 return pathToUriMap; | 442 return pathToUriMap; |
428 } | 443 } |
429 } | 444 } |
OLD | NEW |