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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 return program; | 121 return program; |
122 } | 122 } |
123 | 123 |
124 /// Create a [DartLoader] using the provided [options]. | 124 /// Create a [DartLoader] using the provided [options]. |
125 /// | 125 /// |
126 /// If [options] contain no configuration to resolve `.packages`, the [entry] | 126 /// If [options] contain no configuration to resolve `.packages`, the [entry] |
127 /// file will be used to search for a `.packages` file. | 127 /// file will be used to search for a `.packages` file. |
128 Future<DartLoader> _createLoader(CompilerOptions options, | 128 Future<DartLoader> _createLoader(CompilerOptions options, |
129 {Repository repository, Uri entry}) async { | 129 {Repository repository, Uri entry}) async { |
130 var kernelOptions = _convertOptions(options); | 130 var kernelOptions = _convertOptions(options); |
131 var packages = await createPackages(options.packagesFilePath, | 131 var packages = await createPackages( |
| 132 _uriToPath(options.packagesFilePath, options), |
132 discoveryPath: entry?.path); | 133 discoveryPath: entry?.path); |
133 return new DartLoader( | 134 return new DartLoader( |
134 repository ?? new Repository(), kernelOptions, packages); | 135 repository ?? new Repository(), kernelOptions, packages); |
135 } | 136 } |
136 | 137 |
137 DartOptions _convertOptions(CompilerOptions options) { | 138 DartOptions _convertOptions(CompilerOptions options) { |
138 return new DartOptions( | 139 return new DartOptions( |
139 strongMode: options.strongMode, | 140 strongMode: options.strongMode, |
140 sdk: options.sdkPath, | 141 sdk: _uriToPath(options.sdkPath, options), |
141 // TODO(sigmund): make it possible to use summaries and still compile the | 142 // TODO(sigmund): make it possible to use summaries and still compile the |
142 // sdk sources. | 143 // sdk sources. |
143 sdkSummary: options.compileSdk ? null : options.sdkSummary, | 144 sdkSummary: |
144 packagePath: options.packagesFilePath, | 145 options.compileSdk ? null : _uriToPath(options.sdkSummary, options), |
| 146 packagePath: _uriToPath(options.packagesFilePath, options), |
145 declaredVariables: options.declaredVariables); | 147 declaredVariables: options.declaredVariables); |
146 } | 148 } |
147 | 149 |
148 void _reportErrors(List errors, ErrorHandler onError) { | 150 void _reportErrors(List errors, ErrorHandler onError) { |
149 if (onError == null) return; | 151 if (onError == null) return; |
150 for (var error in errors) { | 152 for (var error in errors) { |
151 onError(new _DartkError(error)); | 153 onError(new _DartkError(error)); |
152 } | 154 } |
153 } | 155 } |
154 | 156 |
| 157 String _uriToPath(Uri uri, CompilerOptions options) { |
| 158 if (uri == null) return null; |
| 159 if (uri.scheme != 'file') { |
| 160 throw new StateError('Only file URIs are supported'); |
| 161 } |
| 162 return options.fileSystem.context.fromUri(uri); |
| 163 } |
| 164 |
155 // TODO(sigmund): delete this class. Dartk should not format errors itself, we | 165 // TODO(sigmund): delete this class. Dartk should not format errors itself, we |
156 // should just pass them along. | 166 // should just pass them along. |
157 class _DartkError implements CompilationError { | 167 class _DartkError implements CompilationError { |
158 String get correction => null; | 168 String get correction => null; |
159 SourceSpan get span => null; | 169 SourceSpan get span => null; |
160 final String message; | 170 final String message; |
161 _DartkError(this.message); | 171 _DartkError(this.message); |
162 } | 172 } |
OLD | NEW |