Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | 6 |
| 7 void print(arg) { | 7 void print(arg) { |
| 8 _Logger._printString(arg.toString()); | 8 _Logger._printString(arg.toString()); |
| 9 } | 9 } |
| 10 | 10 |
| 11 void exit(int status) { | 11 void exit(int status) { |
| 12 if (status is !int) { | 12 if (status is !int) { |
| 13 throw new IllegalArgumentException("int status expected"); | 13 throw new IllegalArgumentException("int status expected"); |
| 14 } | 14 } |
| 15 _exit(status); | 15 _exit(status); |
| 16 } | 16 } |
| 17 | 17 |
| 18 _exit(int status) native "Exit"; | 18 _exit(int status) native "Exit"; |
| 19 | 19 |
| 20 class _Logger { | 20 class _Logger { |
| 21 static void _printString(String s) native "Logger_PrintString"; | 21 static void _printString(String s) native "Logger_PrintString"; |
| 22 } | 22 } |
| 23 | 23 |
| 24 | 24 |
| 25 // Code to deal with URI resolution for the standalone binary. | 25 // Code to deal with URI resolution for the standalone binary. |
| 26 // For Windows we need to massage the paths a bit according to | 26 // For Windows we need to massage the paths a bit according to |
| 27 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx | 27 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx |
| 28 var _is_windows; | 28 var _is_windows; |
| 29 | 29 |
| 30 // The URI that the entrypoint script was loaded from. Remembered so that | |
| 31 // package imports can be resolved relative to it. | |
| 32 Uri _entrypoint; | |
| 33 | |
| 30 void _logResolution(String msg) { | 34 void _logResolution(String msg) { |
| 31 final enabled = false; | 35 final enabled = false; |
| 32 if (enabled) { | 36 if (enabled) { |
| 33 _Logger._printString(msg); | 37 _Logger._printString(msg); |
| 34 } | 38 } |
| 35 } | 39 } |
| 36 | 40 |
| 37 String _resolveScriptUri(String cwd, String scriptName, bool windows) { | 41 String _resolveScriptUri(String cwd, String scriptName, bool windows) { |
| 38 _is_windows = windows; | 42 _is_windows = windows; |
| 39 _logResolution("# Current working directory: $cwd"); | 43 _logResolution("# Current working directory: $cwd"); |
| 40 _logResolution("# ScriptName: $scriptName"); | 44 _logResolution("# ScriptName: $scriptName"); |
| 41 if (windows) { | 45 if (windows) { |
| 42 // Convert | 46 // Convert |
| 43 // C:\one\two\three | 47 // C:\one\two\three |
| 44 // to | 48 // to |
| 45 // /C:/one/two/three | 49 // /C:/one/two/three |
| 46 cwd = "/${cwd.replaceAll('\\', '/')}"; | 50 cwd = "/${cwd.replaceAll('\\', '/')}"; |
| 47 _logResolution("## cwd: $cwd"); | 51 _logResolution("## cwd: $cwd"); |
| 48 if ((scriptName.length > 2) && (scriptName[1] == ":")) { | 52 if ((scriptName.length > 2) && (scriptName[1] == ":")) { |
| 49 // This is an absolute path. | 53 // This is an absolute path. |
| 50 scriptName = "/${scriptName.replaceAll('\\', '/')}"; | 54 scriptName = "/${scriptName.replaceAll('\\', '/')}"; |
| 51 } else { | 55 } else { |
| 52 scriptName = scriptName.replaceAll('\\', '/'); | 56 scriptName = scriptName.replaceAll('\\', '/'); |
| 53 } | 57 } |
| 54 _logResolution("## scriptName: $scriptName"); | 58 _logResolution("## scriptName: $scriptName"); |
| 55 } | 59 } |
| 56 var base = new Uri(scheme: "file", path: cwd.endsWith("/") ? cwd : "$cwd/"); | 60 var base = new Uri(scheme: "file", path: cwd.endsWith("/") ? cwd : "$cwd/"); |
| 57 var resolved = base.resolve(scriptName); | 61 _entrypoint = base.resolve(scriptName); |
| 58 _logResolution("# Resolved to: $resolved"); | 62 _logResolution("# Resolved script to: $_entrypoint"); |
| 59 return resolved.toString(); | 63 |
| 64 return _entrypoint.toString(); | |
| 60 } | 65 } |
| 61 | 66 |
| 62 String _resolveUri(String base, String userString) { | 67 String _resolveUri(String base, String userString) { |
| 63 var baseUri = new Uri.fromString(base); | 68 var baseUri = new Uri.fromString(base); |
| 64 _logResolution("# Resolving: $userString from $base"); | 69 _logResolution("# Resolving: $userString from $base"); |
| 65 var resolved = baseUri.resolve(userString); | 70 var resolved = baseUri.resolve(userString); |
| 66 _logResolution("# Resolved to: $resolved"); | 71 _logResolution("# Resolved to: $resolved"); |
| 67 return resolved.toString(); | 72 return resolved.toString(); |
| 68 } | 73 } |
| 69 | 74 |
| 70 String _resolveExtensionUri(String base, String userString) { | 75 String _resolveExtensionUri(String base, String userString) { |
| 71 var uri = new Uri.fromString(userString); | 76 var uri = new Uri.fromString(userString); |
| 72 if ("dart-ext" != uri.scheme) { | 77 if ("dart-ext" != uri.scheme) { |
| 73 throw "Not a Dart extension uri: $uri"; | 78 throw "Not a Dart extension uri: $uri"; |
| 74 } | 79 } |
| 75 var schemelessUri = new Uri(path: uri.path); | 80 var schemelessUri = new Uri(path: uri.path); |
| 76 var baseUri = new Uri.fromString(base); | 81 var baseUri = new Uri.fromString(base); |
| 77 _logResolution("# Resolving: $userString from $base"); | 82 _logResolution("# Resolving: $userString from $base"); |
| 78 var resolved = baseUri.resolveUri(schemelessUri); | 83 var resolved = baseUri.resolveUri(schemelessUri); |
| 79 resolved = new Uri(scheme: 'dart-ext', path: resolved.path); | 84 resolved = new Uri(scheme: 'dart-ext', path: resolved.path); |
| 80 _logResolution("# Resolved to: $resolved"); | 85 _logResolution("# Resolved to: $resolved"); |
| 81 return resolved.toString(); | 86 return resolved.toString(); |
| 82 } | 87 } |
| 83 | 88 |
| 84 String _filePathFromUri(String userUri) { | 89 String _filePathFromUri(String userUri) { |
| 85 var uri = new Uri.fromString(userUri); | 90 var uri = new Uri.fromString(userUri); |
| 86 _logResolution("# Getting file path from: $uri"); | 91 _logResolution("# Getting file path from: $uri"); |
| 87 if ("file" != uri.scheme) { | 92 |
| 88 // Only handling file URIs in standalone binary. | 93 switch (uri.scheme) { |
| 89 _logResolution("# Not a file URI."); | 94 case 'file': return _filePathFromFileUri(uri); |
| 90 throw "Not a file uri: $uri"; | 95 case 'package': return _filePathFromPackageUri(uri); |
| 96 | |
| 97 default: | |
| 98 // Only handling file and package URIs in standalone binary. | |
| 99 _logResolution("# Not a file or package URI."); | |
| 100 throw "Not a known scheme: $uri"; | |
| 91 } | 101 } |
| 102 } | |
| 103 | |
| 104 String _filePathFromFileUri(Uri uri) { | |
| 105 if (uri.domain != '') { | |
| 106 throw "URIs using the 'file:' scheme may not contain a domain."; | |
| 107 } | |
| 108 | |
| 92 var path = uri.path; | 109 var path = uri.path; |
| 93 _logResolution("# Path: $path"); | 110 _logResolution("# Path: $path"); |
| 94 if (_is_windows) { | 111 if (_is_windows) { |
| 95 // Drop the leading / before the drive letter. | 112 // Drop the leading / before the drive letter. |
| 96 path = path.substring(1); | 113 path = path.substring(1); |
| 97 _logResolution("# path: $path"); | 114 _logResolution("# path: $path"); |
| 98 } | 115 } |
| 99 return path; | 116 return path; |
| 100 } | 117 } |
| 118 | |
| 119 String _filePathFromPackageUri(Uri uri) { | |
| 120 if (uri.domain != '') { | |
| 121 var path = (uri.path != '') ? '${uri.domain}${uri.path}' : uri.domain; | |
| 122 var right = 'package:$path'; | |
| 123 var wrong = 'package://$path'; | |
| 124 | |
| 125 throw "URIs using the 'package:' scheme should look like " + | |
| 126 "'$right', not '$wrong'."; | |
| 127 } | |
| 128 | |
| 129 var path = _entrypoint.resolve('packages/${uri.path}').path; | |
|
srdjan
2012/04/11 19:48:13
This probably does not work on windows....
Bob Nystrom
2012/04/11 20:28:04
I think that's OK, but I'm not sure. I don't see a
Ivan Posva
2012/04/11 20:47:58
As far as I can tell URIs contain forward slashes
| |
| 130 _logResolution("# Package: $path"); | |
| 131 return path; | |
| 132 } | |
| OLD | NEW |