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

Unified Diff: sdk/lib/_internal/pub/lib/src/utils.dart

Issue 14449004: Clean up various ways we find paths in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes. Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/sdk.dart ('k') | sdk/lib/_internal/pub/test/real_version_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/lib/src/utils.dart
diff --git a/sdk/lib/_internal/pub/lib/src/utils.dart b/sdk/lib/_internal/pub/lib/src/utils.dart
index 36cc37157d075f040febf46739f0a755b31cd2ed..5894b99ac3c5bd4b3ec3e94755469720f03a9e79 100644
--- a/sdk/lib/_internal/pub/lib/src/utils.dart
+++ b/sdk/lib/_internal/pub/lib/src/utils.dart
@@ -9,6 +9,7 @@ import 'dart:async';
import 'dart:crypto';
import 'dart:io';
import 'dart:isolate';
+import 'dart:mirrors';
import 'dart:uri';
/// A pair of values.
@@ -360,6 +361,27 @@ Future awaitObject(object) {
});
}
+/// Returns the path to the library named [libraryName]. The library name must
+/// be globally unique, or the wrong library path may be returned.
+String libraryPath(String libraryName) =>
+ fileUriToPath(currentMirrorSystem().libraries[new Symbol(libraryName)].uri);
+
+/// Converts a `file:` [Uri] to a local path string.
+String fileUriToPath(Uri uri) {
+ if (uri.scheme != 'file') {
+ throw new ArgumentError("Uri $uri must have scheme 'file:'.");
+ }
+ if (Platform.operatingSystem != 'windows') return uri.path;
+ if (uri.path.startsWith("/")) {
+ // Drive-letter paths look like "file:///C:/path/to/file". The replaceFirst
+ // removes the extra initial slash.
+ return uri.path.replaceFirst("/", "").replaceAll("/", "\\");
+ } else {
+ // Network paths look like "file://hostname/path/to/file".
+ return "\\\\${uri.path.replaceAll("/", "\\")}";
+ }
+}
+
/// An exception class for exceptions that are intended to be seen by the user.
/// These exceptions won't have any debugging information printed when they're
/// thrown.
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/sdk.dart ('k') | sdk/lib/_internal/pub/test/real_version_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698