| Index: utils/pub/path_source.dart
|
| diff --git a/utils/pub/path_source.dart b/utils/pub/path_source.dart
|
| index 123a3086c2ed0b3a8c5d546e6a12521cf3e897d2..b985a4afc8cd2461611c43f2303bab0af51dfd5a 100644
|
| --- a/utils/pub/path_source.dart
|
| +++ b/utils/pub/path_source.dart
|
| @@ -25,46 +25,78 @@ class PathSource extends Source {
|
| Future<Pubspec> describe(PackageId id) {
|
| return defer(() {
|
| _validatePath(id.name, id.description);
|
| - return new Pubspec.load(id.name, id.description, systemCache.sources);
|
| + return new Pubspec.load(id.name, id.description["path"],
|
| + systemCache.sources);
|
| });
|
| }
|
|
|
| - Future<bool> install(PackageId id, String path) {
|
| + Future<bool> install(PackageId id, String destination) {
|
| return defer(() {
|
| try {
|
| _validatePath(id.name, id.description);
|
| } on FormatException catch(err) {
|
| return false;
|
| }
|
| - return createPackageSymlink(id.name, id.description, path);
|
| +
|
| + return createPackageSymlink(id.name, destination, id.description["path"],
|
| + relative: id.description["relative"]);
|
| }).then((_) => true);
|
| }
|
|
|
| - void validateDescription(description, {bool fromLockFile: false}) {
|
| + /// Parses a path dependency. This takes in a path string and returns a map.
|
| + /// The "path" key will be the original path but resolves relative to the
|
| + /// containing path. The "relative" key will be `true` if the original path
|
| + /// was relative.
|
| + ///
|
| + /// A path coming from a pubspec is a simple string. From a lock file, it's
|
| + /// an expanded {"path": ..., "relative": ...} map.
|
| + dynamic parseDescription(String containingPath, description,
|
| + {bool fromLockFile: false}) {
|
| + if (fromLockFile) {
|
| + if (description is! Map) {
|
| + throw new FormatException("The description must be a map.");
|
| + }
|
| +
|
| + if (description["path"] is! String) {
|
| + throw new FormatException("The 'path' field of the description must "
|
| + "be a string.");
|
| + }
|
| +
|
| + if (description["relative"] is! bool) {
|
| + throw new FormatException("The 'relative' field of the description "
|
| + "must be a boolean.");
|
| + }
|
| +
|
| + return description;
|
| + }
|
| +
|
| if (description is! String) {
|
| throw new FormatException("The description must be a path string.");
|
| }
|
| - }
|
|
|
| - /// Ensures that [dir] is a valid path. It must be an absolute path that
|
| - /// points to an existing directory. Throws a [FormatException] if the path
|
| - /// is invalid.
|
| - void _validatePath(String name, String dir) {
|
| - // Relative paths are not (currently) allowed because the user would expect
|
| - // them to be relative to the pubspec where the dependency appears. That in
|
| - // turn means that two pubspecs in different locations with the same
|
| - // relative path dependency could refer to two different packages. That
|
| - // violates pub's rule that a description should uniquely identify a
|
| - // package.
|
| - //
|
| - // At some point, we may want to loosen this, but it will mean tracking
|
| - // where a given PackageId appeared.
|
| - if (!path.isAbsolute(dir)) {
|
| - throw new FormatException(
|
| - "Path dependency for package '$name' must be an absolute path. "
|
| - "Was '$dir'.");
|
| + // Resolve the path relative to the containing file path, and remember
|
| + // whether the original path was relative or absolute.
|
| + bool isRelative = path.isRelative(description);
|
| + if (path.isRelative(description)) {
|
| + // Can't handle relative paths coming from pubspecs that are not on the
|
| + // local file system.
|
| + assert(containingPath != null);
|
| +
|
| + description = path.join(path.dirname(containingPath), description);
|
| }
|
|
|
| + return {
|
| + "path": description,
|
| + "relative": isRelative
|
| + };
|
| + }
|
| +
|
| + /// Ensures that [description] is a valid path description. It must be a map,
|
| + /// with a "path" key containing a path that points to an existing directory.
|
| + /// Throws a [FormatException] if the path is invalid.
|
| + void _validatePath(String name, description) {
|
| + var dir = description["path"];
|
| +
|
| if (fileExists(dir)) {
|
| throw new FormatException(
|
| "Path dependency for package '$name' must refer to a "
|
|
|