| 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:kernel/target/targets.dart'; | 7 import 'package:kernel/target/targets.dart'; |
| 8 import 'package:kernel/target/vm_fasta.dart'; | 8 import 'package:kernel/target/vm_fasta.dart'; |
| 9 import 'package:front_end/compiler_options.dart'; | 9 import 'package:front_end/compiler_options.dart'; |
| 10 import 'package:front_end/file_system.dart'; | 10 import 'package:front_end/file_system.dart'; |
| 11 import 'package:front_end/src/base/performace_logger.dart'; |
| 12 import 'package:front_end/src/fasta/errors.dart'; |
| 13 import 'package:front_end/src/fasta/ticker.dart'; |
| 11 import 'package:front_end/src/fasta/translate_uri.dart'; | 14 import 'package:front_end/src/fasta/translate_uri.dart'; |
| 12 import 'package:front_end/src/fasta/ticker.dart'; | |
| 13 import 'package:front_end/src/fasta/errors.dart'; | |
| 14 import 'package:front_end/src/base/performace_logger.dart'; | |
| 15 import 'package:front_end/src/incremental/byte_store.dart'; | 15 import 'package:front_end/src/incremental/byte_store.dart'; |
| 16 import 'package:front_end/src/multi_root_file_system.dart'; |
| 16 import 'package:front_end/src/simple_error.dart'; | 17 import 'package:front_end/src/simple_error.dart'; |
| 17 import 'package:package_config/packages_file.dart' as package_config; | 18 import 'package:package_config/packages_file.dart' as package_config; |
| 18 import 'package:kernel/kernel.dart' | 19 import 'package:kernel/kernel.dart' |
| 19 show Program, loadProgramFromBytes, CanonicalName; | 20 show Program, loadProgramFromBytes, CanonicalName; |
| 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 |
| 24 /// implementation, default values for options that were not provided, | 25 /// implementation, default values for options that were not provided, |
| 25 /// and information derived from how the compiler was invoked (like the | 26 /// and information derived from how the compiler was invoked (like the |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 272 |
| 272 // Infer based on the sdkRoot, but only when `compileSdk` is false, | 273 // Infer based on the sdkRoot, but only when `compileSdk` is false, |
| 273 // otherwise the default intent was to compile the sdk from sources and not | 274 // otherwise the default intent was to compile the sdk from sources and not |
| 274 // to load an sdk summary file. | 275 // to load an sdk summary file. |
| 275 if (_raw.compileSdk) return null; | 276 if (_raw.compileSdk) return null; |
| 276 return sdkRoot.resolve('outline.dill'); | 277 return sdkRoot.resolve('outline.dill'); |
| 277 } | 278 } |
| 278 | 279 |
| 279 /// Create a [FileSystem] specific to the current options. | 280 /// Create a [FileSystem] specific to the current options. |
| 280 /// | 281 /// |
| 281 /// If [chaseDependencies] is false, the resulting file system will be | 282 /// If `_raw.multiRoots` is not empty, the file-system will implement the |
| 282 /// hermetic. | 283 /// semantics of multiple roots. If [chaseDependencies] is false, the |
| 284 /// resulting file system will be hermetic. |
| 283 FileSystem _createFileSystem() { | 285 FileSystem _createFileSystem() { |
| 284 var result = _raw.fileSystem; | 286 var result = _raw.fileSystem; |
| 287 // Note: hermetic checks are done before translating multi-root URIs, so |
| 288 // the order in which we create the file systems below is relevant. |
| 289 if (!_raw.multiRoots.isEmpty) { |
| 290 result = new MultiRootFileSystem('multi-root', _raw.multiRoots, result); |
| 291 } |
| 285 if (!chaseDependencies) { | 292 if (!chaseDependencies) { |
| 286 var allInputs = inputs.toSet(); | 293 var allInputs = inputs.toSet(); |
| 287 allInputs.addAll(_raw.inputSummaries); | 294 allInputs.addAll(_raw.inputSummaries); |
| 288 allInputs.addAll(_raw.linkedDependencies); | 295 allInputs.addAll(_raw.linkedDependencies); |
| 289 | 296 |
| 290 if (sdkSummary != null) allInputs.add(sdkSummary); | 297 if (sdkSummary != null) allInputs.add(sdkSummary); |
| 291 | 298 |
| 292 if (_raw.sdkRoot != null) { | 299 if (_raw.sdkRoot != null) { |
| 293 // TODO(sigmund): refine this, we should be more explicit about when | 300 // TODO(sigmund): refine this, we should be more explicit about when |
| 294 // sdkRoot and libraries.json are allowed to be used. | 301 // sdkRoot and libraries.json are allowed to be used. |
| 295 allInputs.add(sdkRoot); | 302 allInputs.add(sdkRoot); |
| 296 allInputs.add(sdkRoot.resolve("lib/libraries.json")); | 303 allInputs.add(sdkRoot.resolve("lib/libraries.json")); |
| 297 } | 304 } |
| 298 | 305 |
| 299 /// Note: Searching the file-system for the package-config is not | 306 /// Note: Searching the file-system for the package-config is not |
| 300 /// supported in hermetic builds. | 307 /// supported in hermetic builds. |
| 301 if (_raw.packagesFileUri != null) allInputs.add(_raw.packagesFileUri); | 308 if (_raw.packagesFileUri != null) allInputs.add(_raw.packagesFileUri); |
| 302 result = new HermeticFileSystem(allInputs, result); | 309 result = new HermeticFileSystem(allInputs, result); |
| 303 } | 310 } |
| 304 // TODO(paulberry): support multiRoots. | |
| 305 assert(_raw.multiRoots.isEmpty); | |
| 306 return result; | 311 return result; |
| 307 } | 312 } |
| 308 } | 313 } |
| 309 | 314 |
| 310 /// A [FileSystem] that only allows access to files that have been explicitly | 315 /// A [FileSystem] that only allows access to files that have been explicitly |
| 311 /// whitelisted. | 316 /// whitelisted. |
| 312 class HermeticFileSystem implements FileSystem { | 317 class HermeticFileSystem implements FileSystem { |
| 313 final Set<Uri> includedFiles; | 318 final Set<Uri> includedFiles; |
| 314 final FileSystem _realFileSystem; | 319 final FileSystem _realFileSystem; |
| 315 | 320 |
| 316 HermeticFileSystem(this.includedFiles, this._realFileSystem); | 321 HermeticFileSystem(this.includedFiles, this._realFileSystem); |
| 317 | 322 |
| 318 FileSystemEntity entityForUri(Uri uri) { | 323 FileSystemEntity entityForUri(Uri uri) { |
| 319 if (includedFiles.contains(uri)) return _realFileSystem.entityForUri(uri); | 324 if (includedFiles.contains(uri)) return _realFileSystem.entityForUri(uri); |
| 320 return inputError( | 325 return inputError( |
| 321 null, | 326 null, |
| 322 -1, | 327 -1, |
| 323 'Invalid access to $uri: ' | 328 'Invalid access to $uri: ' |
| 324 'the file is accessed in a modular hermetic build ' | 329 'the file is accessed in a modular hermetic build ' |
| 325 '(where chaseDependencies is false), but it was not ' | 330 '(where chaseDependencies is false), but it was not ' |
| 326 'explicitly listed as an input.'); | 331 'explicitly listed as an input.'); |
| 327 } | 332 } |
| 328 } | 333 } |
| OLD | NEW |