Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(525)

Side by Side Diff: runtime/bin/builtin.dart

Issue 180783008: Change handling of dart-ext: URIs for native extensions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/dartutils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 library builtin; 5 library builtin;
6 import 'dart:io'; 6 import 'dart:io';
7 import 'dart:async'; 7 import 'dart:async';
8 // import 'root_library'; happens here from C Code 8 // import 'root_library'; happens here from C Code
9 9
10 // The root library (aka the script) is imported into this library. The 10 // The root library (aka the script) is imported into this library. The
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // Script does not have a scheme, assume that it is a path, 200 // Script does not have a scheme, assume that it is a path,
201 // resolve it against the working directory. 201 // resolve it against the working directory.
202 _entryPointScript = _workingDirectoryUri.resolve(scriptName); 202 _entryPointScript = _workingDirectoryUri.resolve(scriptName);
203 } 203 }
204 _logResolution('# Resolved entry point to: $_entryPointScript'); 204 _logResolution('# Resolved entry point to: $_entryPointScript');
205 return _entryPointScript.toString(); 205 return _entryPointScript.toString();
206 } 206 }
207 207
208 208
209 String _resolveUri(String base, String userString) { 209 String _resolveUri(String base, String userString) {
210 _logResolution('# Resolving: $userString from $base');
211 const DART_EXT = 'dart-ext:';
210 var baseUri = Uri.parse(base); 212 var baseUri = Uri.parse(base);
211 _logResolution('# Resolving: $userString from $base'); 213 if (userString.startsWith(DART_EXT)) {
212 214 var uri = userString.substring(DART_EXT.length);
213 var uri = Uri.parse(userString); 215 return '$DART_EXT${baseUri.resolve(uri)}';
214 var resolved;
215 if ('dart-ext' == uri.scheme) {
216 // Relative URIs with scheme dart-ext should be resolved as if with no
217 // scheme.
218 resolved = baseUri.resolve(uri.path);
219 if (resolved.scheme == 'package') {
220 // If we are resolving relative to a package URI we go directly to the
221 // file path and keep the dart-ext scheme. Otherwise, we will lose the
222 // package URI path part.
223 var path = _filePathFromPackageUri(resolved);
224 if (path.startsWith('http:')) {
225 throw "Native extensions not supported in "
226 "packages loaded over http: %path";
227 }
228 resolved = new Uri.file(path);
229 }
230 resolved = new Uri(scheme: 'dart-ext', path: resolved.path);
231 } else { 216 } else {
232 resolved = baseUri.resolve(userString); 217 return '${baseUri.resolve(userString)}';
233 } 218 }
234 _logResolution('# Resolved to: $resolved');
235 return resolved.toString();
236 } 219 }
237 220
238 221
239 // Returns either a file path or a URI starting with http:, as a String. 222 // Returns either a file path or a URI starting with http:, as a String.
240 String _filePathFromUri(String userUri) { 223 String _filePathFromUri(String userUri) {
224 const DART_EXT = 'dart-ext:';
Ivan Posva 2014/03/03 08:26:37 This constant should only be defined once. How abo
Bill Hesse 2014/03/04 09:27:14 Done. Committed with a typo in r33216, fixed in r
225 if (userUri.startsWith(DART_EXT)) {
226 userUri = userUri.substring(DART_EXT.length);
227 }
241 var uri = Uri.parse(userUri); 228 var uri = Uri.parse(userUri);
242 _logResolution('# Getting file path from: $uri'); 229 _logResolution('# Getting file path from: $uri');
243 230
244 var path; 231 var path;
245 switch (uri.scheme) { 232 switch (uri.scheme) {
246 case '': 233 case '':
247 case 'file': 234 case 'file':
248 return uri.toFilePath(); 235 return uri.toFilePath();
249 break; 236 break;
250 case 'dart-ext':
251 // Relative file URIs don't start with file:///.
252 var scheme = (uri.path.startsWith('/') ? 'file' : '');
253 return new Uri(scheme: scheme,
254 host: uri.host,
255 path: uri.path).toFilePath();
256 break;
257 case 'package': 237 case 'package':
258 return _filePathFromPackageUri(uri); 238 return _filePathFromPackageUri(uri);
259 break; 239 break;
260 case 'http': 240 case 'http':
261 return uri.toString(); 241 return uri.toString();
262 default: 242 default:
263 // Only handling file, dart-ext, http, and package URIs 243 // Only handling file, http, and package URIs
264 // in standalone binary. 244 // in standalone binary.
265 _logResolution('# Unknown scheme (${uri.scheme}) in $uri.'); 245 _logResolution('# Unknown scheme (${uri.scheme}) in $uri.');
266 throw 'Not a known scheme: $uri'; 246 throw 'Not a known scheme: $uri';
267 } 247 }
268 } 248 }
269 249
270 250
271 String _filePathFromPackageUri(Uri uri) { 251 String _filePathFromPackageUri(Uri uri) {
272 if (!uri.host.isEmpty) { 252 if (!uri.host.isEmpty) {
273 var path = (uri.path != '') ? '${uri.host}${uri.path}' : uri.host; 253 var path = '${uri.host}${uri.path}';
274 var right = 'package:$path'; 254 var right = 'package:$path';
275 var wrong = 'package://$path'; 255 var wrong = 'package://$path';
276 256
277 throw "URIs using the 'package:' scheme should look like " 257 throw "URIs using the 'package:' scheme should look like "
278 "'$right', not '$wrong'."; 258 "'$right', not '$wrong'.";
279 } 259 }
280 260
281 var packageRoot = _packageRoot == null ? 261 var packageRoot = _packageRoot == null ?
282 _entryPointScript.resolve('packages/') : 262 _entryPointScript.resolve('packages/') :
283 _packageRoot; 263 _packageRoot;
284 return _filePathFromUri(packageRoot.resolve(uri.path).toString()); 264 return _filePathFromUri(packageRoot.resolve(uri.path).toString());
285 } 265 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/dartutils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698