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

Unified Diff: utils/pub/path_source.dart

Issue 12280019: Revert "Support relative paths in path dependencies." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 b985a4afc8cd2461611c43f2303bab0af51dfd5a..123a3086c2ed0b3a8c5d546e6a12521cf3e897d2 100644
--- a/utils/pub/path_source.dart
+++ b/utils/pub/path_source.dart
@@ -25,77 +25,45 @@ class PathSource extends Source {
Future<Pubspec> describe(PackageId id) {
return defer(() {
_validatePath(id.name, id.description);
- return new Pubspec.load(id.name, id.description["path"],
- systemCache.sources);
+ return new Pubspec.load(id.name, id.description, systemCache.sources);
});
}
- Future<bool> install(PackageId id, String destination) {
+ Future<bool> install(PackageId id, String path) {
return defer(() {
try {
_validatePath(id.name, id.description);
} on FormatException catch(err) {
return false;
}
-
- return createPackageSymlink(id.name, destination, id.description["path"],
- relative: id.description["relative"]);
+ return createPackageSymlink(id.name, id.description, path);
}).then((_) => true);
}
- /// 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;
- }
-
+ void validateDescription(description, {bool fromLockFile: false}) {
if (description is! String) {
throw new FormatException("The description must be a path string.");
}
-
- // 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"];
+ /// 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'.");
+ }
if (fileExists(dir)) {
throw new FormatException(
« 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