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

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

Issue 2625533002: Add code to ProcessedOptions to fetch the SDK summary bundle. (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
« no previous file with comments | « no previous file | pkg/front_end/test/src/base/processed_options_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:analyzer/src/summary/idl.dart';
7 import 'package:front_end/compiler_options.dart'; 8 import 'package:front_end/compiler_options.dart';
8 import 'package:front_end/file_system.dart'; 9 import 'package:front_end/file_system.dart';
9 import 'package:front_end/src/base/uri_resolver.dart'; 10 import 'package:front_end/src/base/uri_resolver.dart';
10 import 'package:package_config/packages_file.dart' as package_config; 11 import 'package:package_config/packages_file.dart' as package_config;
11 12
12 /// Wrapper around [CompilerOptions] which exposes the options in a form useful 13 /// Wrapper around [CompilerOptions] which exposes the options in a form useful
13 /// to the front end implementation. 14 /// to the front end implementation.
14 /// 15 ///
15 /// The intent is that the front end should immediately wrap any incoming 16 /// The intent is that the front end should immediately wrap any incoming
16 /// [CompilerOptions] object in this class before doing further processing, and 17 /// [CompilerOptions] object in this class before doing further processing, and
17 /// should thereafter access all options via the wrapper. This ensures that 18 /// 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 are interpreted in a consistent way and that data derived from
19 /// options is not unnecessarily recomputed. 20 /// options is not unnecessarily recomputed.
20 class ProcessedOptions { 21 class ProcessedOptions {
21 /// The raw [CompilerOptions] which this class wraps. 22 /// The raw [CompilerOptions] which this class wraps.
22 final CompilerOptions _raw; 23 final CompilerOptions _raw;
23 24
24 /// The package map derived from the options, or `null` if the package map has 25 /// The package map derived from the options, or `null` if the package map has
25 /// not been computed yet. 26 /// not been computed yet.
26 Map<String, Uri> _packages; 27 Map<String, Uri> _packages;
27 28
28 /// A URI resolver based on the options, or `null` if the URI resolver has not 29 /// A URI resolver based on the options, or `null` if the URI resolver has not
29 /// been computed yet. 30 /// been computed yet.
30 UriResolver _uriResolver; 31 UriResolver _uriResolver;
31 32
33 /// The summary bundle for the SDK, or `null` if it has not been read yet.
34 PackageBundle _sdkSummary;
35
36 /// The location of the SDK, or `null` if the location hasn't been determined
37 /// yet.
38 Uri _sdkLocation;
danrubel 2017/01/09 22:01:23 Is this the same as the sdkRoot in https://coderev
Paul Berry 2017/01/11 14:12:45 Done.
39
32 /// Initializes a [ProcessedOptions] object wrapping the given [rawOptions]. 40 /// Initializes a [ProcessedOptions] object wrapping the given [rawOptions].
33 ProcessedOptions(CompilerOptions rawOptions) : this._raw = rawOptions; 41 ProcessedOptions(CompilerOptions rawOptions) : this._raw = rawOptions;
34 42
35 /// Determine whether to generate code for the SDK when compiling a 43 /// Determine whether to generate code for the SDK when compiling a
36 /// whole-program. 44 /// whole-program.
37 bool get compileSdk => _raw.compileSdk; 45 bool get compileSdk => _raw.compileSdk;
38 46
39 /// Get the [FileSystem] which should be used by the front end to access 47 /// Get the [FileSystem] which should be used by the front end to access
40 /// files. 48 /// files.
41 /// 49 ///
42 /// If the client supplied roots using [CompilerOptions.multiRoots], the 50 /// If the client supplied roots using [CompilerOptions.multiRoots], the
43 /// returned [FileSystem] will automatically perform the appropriate mapping. 51 /// returned [FileSystem] will automatically perform the appropriate mapping.
44 FileSystem get fileSystem { 52 FileSystem get fileSystem {
45 // TODO(paulberry): support multiRoots. 53 // TODO(paulberry): support multiRoots.
46 assert(_raw.multiRoots.isEmpty); 54 assert(_raw.multiRoots.isEmpty);
47 return _raw.fileSystem; 55 return _raw.fileSystem;
48 } 56 }
49 57
58 /// Get the summary bundle for the SDK.
59 ///
60 /// This is an asynchronous getter since file system operations are required.
61 Future<PackageBundle> getSdkSummary() async {
62 if (_sdkSummary == null) {
63 Uri summaryLocation;
64 if (_raw.sdkSummary != null) {
65 // Options sdkSummary and sdkRoot are mutually exclusive.
66 assert(_raw.sdkRoot == null);
67 // No need to look for the SDK; we were told where the SDK summary is.
68 summaryLocation = _raw.sdkSummary;
69 } else {
70 // Need to look for the SDK summary inside the SDK.
71 var sdkLocation = await _getSdkLocation();
72 summaryLocation = sdkLocation.resolve(
73 'lib/_internal/' + (_raw.strongMode ? 'strong.sum' : 'spec.sum'));
74 }
75 var summaryBytes =
76 await fileSystem.entityForUri(summaryLocation).readAsBytes();
77 _sdkSummary = new PackageBundle.fromBuffer(summaryBytes);
78 }
79 return _sdkSummary;
80 }
81
50 /// Get the [UriResolver] which resolves "package:" and "dart:" URIs. 82 /// Get the [UriResolver] which resolves "package:" and "dart:" URIs.
51 /// 83 ///
52 /// This is an asynchronous getter since file system operations may be 84 /// This is an asynchronous getter since file system operations may be
53 /// required to locate/read the packages file as well as SDK metadata. 85 /// required to locate/read the packages file as well as SDK metadata.
54 Future<UriResolver> getUriResolver() async { 86 Future<UriResolver> getUriResolver() async {
55 if (_uriResolver == null) { 87 if (_uriResolver == null) {
56 await _getPackages(); 88 await _getPackages();
57 var sdkLibraries = 89 var sdkLibraries =
58 <String, Uri>{}; // TODO(paulberry): support SDK libraries 90 <String, Uri>{}; // TODO(paulberry): support SDK libraries
59 _uriResolver = new UriResolver(_packages, sdkLibraries); 91 _uriResolver = new UriResolver(_packages, sdkLibraries);
(...skipping 12 matching lines...) Expand all
72 } else if (_raw.packagesFileUri.path.isEmpty) { 104 } else if (_raw.packagesFileUri.path.isEmpty) {
73 _packages = {}; 105 _packages = {};
74 } else { 106 } else {
75 var contents = 107 var contents =
76 await fileSystem.entityForUri(_raw.packagesFileUri).readAsBytes(); 108 await fileSystem.entityForUri(_raw.packagesFileUri).readAsBytes();
77 _packages = package_config.parse(contents, _raw.packagesFileUri); 109 _packages = package_config.parse(contents, _raw.packagesFileUri);
78 } 110 }
79 } 111 }
80 return _packages; 112 return _packages;
81 } 113 }
114
115 /// Get the location of the SDK.
116 ///
117 /// This is an asynchronous getter since file system operations may be
118 /// required to locate the SDK.
119 Future<Uri> _getSdkLocation() async {
120 if (_sdkLocation == null) {
121 // If an SDK summary location was provided, the SDK itself should not be
122 // needed.
123 assert(_raw.sdkSummary == null);
124 if (_raw.sdkRoot == null) {
125 // TODO(paulberry): implement the algorithm for finding the SDK
126 // automagically.
127 throw new UnimplementedError();
128 }
129 _sdkLocation = _raw.sdkRoot;
130 if (!_sdkLocation.path.endsWith('/')) {
131 _sdkLocation = _sdkLocation.replace(path: _sdkLocation.path + '/');
132 }
133 }
134 return _sdkLocation;
135 }
82 } 136 }
OLDNEW
« no previous file with comments | « no previous file | 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