Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:front_end/compilation_message.dart'; | 7 import 'package:front_end/compilation_message.dart'; |
| 8 import 'package:front_end/compiler_options.dart'; | 8 import 'package:front_end/compiler_options.dart'; |
| 9 import 'package:front_end/file_system.dart'; | 9 import 'package:front_end/file_system.dart'; |
| 10 import 'package:front_end/src/base/performace_logger.dart'; | 10 import 'package:front_end/src/base/performace_logger.dart'; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 import 'package:kernel/target/targets.dart'; | 21 import 'package:kernel/target/targets.dart'; |
| 22 import 'package:kernel/target/vm_fasta.dart'; | 22 import 'package:kernel/target/vm_fasta.dart'; |
| 23 import 'package:package_config/packages.dart' show Packages; | 23 import 'package:package_config/packages.dart' show Packages; |
| 24 import 'package:package_config/src/packages_impl.dart' | 24 import 'package:package_config/src/packages_impl.dart' |
| 25 show NonFilePackagesDirectoryPackages, MapPackages; | 25 show NonFilePackagesDirectoryPackages, MapPackages; |
| 26 import 'package:package_config/packages_file.dart' as package_config; | 26 import 'package:package_config/packages_file.dart' as package_config; |
| 27 import 'package:source_span/source_span.dart' show SourceSpan, SourceLocation; | 27 import 'package:source_span/source_span.dart' show SourceSpan, SourceLocation; |
| 28 import 'package:front_end/src/fasta/command_line_reporting.dart' | 28 import 'package:front_end/src/fasta/command_line_reporting.dart' |
| 29 as command_line_reporting; | 29 as command_line_reporting; |
| 30 | 30 |
| 31 import 'libraries_spec.dart'; | |
| 32 | |
| 31 /// All options needed for the front end implementation. | 33 /// All options needed for the front end implementation. |
| 32 /// | 34 /// |
| 33 /// This includes: all of [CompilerOptions] in a form useful to the | 35 /// This includes: all of [CompilerOptions] in a form useful to the |
| 34 /// implementation, default values for options that were not provided, | 36 /// implementation, default values for options that were not provided, |
| 35 /// and information derived from how the compiler was invoked (like the | 37 /// and information derived from how the compiler was invoked (like the |
| 36 /// entry-points given to the compiler and whether a modular or whole-program | 38 /// entry-points given to the compiler and whether a modular or whole-program |
| 37 /// API was used). | 39 /// API was used). |
| 38 /// | 40 /// |
| 39 /// The intent is that the front end should immediately wrap any incoming | 41 /// The intent is that the front end should immediately wrap any incoming |
| 40 /// [CompilerOptions] object in this class before doing further processing, and | 42 /// [CompilerOptions] object in this class before doing further processing, and |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 69 /// includes inferred types. | 71 /// includes inferred types. |
| 70 List<Program> _inputSummariesPrograms; | 72 List<Program> _inputSummariesPrograms; |
| 71 | 73 |
| 72 /// Other programs that are meant to be linked and compiled with the input | 74 /// Other programs that are meant to be linked and compiled with the input |
| 73 /// sources. | 75 /// sources. |
| 74 List<Program> _linkedDependencies; | 76 List<Program> _linkedDependencies; |
| 75 | 77 |
| 76 /// The location of the SDK, or `null` if the location hasn't been determined | 78 /// The location of the SDK, or `null` if the location hasn't been determined |
| 77 /// yet. | 79 /// yet. |
| 78 Uri _sdkRoot; | 80 Uri _sdkRoot; |
| 79 Uri get sdkRoot => _sdkRoot ??= _normalizeSdkRoot(); | 81 Uri get sdkRoot { |
| 82 _ensureSdkDefaults(); | |
| 83 return _sdkRoot; | |
| 84 } | |
| 80 | 85 |
| 81 Uri _sdkSummary; | 86 Uri _sdkSummary; |
| 82 Uri get sdkSummary => _sdkSummary ??= _computeSdkSummaryUri(); | 87 Uri get sdkSummary { |
| 88 _ensureSdkDefaults(); | |
| 89 return _sdkSummary; | |
| 90 } | |
| 91 | |
| 92 Uri _librariesSpecUri; | |
| 93 Uri get librariesSpecUri { | |
| 94 _ensureSdkDefaults(); | |
| 95 return _librariesSpecUri; | |
| 96 } | |
| 83 | 97 |
| 84 Ticker ticker; | 98 Ticker ticker; |
| 85 | 99 |
| 86 bool get verbose => _raw.verbose; | 100 bool get verbose => _raw.verbose; |
| 87 | 101 |
| 88 bool get verify => _raw.verify; | 102 bool get verify => _raw.verify; |
| 89 | 103 |
| 90 bool get debugDump => _raw.debugDump; | 104 bool get debugDump => _raw.debugDump; |
| 91 | 105 |
| 92 bool get setExitCodeOnProblem => _raw.setExitCodeOnProblem; | 106 bool get setExitCodeOnProblem => _raw.setExitCodeOnProblem; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 Program loadProgram(List<int> bytes, CanonicalName nameRoot) { | 281 Program loadProgram(List<int> bytes, CanonicalName nameRoot) { |
| 268 return loadProgramFromBytes(bytes, new Program(nameRoot: nameRoot)); | 282 return loadProgramFromBytes(bytes, new Program(nameRoot: nameRoot)); |
| 269 } | 283 } |
| 270 | 284 |
| 271 /// Get the [UriTranslator] which resolves "package:" and "dart:" URIs. | 285 /// Get the [UriTranslator] which resolves "package:" and "dart:" URIs. |
| 272 /// | 286 /// |
| 273 /// This is an asynchronous method since file system operations may be | 287 /// This is an asynchronous method since file system operations may be |
| 274 /// required to locate/read the packages file as well as SDK metadata. | 288 /// required to locate/read the packages file as well as SDK metadata. |
| 275 Future<UriTranslatorImpl> getUriTranslator() async { | 289 Future<UriTranslatorImpl> getUriTranslator() async { |
| 276 if (_uriTranslator == null) { | 290 if (_uriTranslator == null) { |
| 277 await _getPackages(); | 291 var libraries = await _computeLibrarySpecification(); |
| 278 // TODO(scheglov) Load SDK libraries from whatever format we decide. | 292 ticker.logMs("Read libraries file"); |
|
ahe
2017/08/03 11:58:16
You need to make sure you know precisely when tick
Paul Berry
2017/08/03 17:50:41
It seems like you're suggesting a flow where the c
Siggi Cherem (dart-lang)
2017/08/05 00:41:02
Done. Added the extra tick as Paul suggested.
ahe
2017/08/07 22:12:04
I don't think that will work. This will print some
| |
| 279 // TODO(scheglov) Remove the field "_raw.dartLibraries". | 293 var packages = await _getPackages(); |
| 280 var libraries = _raw.dartLibraries ?? await _parseDartLibraries(); | |
| 281 _uriTranslator = new UriTranslatorImpl( | |
| 282 libraries, const <String, List<Uri>>{}, _packages); | |
| 283 ticker.logMs("Read packages file"); | 294 ticker.logMs("Read packages file"); |
| 295 _uriTranslator = new UriTranslatorImpl(libraries, packages); | |
| 284 } | 296 } |
| 285 return _uriTranslator; | 297 return _uriTranslator; |
| 286 } | 298 } |
| 287 | 299 |
| 288 Future<Map<String, Uri>> _parseDartLibraries() async { | 300 Future<TargetLibrariesSpecification> _computeLibrarySpecification() async { |
| 289 Uri librariesJson = _raw.sdkRoot?.resolve("lib/libraries.json"); | 301 var name = target.name; |
| 290 return await computeDartLibraries(fileSystem, librariesJson); | 302 // TODO(sigmund): eek! we should get to the point where there is no |
|
ahe
2017/08/03 11:58:16
Eek (uppercase).
We (uppercase).
Siggi Cherem (dart-lang)
2017/08/05 00:41:02
EEK! OK :)
| |
| 303 // fasta-specific targets and the target names are meaningful. | |
| 304 if (name.endsWith('_fasta')) name = name.substring(0, name.length - 6); | |
| 305 | |
| 306 if (librariesSpecUri == null || | |
|
ahe
2017/08/03 11:58:15
This field should be named librariesSpecificationU
Siggi Cherem (dart-lang)
2017/08/05 00:41:02
Done.
| |
| 307 !await fileSystem.entityForUri(librariesSpecUri).exists()) { | |
| 308 if (compileSdk) { | |
| 309 reportWithoutLocation( | |
| 310 templateSdkSpecificationNotFound.withArguments(librariesSpecUri), | |
| 311 Severity.error); | |
| 312 } | |
| 313 return new TargetLibrariesSpecification(name); | |
| 314 } | |
| 315 | |
| 316 var json = await fileSystem.entityForUri(librariesSpecUri).readAsString(); | |
| 317 var spec = await LibrariesSpecification.parse(librariesSpecUri, json); | |
| 318 return spec.specificationFor(name); | |
| 291 } | 319 } |
| 292 | 320 |
| 293 /// Get the package map which maps package names to URIs. | 321 /// Get the package map which maps package names to URIs. |
| 294 /// | 322 /// |
| 295 /// This is an asynchronous getter since file system operations may be | 323 /// This is an asynchronous getter since file system operations may be |
| 296 /// required to locate/read the packages file. | 324 /// required to locate/read the packages file. |
| 297 Future<Packages> _getPackages() async { | 325 Future<Packages> _getPackages() async { |
| 298 if (_packages != null) return _packages; | 326 if (_packages != null) return _packages; |
| 299 if (_raw.packagesFileUri != null) { | 327 if (_raw.packagesFileUri != null) { |
| 300 return _packages = await createPackagesFromFile(_raw.packagesFileUri); | 328 return _packages = await createPackagesFromFile(_raw.packagesFileUri); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 candidate = await checkInDir(parentDir); | 419 candidate = await checkInDir(parentDir); |
| 392 if (candidate != null) break; | 420 if (candidate != null) break; |
| 393 dir = parentDir; | 421 dir = parentDir; |
| 394 parentDir = dir.resolve('..'); | 422 parentDir = dir.resolve('..'); |
| 395 } | 423 } |
| 396 | 424 |
| 397 if (candidate != null) return createPackagesFromFile(candidate); | 425 if (candidate != null) return createPackagesFromFile(candidate); |
| 398 return Packages.noPackages; | 426 return Packages.noPackages; |
| 399 } | 427 } |
| 400 | 428 |
| 401 /// Get the location of the SDK. | 429 bool _computedSdkDefaults = false; |
| 402 Uri _normalizeSdkRoot() { | 430 |
| 403 // If an SDK summary location was provided, the SDK itself should not be | 431 /// Ensure [_sdkRoot], [_sdkSummary] and [_librarySpecUri] are initialized. |
| 404 // needed. | 432 /// |
| 405 assert(_raw.sdkSummary == null); | 433 /// If they are not set explicitly, they are infered based on the default |
| 406 if (_raw.sdkRoot == null) { | 434 /// behavior described in [CompilerOptions]. |
| 435 void _ensureSdkDefaults() { | |
| 436 if (_computedSdkDefaults) return; | |
| 437 _computedSdkDefaults = true; | |
| 438 var root = _raw.sdkRoot; | |
| 439 if (root != null) { | |
| 440 // Normalize to always end in '/' | |
| 441 if (!root.path.endsWith('/')) { | |
| 442 root = root.replace(path: root.path + '/'); | |
| 443 } | |
| 444 _sdkRoot = root; | |
| 445 } else if (compileSdk) { | |
| 407 // TODO(paulberry): implement the algorithm for finding the SDK | 446 // TODO(paulberry): implement the algorithm for finding the SDK |
| 408 // automagically. | 447 // automagically. |
| 409 return unimplemented('infer the default sdk location', -1, null); | 448 unimplemented('infer the default sdk location', -1, null); |
| 410 } | 449 } |
| 411 var root = _raw.sdkRoot; | 450 |
| 412 if (!root.path.endsWith('/')) { | 451 if (_raw.sdkSummary != null) { |
| 413 root = root.replace(path: root.path + '/'); | 452 _sdkSummary = _raw.sdkSummary; |
| 453 } else if (!compileSdk) { | |
| 454 // Infer based on the sdkRoot, but only when `compileSdk` is false, | |
| 455 // otherwise the default intent was to compile the sdk from sources and | |
| 456 // not to load an sdk summary file. | |
| 457 _sdkSummary = root?.resolve('outline.dill'); | |
| 414 } | 458 } |
| 415 return root; | |
| 416 } | |
| 417 | 459 |
| 418 /// Get or infer the location of the SDK summary. | 460 if (_raw.librariesSpecUri != null) { |
| 419 Uri _computeSdkSummaryUri() { | 461 _librariesSpecUri = _raw.librariesSpecUri; |
| 420 if (_raw.sdkSummary != null) return _raw.sdkSummary; | 462 } else if (compileSdk) { |
| 421 | 463 _librariesSpecUri = sdkRoot.resolve('lib/libraries.json'); |
| 422 // Infer based on the sdkRoot, but only when `compileSdk` is false, | 464 } |
| 423 // otherwise the default intent was to compile the sdk from sources and not | |
| 424 // to load an sdk summary file. | |
| 425 if (_raw.compileSdk) return null; | |
| 426 return sdkRoot.resolve('outline.dill'); | |
| 427 } | 465 } |
| 428 | 466 |
| 429 /// Create a [FileSystem] specific to the current options. | 467 /// Create a [FileSystem] specific to the current options. |
| 430 /// | 468 /// |
| 431 /// If `_raw.multiRoots` is not empty, the file-system will implement the | 469 /// If `_raw.multiRoots` is not empty, the file-system will implement the |
| 432 /// semantics of multiple roots. If [chaseDependencies] is false, the | 470 /// semantics of multiple roots. If [chaseDependencies] is false, the |
| 433 /// resulting file system will be hermetic. | 471 /// resulting file system will be hermetic. |
| 434 FileSystem _createFileSystem() { | 472 FileSystem _createFileSystem() { |
| 435 var result = _raw.fileSystem; | 473 var result = _raw.fileSystem; |
| 436 // Note: hermetic checks are done before translating multi-root URIs, so | 474 // Note: hermetic checks are done before translating multi-root URIs, so |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 writeList('Multiroots', _raw.multiRoots); | 525 writeList('Multiroots', _raw.multiRoots); |
| 488 | 526 |
| 489 sb.writeln('Modular: ${_modularApi}'); | 527 sb.writeln('Modular: ${_modularApi}'); |
| 490 sb.writeln('Hermetic: ${!chaseDependencies}' | 528 sb.writeln('Hermetic: ${!chaseDependencies}' |
| 491 ' (provided: ${!_raw.chaseDependencies})'); | 529 ' (provided: ${!_raw.chaseDependencies})'); |
| 492 sb.writeln('Packages uri: ${_raw.packagesFileUri}'); | 530 sb.writeln('Packages uri: ${_raw.packagesFileUri}'); |
| 493 sb.writeln('Packages: ${_packages}'); | 531 sb.writeln('Packages: ${_packages}'); |
| 494 | 532 |
| 495 sb.writeln('Compile SDK: ${compileSdk}'); | 533 sb.writeln('Compile SDK: ${compileSdk}'); |
| 496 sb.writeln('SDK root: ${_sdkRoot} (provided: ${_raw.sdkRoot})'); | 534 sb.writeln('SDK root: ${_sdkRoot} (provided: ${_raw.sdkRoot})'); |
| 535 sb.writeln('SDK specification: ${_librariesSpecUri} ' | |
| 536 '(provided: ${_raw.librariesSpecUri})'); | |
| 497 sb.writeln('SDK summary: ${_sdkSummary} (provided: ${_raw.sdkSummary})'); | 537 sb.writeln('SDK summary: ${_sdkSummary} (provided: ${_raw.sdkSummary})'); |
| 498 | 538 |
| 499 sb.writeln('Strong: ${strongMode}'); | 539 sb.writeln('Strong: ${strongMode}'); |
| 500 sb.writeln('Target: ${_target?.name} (provided: ${_raw.target?.name})'); | 540 sb.writeln('Target: ${_target?.name} (provided: ${_raw.target?.name})'); |
| 501 | 541 |
| 502 sb.writeln('throwOnErrorsAreFatal: ${throwOnErrors}'); | 542 sb.writeln('throwOnErrorsAreFatal: ${throwOnErrors}'); |
| 503 sb.writeln('throwOnWarningsAreFatal: ${throwOnWarnings}'); | 543 sb.writeln('throwOnWarningsAreFatal: ${throwOnWarnings}'); |
| 504 sb.writeln('throwOnNits: ${throwOnNits}'); | 544 sb.writeln('throwOnNits: ${throwOnNits}'); |
| 505 sb.writeln('exit on problem: ${setExitCodeOnProblem}'); | 545 sb.writeln('exit on problem: ${setExitCodeOnProblem}'); |
| 506 sb.writeln('Embed sources: ${embedSourceText}'); | 546 sb.writeln('Embed sources: ${embedSourceText}'); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 String get dart2jsCode => _original.code.dart2jsCode; | 591 String get dart2jsCode => _original.code.dart2jsCode; |
| 552 | 592 |
| 553 SourceSpan get span => | 593 SourceSpan get span => |
| 554 new SourceLocation(_original.charOffset, sourceUrl: _original.uri) | 594 new SourceLocation(_original.charOffset, sourceUrl: _original.uri) |
| 555 .pointSpan(); | 595 .pointSpan(); |
| 556 | 596 |
| 557 _CompilationMessage(this._original, this.severity); | 597 _CompilationMessage(this._original, this.severity); |
| 558 | 598 |
| 559 String toString() => message; | 599 String toString() => message; |
| 560 } | 600 } |
| OLD | NEW |