| 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_error.dart'; | 7 import 'package:front_end/compilation_error.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'; |
| 11 import 'package:front_end/src/fasta/ticker.dart'; | 11 import 'package:front_end/src/fasta/ticker.dart'; |
| 12 import 'package:front_end/src/fasta/translate_uri.dart'; | 12 import 'package:front_end/src/fasta/translate_uri.dart'; |
| 13 import 'package:front_end/src/incremental/byte_store.dart'; | 13 import 'package:front_end/src/incremental/byte_store.dart'; |
| 14 import 'package:front_end/src/multi_root_file_system.dart'; |
| 14 import 'package:kernel/kernel.dart' | 15 import 'package:kernel/kernel.dart' |
| 15 show Program, loadProgramFromBytes, CanonicalName; | 16 show Program, loadProgramFromBytes, CanonicalName; |
| 16 import 'package:kernel/target/targets.dart'; | 17 import 'package:kernel/target/targets.dart'; |
| 17 import 'package:kernel/target/vm_fasta.dart'; | 18 import 'package:kernel/target/vm_fasta.dart'; |
| 18 import 'package:package_config/packages_file.dart' as package_config; | 19 import 'package:package_config/packages_file.dart' as package_config; |
| 19 import 'package:source_span/source_span.dart' show SourceSpan; | 20 import 'package:source_span/source_span.dart' show SourceSpan; |
| 20 | 21 |
| 21 /// All options needed for the front end implementation. | 22 /// All options needed for the front end implementation. |
| 22 /// | 23 /// |
| 23 /// This includes: all of [CompilerOptions] in a form useful to the | 24 /// This includes: all of [CompilerOptions] in a form useful to the |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 277 |
| 277 // Infer based on the sdkRoot, but only when `compileSdk` is false, | 278 // Infer based on the sdkRoot, but only when `compileSdk` is false, |
| 278 // otherwise the default intent was to compile the sdk from sources and not | 279 // otherwise the default intent was to compile the sdk from sources and not |
| 279 // to load an sdk summary file. | 280 // to load an sdk summary file. |
| 280 if (_raw.compileSdk) return null; | 281 if (_raw.compileSdk) return null; |
| 281 return sdkRoot.resolve('outline.dill'); | 282 return sdkRoot.resolve('outline.dill'); |
| 282 } | 283 } |
| 283 | 284 |
| 284 /// Create a [FileSystem] specific to the current options. | 285 /// Create a [FileSystem] specific to the current options. |
| 285 /// | 286 /// |
| 286 /// If [chaseDependencies] is false, the resulting file system will be | 287 /// If `_raw.multiRoots` is not empty, the file-system will implement the |
| 287 /// hermetic. | 288 /// semantics of multiple roots. If [chaseDependencies] is false, the |
| 289 /// resulting file system will be hermetic. |
| 288 FileSystem _createFileSystem() { | 290 FileSystem _createFileSystem() { |
| 289 var result = _raw.fileSystem; | 291 var result = _raw.fileSystem; |
| 292 // Note: hermetic checks are done before translating multi-root URIs, so |
| 293 // the order in which we create the file systems below is relevant. |
| 294 if (!_raw.multiRoots.isEmpty) { |
| 295 result = new MultiRootFileSystem('multi-root', _raw.multiRoots, result); |
| 296 } |
| 290 if (!chaseDependencies) { | 297 if (!chaseDependencies) { |
| 291 var allInputs = inputs.toSet(); | 298 var allInputs = inputs.toSet(); |
| 292 allInputs.addAll(_raw.inputSummaries); | 299 allInputs.addAll(_raw.inputSummaries); |
| 293 allInputs.addAll(_raw.linkedDependencies); | 300 allInputs.addAll(_raw.linkedDependencies); |
| 294 | 301 |
| 295 if (sdkSummary != null) allInputs.add(sdkSummary); | 302 if (sdkSummary != null) allInputs.add(sdkSummary); |
| 296 | 303 |
| 297 if (_raw.sdkRoot != null) { | 304 if (_raw.sdkRoot != null) { |
| 298 // TODO(sigmund): refine this, we should be more explicit about when | 305 // TODO(sigmund): refine this, we should be more explicit about when |
| 299 // sdkRoot and libraries.json are allowed to be used. | 306 // sdkRoot and libraries.json are allowed to be used. |
| 300 allInputs.add(sdkRoot); | 307 allInputs.add(sdkRoot); |
| 301 allInputs.add(sdkRoot.resolve("lib/libraries.json")); | 308 allInputs.add(sdkRoot.resolve("lib/libraries.json")); |
| 302 } | 309 } |
| 303 | 310 |
| 304 /// Note: Searching the file-system for the package-config is not | 311 /// Note: Searching the file-system for the package-config is not |
| 305 /// supported in hermetic builds. | 312 /// supported in hermetic builds. |
| 306 if (_raw.packagesFileUri != null) allInputs.add(_raw.packagesFileUri); | 313 if (_raw.packagesFileUri != null) allInputs.add(_raw.packagesFileUri); |
| 307 result = new HermeticFileSystem(allInputs, result); | 314 result = new HermeticFileSystem(allInputs, result); |
| 308 } | 315 } |
| 309 // TODO(paulberry): support multiRoots. | |
| 310 assert(_raw.multiRoots.isEmpty); | |
| 311 return result; | 316 return result; |
| 312 } | 317 } |
| 313 } | 318 } |
| 314 | 319 |
| 315 /// A [FileSystem] that only allows access to files that have been explicitly | 320 /// A [FileSystem] that only allows access to files that have been explicitly |
| 316 /// whitelisted. | 321 /// whitelisted. |
| 317 class HermeticFileSystem implements FileSystem { | 322 class HermeticFileSystem implements FileSystem { |
| 318 final Set<Uri> includedFiles; | 323 final Set<Uri> includedFiles; |
| 319 final FileSystem _realFileSystem; | 324 final FileSystem _realFileSystem; |
| 320 | 325 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 340 | 345 |
| 341 /// An error that only contains a message and no error location. | 346 /// An error that only contains a message and no error location. |
| 342 class _CompilationError implements CompilationError { | 347 class _CompilationError implements CompilationError { |
| 343 String get correction => null; | 348 String get correction => null; |
| 344 SourceSpan get span => null; | 349 SourceSpan get span => null; |
| 345 final String message; | 350 final String message; |
| 346 _CompilationError(this.message); | 351 _CompilationError(this.message); |
| 347 | 352 |
| 348 String toString() => message; | 353 String toString() => message; |
| 349 } | 354 } |
| OLD | NEW |