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