Chromium Code Reviews| Index: pkg/front_end/lib/src/base/processed_options.dart |
| diff --git a/pkg/front_end/lib/src/base/processed_options.dart b/pkg/front_end/lib/src/base/processed_options.dart |
| index 360b5fa6a48807aa65938d2b484e679b18469555..be1783a318d203eee72745e4a449848c82f53538 100644 |
| --- a/pkg/front_end/lib/src/base/processed_options.dart |
| +++ b/pkg/front_end/lib/src/base/processed_options.dart |
| @@ -4,6 +4,7 @@ |
| import 'dart:async'; |
| +import 'package:analyzer/src/summary/idl.dart'; |
| import 'package:front_end/compiler_options.dart'; |
| import 'package:front_end/file_system.dart'; |
| import 'package:front_end/src/base/uri_resolver.dart'; |
| @@ -29,6 +30,13 @@ class ProcessedOptions { |
| /// been computed yet. |
| UriResolver _uriResolver; |
| + /// The summary bundle for the SDK, or `null` if it has not been read yet. |
| + PackageBundle _sdkSummary; |
| + |
| + /// The location of the SDK, or `null` if the location hasn't been determined |
| + /// yet. |
| + 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.
|
| + |
| /// Initializes a [ProcessedOptions] object wrapping the given [rawOptions]. |
| ProcessedOptions(CompilerOptions rawOptions) : this._raw = rawOptions; |
| @@ -47,6 +55,30 @@ class ProcessedOptions { |
| return _raw.fileSystem; |
| } |
| + /// Get the summary bundle for the SDK. |
| + /// |
| + /// This is an asynchronous getter since file system operations are required. |
| + Future<PackageBundle> getSdkSummary() async { |
| + if (_sdkSummary == null) { |
| + Uri summaryLocation; |
| + if (_raw.sdkSummary != null) { |
| + // Options sdkSummary and sdkRoot are mutually exclusive. |
| + assert(_raw.sdkRoot == null); |
| + // No need to look for the SDK; we were told where the SDK summary is. |
| + summaryLocation = _raw.sdkSummary; |
| + } else { |
| + // Need to look for the SDK summary inside the SDK. |
| + var sdkLocation = await _getSdkLocation(); |
| + summaryLocation = sdkLocation.resolve( |
| + 'lib/_internal/' + (_raw.strongMode ? 'strong.sum' : 'spec.sum')); |
| + } |
| + var summaryBytes = |
| + await fileSystem.entityForUri(summaryLocation).readAsBytes(); |
| + _sdkSummary = new PackageBundle.fromBuffer(summaryBytes); |
| + } |
| + return _sdkSummary; |
| + } |
| + |
| /// Get the [UriResolver] which resolves "package:" and "dart:" URIs. |
| /// |
| /// This is an asynchronous getter since file system operations may be |
| @@ -79,4 +111,26 @@ class ProcessedOptions { |
| } |
| return _packages; |
| } |
| + |
| + /// Get the location of the SDK. |
| + /// |
| + /// This is an asynchronous getter since file system operations may be |
| + /// required to locate the SDK. |
| + Future<Uri> _getSdkLocation() async { |
| + if (_sdkLocation == null) { |
| + // If an SDK summary location was provided, the SDK itself should not be |
| + // needed. |
| + assert(_raw.sdkSummary == null); |
| + if (_raw.sdkRoot == null) { |
| + // TODO(paulberry): implement the algorithm for finding the SDK |
| + // automagically. |
| + throw new UnimplementedError(); |
| + } |
| + _sdkLocation = _raw.sdkRoot; |
| + if (!_sdkLocation.path.endsWith('/')) { |
| + _sdkLocation = _sdkLocation.replace(path: _sdkLocation.path + '/'); |
| + } |
| + } |
| + return _sdkLocation; |
| + } |
| } |