Index: utils/pub/io.dart |
diff --git a/utils/pub/io.dart b/utils/pub/io.dart |
index 25e8d7fde85e7ef7c6236afdce4a0666bda86360..3d9a366264f2edfe3ca913ed3f1b4476e4695cd7 100644 |
--- a/utils/pub/io.dart |
+++ b/utils/pub/io.dart |
@@ -280,6 +280,55 @@ Future<File> createSymlink(from, to) { |
} |
/** |
+ * Creates a new symlink that creates an alias from the package [from] to [to], |
+ * both of which can be a [String], [File], or [Directory]. Returns a [Future] |
+ * which completes to the symlink file (i.e. [to]). |
+ * |
+ * Unlike [createSymlink], this has heuristics to detect if [from] is using |
+ * the old or new style of package layout. If it's using the new style, then |
+ * it will create a symlink to the "lib" directory contained inside that |
+ * package directory. Otherwise, it just symlinks to the package directory |
+ * itself. |
+ */ |
+// TODO(rnystrom): Remove this when old style packages are no longer supported. |
+// See: http://code.google.com/p/dart/issues/detail?id=4964. |
+Future<File> createPackageSymlink(String name, from, to, |
nweiz
2012/09/11 21:07:47
Can't you infer the name from "from"?
Bob Nystrom
2012/09/11 21:39:01
I could, but every callsite knew the name so I fig
|
+ [bool isSelfLink = false]) { |
+ // If from contains any Dart files at the top level (aside from build.dart) |
+ // we assume that means it's an old style package. |
+ return listDir(from).chain((contents) { |
+ var isOldStyle = contents.some( |
+ (file) => file.endsWith('.dart') && basename(file) != 'build.dart'); |
+ |
+ if (isOldStyle) { |
+ if (isSelfLink) { |
+ printError('Warning: Package "$name" is using a deprecated layout.'); |
+ printError('See http://www.dartlang.org/docs/pub-package-manager/' |
+ 'package-layout.html for details.'); |
+ |
+ // Do not create self-links on old style packages. |
+ return new Future.immediate(to); |
+ } else { |
+ return createSymlink(from, to); |
+ } |
+ } |
+ |
+ // It's a new style package, so symlink to the 'lib' directory. But only |
+ // if the package actually *has* one. Otherwise, we won't create a |
+ // symlink at all. |
+ from = join(from, 'lib'); |
+ return dirExists(from).chain((exists) { |
+ if (exists) { |
+ return createSymlink(from, to); |
+ } else { |
+ printError('Warning: Package "$name" does not have a "lib" directory.'); |
+ return new Future.immediate(to); |
+ } |
+ }); |
+ }); |
+} |
+ |
+/** |
* Given [entry] which may be a [String], [File], or [Directory] relative to |
* the current working directory, returns its full canonicalized path. |
*/ |