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

Side by Side Diff: pkg/front_end/lib/kernel_generator.dart

Issue 2844903002: Extend file-system abstraction with a couple methods, remove context (Closed)
Patch Set: v3 Created 3 years, 7 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
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 /// Defines the front-end API for converting source code to Dart Kernel objects. 5 /// Defines the front-end API for converting source code to Dart Kernel objects.
6 library front_end.kernel_generator; 6 library front_end.kernel_generator;
7 7
8 import 'compilation_error.dart'; 8 import 'compilation_error.dart';
9 import 'compiler_options.dart'; 9 import 'compiler_options.dart';
10 import 'dart:async'; 10 import 'dart:async';
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 return program; 126 return program;
127 } 127 }
128 128
129 /// Create a [DartLoader] using the provided [options]. 129 /// Create a [DartLoader] using the provided [options].
130 /// 130 ///
131 /// If [options] contain no configuration to resolve `.packages`, the [entry] 131 /// If [options] contain no configuration to resolve `.packages`, the [entry]
132 /// file will be used to search for a `.packages` file. 132 /// file will be used to search for a `.packages` file.
133 Future<DartLoader> _createLoader(CompilerOptions options, 133 Future<DartLoader> _createLoader(CompilerOptions options,
134 {Program program, Uri entry}) async { 134 {Program program, Uri entry}) async {
135 var kernelOptions = _convertOptions(options); 135 var kernelOptions = _convertOptions(options);
136 var packages = await createPackages( 136 var packages = await createPackages(_uriToPath(options.packagesFileUri),
137 _uriToPath(options.packagesFileUri, options),
138 discoveryPath: entry?.path); 137 discoveryPath: entry?.path);
139 var loader = 138 var loader =
140 new DartLoader(program ?? new Program(), kernelOptions, packages); 139 new DartLoader(program ?? new Program(), kernelOptions, packages);
141 var patchPaths = <String, List<String>>{}; 140 var patchPaths = <String, List<String>>{};
142 141
143 // TODO(sigmund,paulberry): use ProcessedOptions so that we can resolve the 142 // TODO(sigmund,paulberry): use ProcessedOptions so that we can resolve the
144 // URIs correctly even if sdkRoot is inferred and not specified explicitly. 143 // URIs correctly even if sdkRoot is inferred and not specified explicitly.
145 String resolve(Uri patch) => 144 String resolve(Uri patch) => _uriToPath(options.sdkRoot.resolveUri(patch));
146 options.fileSystem.context.fromUri(options.sdkRoot.resolveUri(patch));
147 145
148 options.targetPatches.forEach((uri, patches) { 146 options.targetPatches.forEach((uri, patches) {
149 patchPaths['$uri'] = patches.map(resolve).toList(); 147 patchPaths['$uri'] = patches.map(resolve).toList();
150 }); 148 });
151 AnalysisOptionsImpl analysisOptions = loader.context.analysisOptions; 149 AnalysisOptionsImpl analysisOptions = loader.context.analysisOptions;
152 analysisOptions.patchPaths = patchPaths; 150 analysisOptions.patchPaths = patchPaths;
153 return loader; 151 return loader;
154 } 152 }
155 153
156 DartOptions _convertOptions(CompilerOptions options) { 154 DartOptions _convertOptions(CompilerOptions options) {
157 return new DartOptions( 155 return new DartOptions(
158 strongMode: options.strongMode, 156 strongMode: options.strongMode,
159 sdk: _uriToPath(options.sdkRoot, options), 157 sdk: _uriToPath(options.sdkRoot),
160 // TODO(sigmund): make it possible to use summaries and still compile the 158 // TODO(sigmund): make it possible to use summaries and still compile the
161 // sdk sources. 159 // sdk sources.
162 sdkSummary: 160 sdkSummary: options.compileSdk ? null : _uriToPath(options.sdkSummary),
163 options.compileSdk ? null : _uriToPath(options.sdkSummary, options), 161 packagePath: _uriToPath(options.packagesFileUri),
164 packagePath: _uriToPath(options.packagesFileUri, options),
165 customUriMappings: options.uriOverride, 162 customUriMappings: options.uriOverride,
166 declaredVariables: options.declaredVariables); 163 declaredVariables: options.declaredVariables);
167 } 164 }
168 165
169 void _reportErrors(List errors, ErrorHandler onError) { 166 void _reportErrors(List errors, ErrorHandler onError) {
170 if (onError == null) return; 167 if (onError == null) return;
171 for (var error in errors) { 168 for (var error in errors) {
172 onError(new _DartkError(error)); 169 onError(new _DartkError(error));
173 } 170 }
174 } 171 }
175 172
176 String _uriToPath(Uri uri, CompilerOptions options) { 173 String _uriToPath(Uri uri) {
177 if (uri == null) return null; 174 if (uri == null) return null;
178 if (uri.scheme != 'file') { 175 if (uri.scheme != 'file') {
179 throw new StateError('Only file URIs are supported: $uri'); 176 throw new StateError('Only file URIs are supported: $uri');
180 } 177 }
181 return options.fileSystem.context.fromUri(uri); 178 return uri.toFilePath();
182 } 179 }
183 180
184 // TODO(sigmund): delete this class. Dartk should not format errors itself, we 181 // TODO(sigmund): delete this class. Dartk should not format errors itself, we
185 // should just pass them along. 182 // should just pass them along.
186 class _DartkError implements CompilationError { 183 class _DartkError implements CompilationError {
187 String get correction => null; 184 String get correction => null;
188 SourceSpan get span => null; 185 SourceSpan get span => null;
189 final String message; 186 final String message;
190 _DartkError(this.message); 187 _DartkError(this.message);
191 } 188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698