Skip to content
Snippets Groups Projects
Commit c4a70483 authored by nweiz@google.com's avatar nweiz@google.com Committed by Natalie Weizenbaum
Browse files

Clean up various ways we find paths in pub.

This makes it so that it's never necessary to pass in DART_SDK.

Review URL: https://codereview.chromium.org//14449004

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge@21914 260f80e4-7a28-3924-810f-c04153c831b5
parent a7d10534
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
/// Helper functionality to make working with IO easier.
library io;
library pub.io;
import 'dart:async';
import 'dart:io';
......@@ -253,22 +253,8 @@ void createPackageSymlink(String name, String target, String symlink,
}
/// Resolves [target] relative to the root directory of pub.
String relativeToPub(String target) {
var scriptPath = new File(new Options().script).fullPathSync();
// Walk up until we hit the "internal(s)" directory. This lets us figure out
// where we are if this function is called from pub.dart, one of the tests, or
// from the SDK.
var internalDir = path.dirname(scriptPath);
while (path.basename(internalDir) != '_internal') {
if (path.basename(internalDir) == '') {
throw new Exception('Could not find path to pub.');
}
internalDir = path.dirname(internalDir);
}
return path.normalize(path.join(internalDir, 'pub', target));
}
String relativeToPub(String target) => path.normalize(path.join(
path.dirname(libraryPath('pub.io')), '..', '..', target));
/// A line-by-line stream of standard input.
final Stream<String> stdinLines = streamToLines(
......
......@@ -28,8 +28,8 @@ String get rootDirectory {
return dir;
}
throw new Exception('DART_SDK environment variable not set, unable to find '
'the SDK.');
// Assume the Dart executable is always coming from the SDK.
return path.dirname(path.dirname(new Options().executable));
}
/// Gets the SDK's revision number formatted to be a semantic version.
......
......@@ -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.
......
......@@ -6,6 +6,8 @@ library pub_tests;
import 'dart:io';
import '../lib/src/sdk.dart' as sdk;
import 'package:pathos/path.dart' as path;
import 'package:scheduled_test/scheduled_process.dart';
import 'package:scheduled_test/scheduled_test.dart';
......@@ -28,9 +30,8 @@ main() {
// the built SDK directory, and not the live pub code directly in the repo.
integration('parse the real SDK "version" file', () {
// Get the path to the pub binary in the SDK.
var dartPath = new Options().executable;
var pubPath = path.join(path.dirname(dartPath), "pub");
if (Platform.operatingSystem == "windows") pubPath = '$pubPath.bat';
var pubPath = path.join(sdk.rootDirectory, 'bin',
Platform.operatingSystem == "windows" ? "pub.bat" : "pub");
var pub = new ScheduledProcess.start(pubPath, ['version']);
expect(pub.nextLine(), completion(startsWith("Pub")));
......
......@@ -272,12 +272,8 @@ void _integration(String description, void body(), [Function testFn]) {
/// Get the path to the root "pub/test" directory containing the pub
/// tests.
String get testDirectory {
var dir = new Options().script;
while (path.basename(dir) != 'test') dir = path.dirname(dir);
return path.absolute(dir);
}
String get testDirectory =>
path.absolute(path.dirname(libraryPath('test_pub')));
/// Schedules renaming (moving) the directory at [from] to [to], both of which
/// are assumed to be relative to [sandboxDir].
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment