| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(_uriToPath(options.packagesFileUri), | 136 var packages = await createPackages( |
| 137 _uriToPath(options.packagesFileUri, options), |
| 137 discoveryPath: entry?.path); | 138 discoveryPath: entry?.path); |
| 138 var loader = | 139 var loader = |
| 139 new DartLoader(program ?? new Program(), kernelOptions, packages); | 140 new DartLoader(program ?? new Program(), kernelOptions, packages); |
| 140 var patchPaths = <String, List<String>>{}; | 141 var patchPaths = <String, List<String>>{}; |
| 141 | 142 |
| 142 // TODO(sigmund,paulberry): use ProcessedOptions so that we can resolve the | 143 // TODO(sigmund,paulberry): use ProcessedOptions so that we can resolve the |
| 143 // URIs correctly even if sdkRoot is inferred and not specified explicitly. | 144 // URIs correctly even if sdkRoot is inferred and not specified explicitly. |
| 144 String resolve(Uri patch) => _uriToPath(options.sdkRoot.resolveUri(patch)); | 145 String resolve(Uri patch) => |
| 146 options.fileSystem.context.fromUri(options.sdkRoot.resolveUri(patch)); |
| 145 | 147 |
| 146 options.targetPatches.forEach((uri, patches) { | 148 options.targetPatches.forEach((uri, patches) { |
| 147 patchPaths['$uri'] = patches.map(resolve).toList(); | 149 patchPaths['$uri'] = patches.map(resolve).toList(); |
| 148 }); | 150 }); |
| 149 AnalysisOptionsImpl analysisOptions = loader.context.analysisOptions; | 151 AnalysisOptionsImpl analysisOptions = loader.context.analysisOptions; |
| 150 analysisOptions.patchPaths = patchPaths; | 152 analysisOptions.patchPaths = patchPaths; |
| 151 return loader; | 153 return loader; |
| 152 } | 154 } |
| 153 | 155 |
| 154 DartOptions _convertOptions(CompilerOptions options) { | 156 DartOptions _convertOptions(CompilerOptions options) { |
| 155 return new DartOptions( | 157 return new DartOptions( |
| 156 strongMode: options.strongMode, | 158 strongMode: options.strongMode, |
| 157 sdk: _uriToPath(options.sdkRoot), | 159 sdk: _uriToPath(options.sdkRoot, options), |
| 158 // TODO(sigmund): make it possible to use summaries and still compile the | 160 // TODO(sigmund): make it possible to use summaries and still compile the |
| 159 // sdk sources. | 161 // sdk sources. |
| 160 sdkSummary: options.compileSdk ? null : _uriToPath(options.sdkSummary), | 162 sdkSummary: |
| 161 packagePath: _uriToPath(options.packagesFileUri), | 163 options.compileSdk ? null : _uriToPath(options.sdkSummary, options), |
| 164 packagePath: _uriToPath(options.packagesFileUri, options), |
| 162 customUriMappings: options.uriOverride, | 165 customUriMappings: options.uriOverride, |
| 163 declaredVariables: options.declaredVariables); | 166 declaredVariables: options.declaredVariables); |
| 164 } | 167 } |
| 165 | 168 |
| 166 void _reportErrors(List errors, ErrorHandler onError) { | 169 void _reportErrors(List errors, ErrorHandler onError) { |
| 167 if (onError == null) return; | 170 if (onError == null) return; |
| 168 for (var error in errors) { | 171 for (var error in errors) { |
| 169 onError(new _DartkError(error)); | 172 onError(new _DartkError(error)); |
| 170 } | 173 } |
| 171 } | 174 } |
| 172 | 175 |
| 173 String _uriToPath(Uri uri) { | 176 String _uriToPath(Uri uri, CompilerOptions options) { |
| 174 if (uri == null) return null; | 177 if (uri == null) return null; |
| 175 if (uri.scheme != 'file') { | 178 if (uri.scheme != 'file') { |
| 176 throw new StateError('Only file URIs are supported: $uri'); | 179 throw new StateError('Only file URIs are supported: $uri'); |
| 177 } | 180 } |
| 178 return uri.toFilePath(); | 181 return options.fileSystem.context.fromUri(uri); |
| 179 } | 182 } |
| 180 | 183 |
| 181 // TODO(sigmund): delete this class. Dartk should not format errors itself, we | 184 // TODO(sigmund): delete this class. Dartk should not format errors itself, we |
| 182 // should just pass them along. | 185 // should just pass them along. |
| 183 class _DartkError implements CompilationError { | 186 class _DartkError implements CompilationError { |
| 184 String get correction => null; | 187 String get correction => null; |
| 185 SourceSpan get span => null; | 188 SourceSpan get span => null; |
| 186 final String message; | 189 final String message; |
| 187 _DartkError(this.message); | 190 _DartkError(this.message); |
| 188 } | 191 } |
| OLD | NEW |