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

Unified Diff: utils/pub/path_source.dart

Issue 12294039: Support relative paths in path dependencies. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise Created 7 years, 10 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 | « utils/pub/lock_file.dart ('k') | utils/pub/pubspec.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/path_source.dart
diff --git a/utils/pub/path_source.dart b/utils/pub/path_source.dart
index 123a3086c2ed0b3a8c5d546e6a12521cf3e897d2..69471f8588dcf4db8a8065d223f5c50534e1bfd8 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, id.description["path"], destination,
+ 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 "
@@ -75,4 +107,4 @@ class PathSource extends Source {
throw new FormatException("Could not find package '$name' at '$dir'.");
}
}
-}
+}
« no previous file with comments | « utils/pub/lock_file.dart ('k') | utils/pub/pubspec.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698