Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: pkg/front_end/lib/src/base/processed_options.dart

Issue 2618633006: Create a wrapper class to handle CompilerOptions in a uniform way. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:async';
6
7 import 'package:front_end/compiler_options.dart';
8 import 'package:front_end/file_system.dart';
9 import 'package:front_end/src/base/uri_resolver.dart';
10 import 'package:package_config/packages_file.dart' as package_config;
11
12 /// Wrapper around [CompilerOptions] which exposes the options in a form useful
13 /// to the front end implementation.
14 ///
15 /// The intent is that the front end should immediately wrap any incoming
16 /// [CompilerOptions] object in this class before doing further processing, and
17 /// should thereafter access all options via the wrapper. This ensures that
18 /// options are interpreted in a consistent way and that data derived from
19 /// options is not unnecessarily recomputed.
20 class ProcessedOptions {
21 /// The raw [CompilerOptions] which this class wraps.
22 final CompilerOptions _raw;
23
24 /// The package map derived from the options, or `null` if the package map has
25 /// not been computed yet.
26 Map<String, Uri> _packages;
27
28 /// A URI resolver based on the options, or `null` if the URI resolver has not
29 /// been computed yet.
30 UriResolver _uriResolver;
31
32 /// Initializes a [ProcessedOptions] object wrapping the given [rawOptions].
33 ProcessedOptions(CompilerOptions rawOptions) : this._raw = rawOptions;
34
35 /// Determine whether to generate code for the SDK when compiling a
36 /// whole-program.
37 bool get compileSdk => _raw.compileSdk;
38
39 /// Get the [FileSystem] which should be used by the front end to access
40 /// files.
41 ///
42 /// If the client supplied bazel roots using [CompilerOptions.bazelRoots], the
43 /// returned [FileSystem] will automatically perform the appropriate mapping.
44 FileSystem get fileSystem {
45 // TODO(paulberry): support bazelRoots.
46 assert(_raw.bazelRoots.isEmpty);
47 return _raw.fileSystem;
48 }
49
50 /// Get the [UriResolver] which resolves "package:" and "dart:" URIs.
51 ///
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.
54 Future<UriResolver> getUriResolver() async {
55 if (_uriResolver == null) {
56 await _getPackages();
57 var sdkLibraries =
58 <String, Uri>{}; // TODO(paulberry): support SDK libraries
59 _uriResolver =
60 new UriResolver(_packages, sdkLibraries, fileSystem.context);
61 }
62 return _uriResolver;
63 }
64
65 /// Get the package map which maps package names to URIs.
66 ///
67 /// This is an asynchronous getter since file system operations may be
68 /// required to locate/read the packages file.
69 Future<Map<String, Uri>> _getPackages() async {
70 if (_packages == null) {
71 if (_raw.packagesFilePath == null) {
72 throw new UnimplementedError(); // TODO(paulberry): search for .packages
73 } else if (_raw.packagesFilePath.isEmpty) {
74 _packages = {};
75 } else {
76 var contents =
77 await fileSystem.entityForPath(_raw.packagesFilePath).readAsBytes();
78 var baseLocation = fileSystem.context.toUri(_raw.packagesFilePath);
79 _packages = package_config.parse(contents, baseLocation);
80 }
81 }
82 return _packages;
83 }
84 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/dependency_grapher.dart ('k') | pkg/front_end/test/src/base/processed_options_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698