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

Unified Diff: utils/pub/io.dart

Issue 10916190: Support both new and old style package layouts. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Respond to review. Created 8 years, 3 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/entrypoint.dart ('k') | utils/pub/pub.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
*/
« no previous file with comments | « utils/pub/entrypoint.dart ('k') | utils/pub/pub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698