Chromium Code Reviews| 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 /// 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 19 matching lines...) Expand all Loading... | |
| 30 /// code for the SDK. | 30 /// code for the SDK. |
| 31 /// | 31 /// |
| 32 /// If summaries are provided in [options], they may be used to speed up | 32 /// If summaries are provided in [options], they may be used to speed up |
| 33 /// analysis. If in addition `compileSdk` is false, this will speed up | 33 /// analysis. If in addition `compileSdk` is false, this will speed up |
| 34 /// compilation, as no source of the sdk will be generated. Note however, that | 34 /// compilation, as no source of the sdk will be generated. Note however, that |
| 35 /// summaries for application code can also speed up analysis, but they will not | 35 /// summaries for application code can also speed up analysis, but they will not |
| 36 /// take the place of Dart source code (since the Dart source code is still | 36 /// take the place of Dart source code (since the Dart source code is still |
| 37 /// needed to access the contents of method bodies). | 37 /// needed to access the contents of method bodies). |
| 38 Future<Program> kernelForProgram(Uri source, CompilerOptions options) async { | 38 Future<Program> kernelForProgram(Uri source, CompilerOptions options) async { |
| 39 var loader = await _createLoader(options, entry: source); | 39 var loader = await _createLoader(options, entry: source); |
| 40 // TODO(sigmund): delete this. At this time we have no need to explicitly list | |
| 41 // VM libraries, since they are normally found by chasing dependencies. | |
| 42 // `dart:_builtin` is an exception because it is used by the kernel | |
| 43 // transformers to inform the VM about where the main entrypoint is. This is | |
| 44 // expected to change, and we should be able to remove these lines at that | |
| 45 // point. We check for the presense of `dart:developer` in the targetPatches | |
| 46 // to ensure we only load this library while running on the VM. | |
| 47 if (options.compileSdk && | |
| 48 options.targetPatches.containsKey(Uri.parse('dart:developer'))) { | |
| 49 loader.loadLibrary(Uri.parse('dart:_builtin')); | |
|
Siggi Cherem (dart-lang)
2017/01/27 21:55:51
this came up in the context of my other CL where I
| |
| 50 } | |
| 40 // TODO(sigmund): merge what we have in loadEverything and the logic below in | 51 // TODO(sigmund): merge what we have in loadEverything and the logic below in |
| 41 // kernelForBuildUnit so there is a single place where we crawl for | 52 // kernelForBuildUnit so there is a single place where we crawl for |
| 42 // dependencies. | 53 // dependencies. |
| 43 Program program = loader.loadProgram(source, compileSdk: options.compileSdk); | 54 Program program = loader.loadProgram(source, compileSdk: options.compileSdk); |
| 44 _reportErrors(loader.errors, options.onError); | 55 _reportErrors(loader.errors, options.onError); |
| 45 return program; | 56 return program; |
| 46 } | 57 } |
| 47 | 58 |
| 48 /// Generates a kernel representation for a build unit. | 59 /// Generates a kernel representation for a build unit. |
| 49 /// | 60 /// |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 /// Create a [DartLoader] using the provided [options]. | 135 /// Create a [DartLoader] using the provided [options]. |
| 125 /// | 136 /// |
| 126 /// If [options] contain no configuration to resolve `.packages`, the [entry] | 137 /// If [options] contain no configuration to resolve `.packages`, the [entry] |
| 127 /// file will be used to search for a `.packages` file. | 138 /// file will be used to search for a `.packages` file. |
| 128 Future<DartLoader> _createLoader(CompilerOptions options, | 139 Future<DartLoader> _createLoader(CompilerOptions options, |
| 129 {Repository repository, Uri entry}) async { | 140 {Repository repository, Uri entry}) async { |
| 130 var kernelOptions = _convertOptions(options); | 141 var kernelOptions = _convertOptions(options); |
| 131 var packages = await createPackages( | 142 var packages = await createPackages( |
| 132 _uriToPath(options.packagesFileUri, options), | 143 _uriToPath(options.packagesFileUri, options), |
| 133 discoveryPath: entry?.path); | 144 discoveryPath: entry?.path); |
| 134 return new DartLoader( | 145 var loader = new DartLoader( |
| 135 repository ?? new Repository(), kernelOptions, packages); | 146 repository ?? new Repository(), kernelOptions, packages); |
| 147 var patchPaths = {}; | |
| 148 | |
| 149 String resolve(Uri patch) => | |
| 150 options.fileSystem.context.fromUri(options.sdkRoot.resolveUri(patch)); | |
|
Siggi Cherem (dart-lang)
2017/01/27 21:55:51
you'll see in the other CL that this is not used y
Paul Berry
2017/01/27 22:49:19
Add a TODO comment here: we should switch this cod
Siggi Cherem (dart-lang)
2017/01/27 23:00:19
Done.
| |
| 151 | |
| 152 options.targetPatches.forEach((uri, patches) { | |
| 153 patchPaths['$uri'] = patches.map(resolve).toList(); | |
| 154 }); | |
| 155 loader.context.analysisOptions.patchPaths = patchPaths; | |
| 156 return loader; | |
| 136 } | 157 } |
| 137 | 158 |
| 138 DartOptions _convertOptions(CompilerOptions options) { | 159 DartOptions _convertOptions(CompilerOptions options) { |
| 139 return new DartOptions( | 160 return new DartOptions( |
| 140 strongMode: options.strongMode, | 161 strongMode: options.strongMode, |
| 141 sdk: _uriToPath(options.sdkRoot, options), | 162 sdk: _uriToPath(options.sdkRoot, options), |
| 142 // TODO(sigmund): make it possible to use summaries and still compile the | 163 // TODO(sigmund): make it possible to use summaries and still compile the |
| 143 // sdk sources. | 164 // sdk sources. |
| 144 sdkSummary: | 165 sdkSummary: |
| 145 options.compileSdk ? null : _uriToPath(options.sdkSummary, options), | 166 options.compileSdk ? null : _uriToPath(options.sdkSummary, options), |
| 146 packagePath: _uriToPath(options.packagesFileUri, options), | 167 packagePath: _uriToPath(options.packagesFileUri, options), |
| 168 customUriMappings: options.uriOverride, | |
| 147 declaredVariables: options.declaredVariables); | 169 declaredVariables: options.declaredVariables); |
| 148 } | 170 } |
| 149 | 171 |
| 150 void _reportErrors(List errors, ErrorHandler onError) { | 172 void _reportErrors(List errors, ErrorHandler onError) { |
| 151 if (onError == null) return; | 173 if (onError == null) return; |
| 152 for (var error in errors) { | 174 for (var error in errors) { |
| 153 onError(new _DartkError(error)); | 175 onError(new _DartkError(error)); |
| 154 } | 176 } |
| 155 } | 177 } |
| 156 | 178 |
| 157 String _uriToPath(Uri uri, CompilerOptions options) { | 179 String _uriToPath(Uri uri, CompilerOptions options) { |
| 158 if (uri == null) return null; | 180 if (uri == null) return null; |
| 159 if (uri.scheme != 'file') { | 181 if (uri.scheme != 'file') { |
| 160 throw new StateError('Only file URIs are supported'); | 182 throw new StateError('Only file URIs are supported'); |
| 161 } | 183 } |
| 162 return options.fileSystem.context.fromUri(uri); | 184 return options.fileSystem.context.fromUri(uri); |
| 163 } | 185 } |
| 164 | 186 |
| 165 // TODO(sigmund): delete this class. Dartk should not format errors itself, we | 187 // TODO(sigmund): delete this class. Dartk should not format errors itself, we |
| 166 // should just pass them along. | 188 // should just pass them along. |
| 167 class _DartkError implements CompilationError { | 189 class _DartkError implements CompilationError { |
| 168 String get correction => null; | 190 String get correction => null; |
| 169 SourceSpan get span => null; | 191 SourceSpan get span => null; |
| 170 final String message; | 192 final String message; |
| 171 _DartkError(this.message); | 193 _DartkError(this.message); |
| 172 } | 194 } |
| OLD | NEW |