OLD | NEW |
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 /// An entrypoint used to run portions of front_end and measure its performance. | 5 /// An entrypoint used to run portions of front_end and measure its performance. |
6 library front_end.tool.perf; | 6 library front_end.tool.perf; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:io' show Directory, File, Platform, exit; | 9 import 'dart:io' show Directory, File, Platform, exit; |
10 | 10 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 } | 138 } |
139 Program program = await _kernelForProgramViaDartk(entryUri, options); | 139 Program program = await _kernelForProgramViaDartk(entryUri, options); |
140 dartkTimer.stop(); | 140 dartkTimer.stop(); |
141 var suffix = useSdkSummary ? '_sum' : ''; | 141 var suffix = useSdkSummary ? '_sum' : ''; |
142 report('kernel_gen_e2e${suffix}', dartkTimer.elapsedMicroseconds); | 142 report('kernel_gen_e2e${suffix}', dartkTimer.elapsedMicroseconds); |
143 return program; | 143 return program; |
144 } | 144 } |
145 | 145 |
146 _kernelForProgramViaDartk(Uri source, CompilerOptions options) async { | 146 _kernelForProgramViaDartk(Uri source, CompilerOptions options) async { |
147 var loader = await _createLoader(options, entry: source); | 147 var loader = await _createLoader(options, entry: source); |
| 148 if (options.compileSdk) { |
| 149 options.additionalLibraries.forEach(loader.loadLibrary); |
| 150 } |
148 loader.loadProgram(source, compileSdk: options.compileSdk); | 151 loader.loadProgram(source, compileSdk: options.compileSdk); |
149 _reportErrors(loader.errors, options.onError); | 152 _reportErrors(loader.errors, options.onError); |
150 return loader.program; | 153 return loader.program; |
151 } | 154 } |
152 | 155 |
153 /// Create a [DartLoader] using the provided [options]. | 156 /// Create a [DartLoader] using the provided [options]. |
154 /// | 157 /// |
155 /// If [options] contain no configuration to resolve `.packages`, the [entry] | 158 /// If [options] contain no configuration to resolve `.packages`, the [entry] |
156 /// file will be used to search for a `.packages` file. | 159 /// file will be used to search for a `.packages` file. |
157 Future<DartLoader> _createLoader(CompilerOptions options, | 160 Future<DartLoader> _createLoader(CompilerOptions options, |
158 {Program program, Uri entry}) async { | 161 {Program program, Uri entry}) async { |
159 var kernelOptions = _convertOptions(options); | 162 var kernelOptions = _convertOptions(options); |
160 var packages = await createPackages(_uriToPath(options.packagesFileUri), | 163 var packages = await createPackages(_uriToPath(options.packagesFileUri), |
161 discoveryPath: entry?.path); | 164 discoveryPath: entry?.path); |
162 var loader = | 165 var loader = |
163 new DartLoader(program ?? new Program(), kernelOptions, packages); | 166 new DartLoader(program ?? new Program(), kernelOptions, packages); |
164 var patchPaths = <String, List<String>>{}; | 167 var patchPaths = <String, List<String>>{}; |
165 | 168 |
166 // TODO(sigmund,paulberry): use ProcessedOptions so that we can resolve the | 169 // TODO(sigmund,paulberry): use ProcessedOptions so that we can resolve the |
167 // URIs correctly even if sdkRoot is inferred and not specified explicitly. | 170 // URIs correctly even if sdkRoot is inferred and not specified explicitly. |
168 String resolve(Uri patch) => _uriToPath(options.sdkRoot.resolveUri(patch)); | 171 String resolve(Uri patch) => _uriToPath(options.sdkRoot.resolveUri(patch)); |
169 | 172 |
170 options.targetPatches.forEach((name, patches) { | 173 options.targetPatches.forEach((uri, patches) { |
171 patchPaths['dart:$name'] = patches.map(resolve).toList(); | 174 patchPaths['$uri'] = patches.map(resolve).toList(); |
172 }); | 175 }); |
173 AnalysisOptionsImpl analysisOptions = loader.context.analysisOptions; | 176 AnalysisOptionsImpl analysisOptions = loader.context.analysisOptions; |
174 analysisOptions.patchPaths = patchPaths; | 177 analysisOptions.patchPaths = patchPaths; |
175 return loader; | 178 return loader; |
176 } | 179 } |
177 | 180 |
178 DartOptions _convertOptions(CompilerOptions options) { | 181 DartOptions _convertOptions(CompilerOptions options) { |
179 return new DartOptions( | 182 return new DartOptions( |
180 strongMode: options.strongMode, | 183 strongMode: options.strongMode, |
181 sdk: _uriToPath(options.sdkRoot), | 184 sdk: _uriToPath(options.sdkRoot), |
182 // TODO(sigmund): make it possible to use summaries and still compile the | 185 // TODO(sigmund): make it possible to use summaries and still compile the |
183 // sdk sources. | 186 // sdk sources. |
184 sdkSummary: options.compileSdk ? null : _uriToPath(options.sdkSummary), | 187 sdkSummary: options.compileSdk ? null : _uriToPath(options.sdkSummary), |
185 packagePath: _uriToPath(options.packagesFileUri), | 188 packagePath: _uriToPath(options.packagesFileUri), |
| 189 customUriMappings: options.uriOverride, |
186 declaredVariables: options.declaredVariables); | 190 declaredVariables: options.declaredVariables); |
187 } | 191 } |
188 | 192 |
189 String _uriToPath(Uri uri) { | 193 String _uriToPath(Uri uri) { |
190 if (uri == null) return null; | 194 if (uri == null) return null; |
191 if (uri.scheme != 'file') { | 195 if (uri.scheme != 'file') { |
192 throw new StateError('Only file URIs are supported: $uri'); | 196 throw new StateError('Only file URIs are supported: $uri'); |
193 } | 197 } |
194 return uri.toFilePath(); | 198 return uri.toFilePath(); |
195 } | 199 } |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 class _Scanner extends Scanner { | 435 class _Scanner extends Scanner { |
432 _Scanner(String contents) : super.create(new CharSequenceReader(contents)) { | 436 _Scanner(String contents) : super.create(new CharSequenceReader(contents)) { |
433 preserveComments = false; | 437 preserveComments = false; |
434 } | 438 } |
435 | 439 |
436 @override | 440 @override |
437 void reportError(errorCode, int offset, List<Object> arguments) { | 441 void reportError(errorCode, int offset, List<Object> arguments) { |
438 // ignore errors. | 442 // ignore errors. |
439 } | 443 } |
440 } | 444 } |
OLD | NEW |