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

Unified Diff: pkg/front_end/lib/src/base/processed_options.dart

Issue 2993113003: Revert "Switch FE to use the libraries.json format." (Closed)
Patch Set: Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
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 5ba11fafdd27691e5164e47c15ad44b4838a153a..ea1d6ac526b132e1c77ef3fecc461f75f8c43489 100644
--- a/pkg/front_end/lib/src/base/processed_options.dart
+++ b/pkg/front_end/lib/src/base/processed_options.dart
@@ -28,8 +28,6 @@ import 'package:source_span/source_span.dart' show SourceSpan, SourceLocation;
import 'package:front_end/src/fasta/command_line_reporting.dart'
as command_line_reporting;
-import 'libraries_specification.dart';
-
/// All options needed for the front end implementation.
///
/// This includes: all of [CompilerOptions] in a form useful to the
@@ -78,22 +76,10 @@ class ProcessedOptions {
/// The location of the SDK, or `null` if the location hasn't been determined
/// yet.
Uri _sdkRoot;
- Uri get sdkRoot {
- _ensureSdkDefaults();
- return _sdkRoot;
- }
+ Uri get sdkRoot => _sdkRoot ??= _normalizeSdkRoot();
Uri _sdkSummary;
- Uri get sdkSummary {
- _ensureSdkDefaults();
- return _sdkSummary;
- }
-
- Uri _librariesSpecificationUri;
- Uri get librariesSpecificationUri {
- _ensureSdkDefaults();
- return _librariesSpecificationUri;
- }
+ Uri get sdkSummary => _sdkSummary ??= _computeSdkSummaryUri();
Ticker ticker;
@@ -288,45 +274,20 @@ class ProcessedOptions {
/// required to locate/read the packages file as well as SDK metadata.
Future<UriTranslatorImpl> getUriTranslator() async {
if (_uriTranslator == null) {
- ticker.logMs("Started building UriTranslator");
- var libraries = await _computeLibrarySpecification();
- ticker.logMs("Read libraries file");
- var packages = await _getPackages();
+ await _getPackages();
+ // TODO(scheglov) Load SDK libraries from whatever format we decide.
+ // TODO(scheglov) Remove the field "_raw.dartLibraries".
+ var libraries = _raw.dartLibraries ?? await _parseDartLibraries();
+ _uriTranslator = new UriTranslatorImpl(
+ libraries, const <String, List<Uri>>{}, _packages);
ticker.logMs("Read packages file");
- _uriTranslator = new UriTranslatorImpl(libraries, packages);
}
return _uriTranslator;
}
- Future<TargetLibrariesSpecification> _computeLibrarySpecification() async {
- var name = target.name;
- // TODO(sigmund): Eek! We should get to the point where there is no
- // fasta-specific targets and the target names are meaningful.
- if (name.endsWith('_fasta')) name = name.substring(0, name.length - 6);
-
- if (librariesSpecificationUri == null ||
- !await fileSystem.entityForUri(librariesSpecificationUri).exists()) {
- if (compileSdk) {
- reportWithoutLocation(
- templateSdkSpecificationNotFound
- .withArguments(librariesSpecificationUri),
- Severity.error);
- }
- return new TargetLibrariesSpecification(name);
- }
-
- var json =
- await fileSystem.entityForUri(librariesSpecificationUri).readAsString();
- try {
- var spec =
- await LibrariesSpecification.parse(librariesSpecificationUri, json);
- return spec.specificationFor(name);
- } on LibrariesSpecificationException catch (e) {
- reportWithoutLocation(
- templateCannotReadSdkSpecification.withArguments('${e.error}'),
- Severity.error);
- return new TargetLibrariesSpecification(name);
- }
+ Future<Map<String, Uri>> _parseDartLibraries() async {
+ Uri librariesJson = _raw.sdkRoot?.resolve("lib/libraries.json");
+ return await computeDartLibraries(fileSystem, librariesJson);
}
/// Get the package map which maps package names to URIs.
@@ -437,42 +398,32 @@ class ProcessedOptions {
return Packages.noPackages;
}
- bool _computedSdkDefaults = false;
-
- /// Ensure [_sdkRoot], [_sdkSummary] and [_librarySpecUri] are initialized.
- ///
- /// If they are not set explicitly, they are infered based on the default
- /// behavior described in [CompilerOptions].
- void _ensureSdkDefaults() {
- if (_computedSdkDefaults) return;
- _computedSdkDefaults = true;
- var root = _raw.sdkRoot;
- if (root != null) {
- // Normalize to always end in '/'
- if (!root.path.endsWith('/')) {
- root = root.replace(path: root.path + '/');
- }
- _sdkRoot = root;
- } else if (compileSdk) {
+ /// Get the location of the SDK.
+ Uri _normalizeSdkRoot() {
+ // 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.
- unimplemented('infer the default sdk location', -1, null);
+ return unimplemented('infer the default sdk location', -1, null);
}
-
- if (_raw.sdkSummary != null) {
- _sdkSummary = _raw.sdkSummary;
- } else if (!compileSdk) {
- // Infer based on the sdkRoot, but only when `compileSdk` is false,
- // otherwise the default intent was to compile the sdk from sources and
- // not to load an sdk summary file.
- _sdkSummary = root?.resolve('outline.dill');
+ var root = _raw.sdkRoot;
+ if (!root.path.endsWith('/')) {
+ root = root.replace(path: root.path + '/');
}
+ return root;
+ }
- if (_raw.librariesSpecificationUri != null) {
- _librariesSpecificationUri = _raw.librariesSpecificationUri;
- } else if (compileSdk) {
- _librariesSpecificationUri = sdkRoot.resolve('lib/libraries.json');
- }
+ /// Get or infer the location of the SDK summary.
+ Uri _computeSdkSummaryUri() {
+ if (_raw.sdkSummary != null) return _raw.sdkSummary;
+
+ // Infer based on the sdkRoot, but only when `compileSdk` is false,
+ // otherwise the default intent was to compile the sdk from sources and not
+ // to load an sdk summary file.
+ if (_raw.compileSdk) return null;
+ return sdkRoot.resolve('outline.dill');
}
/// Create a [FileSystem] specific to the current options.
@@ -543,8 +494,6 @@ class ProcessedOptions {
sb.writeln('Compile SDK: ${compileSdk}');
sb.writeln('SDK root: ${_sdkRoot} (provided: ${_raw.sdkRoot})');
- sb.writeln('SDK specification: ${_librariesSpecificationUri} '
- '(provided: ${_raw.librariesSpecificationUri})');
sb.writeln('SDK summary: ${_sdkSummary} (provided: ${_raw.sdkSummary})');
sb.writeln('Strong: ${strongMode}');
« no previous file with comments | « pkg/front_end/lib/src/base/libraries_specification.dart ('k') | pkg/front_end/lib/src/fasta/fasta_codes_generated.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698