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/compiler_options.dart'; | 7 import 'package:front_end/compiler_options.dart'; |
8 import 'package:front_end/file_system.dart'; | 8 import 'package:front_end/file_system.dart'; |
9 import 'package:front_end/src/base/uri_resolver.dart'; | 9 import 'package:front_end/src/base/uri_resolver.dart'; |
10 import 'package:package_config/packages_file.dart' as package_config; | 10 import 'package:package_config/packages_file.dart' as package_config; |
(...skipping 21 matching lines...) Expand all Loading... |
32 /// Initializes a [ProcessedOptions] object wrapping the given [rawOptions]. | 32 /// Initializes a [ProcessedOptions] object wrapping the given [rawOptions]. |
33 ProcessedOptions(CompilerOptions rawOptions) : this._raw = rawOptions; | 33 ProcessedOptions(CompilerOptions rawOptions) : this._raw = rawOptions; |
34 | 34 |
35 /// Determine whether to generate code for the SDK when compiling a | 35 /// Determine whether to generate code for the SDK when compiling a |
36 /// whole-program. | 36 /// whole-program. |
37 bool get compileSdk => _raw.compileSdk; | 37 bool get compileSdk => _raw.compileSdk; |
38 | 38 |
39 /// Get the [FileSystem] which should be used by the front end to access | 39 /// Get the [FileSystem] which should be used by the front end to access |
40 /// files. | 40 /// files. |
41 /// | 41 /// |
42 /// If the client supplied bazel roots using [CompilerOptions.bazelRoots], the | 42 /// If the client supplied roots using [CompilerOptions.multiRoots], the |
43 /// returned [FileSystem] will automatically perform the appropriate mapping. | 43 /// returned [FileSystem] will automatically perform the appropriate mapping. |
44 FileSystem get fileSystem { | 44 FileSystem get fileSystem { |
45 // TODO(paulberry): support bazelRoots. | 45 // TODO(paulberry): support multiRoots. |
46 assert(_raw.bazelRoots.isEmpty); | 46 assert(_raw.multiRoots.isEmpty); |
47 return _raw.fileSystem; | 47 return _raw.fileSystem; |
48 } | 48 } |
49 | 49 |
50 /// Get the [UriResolver] which resolves "package:" and "dart:" URIs. | 50 /// Get the [UriResolver] which resolves "package:" and "dart:" URIs. |
51 /// | 51 /// |
52 /// This is an asynchronous getter since file system operations may be | 52 /// This is an asynchronous getter since file system operations may be |
53 /// required to locate/read the packages file as well as SDK metadata. | 53 /// required to locate/read the packages file as well as SDK metadata. |
54 Future<UriResolver> getUriResolver() async { | 54 Future<UriResolver> getUriResolver() async { |
55 if (_uriResolver == null) { | 55 if (_uriResolver == null) { |
56 await _getPackages(); | 56 await _getPackages(); |
57 var sdkLibraries = | 57 var sdkLibraries = |
58 <String, Uri>{}; // TODO(paulberry): support SDK libraries | 58 <String, Uri>{}; // TODO(paulberry): support SDK libraries |
59 _uriResolver = | 59 _uriResolver = new UriResolver(_packages, sdkLibraries); |
60 new UriResolver(_packages, sdkLibraries, fileSystem.context); | |
61 } | 60 } |
62 return _uriResolver; | 61 return _uriResolver; |
63 } | 62 } |
64 | 63 |
65 /// Get the package map which maps package names to URIs. | 64 /// Get the package map which maps package names to URIs. |
66 /// | 65 /// |
67 /// This is an asynchronous getter since file system operations may be | 66 /// This is an asynchronous getter since file system operations may be |
68 /// required to locate/read the packages file. | 67 /// required to locate/read the packages file. |
69 Future<Map<String, Uri>> _getPackages() async { | 68 Future<Map<String, Uri>> _getPackages() async { |
70 if (_packages == null) { | 69 if (_packages == null) { |
71 if (_raw.packagesFilePath == null) { | 70 if (_raw.packagesFileUri == null) { |
72 throw new UnimplementedError(); // TODO(paulberry): search for .packages | 71 throw new UnimplementedError(); // TODO(paulberry): search for .packages |
73 } else if (_raw.packagesFilePath.isEmpty) { | 72 } else if (_raw.packagesFileUri.path.isEmpty) { |
74 _packages = {}; | 73 _packages = {}; |
75 } else { | 74 } else { |
76 var contents = | 75 var contents = |
77 await fileSystem.entityForPath(_raw.packagesFilePath).readAsBytes(); | 76 await fileSystem.entityForUri(_raw.packagesFileUri).readAsBytes(); |
78 var baseLocation = fileSystem.context.toUri(_raw.packagesFilePath); | 77 _packages = package_config.parse(contents, _raw.packagesFileUri); |
79 _packages = package_config.parse(contents, baseLocation); | |
80 } | 78 } |
81 } | 79 } |
82 return _packages; | 80 return _packages; |
83 } | 81 } |
84 } | 82 } |
OLD | NEW |