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

Unified Diff: utils/pub/entrypoint.dart

Issue 10900015: Create packages directories in test/ and bin/ as well as at the top level. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 | « no previous file | utils/tests/pub/pub_install_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/entrypoint.dart
diff --git a/utils/pub/entrypoint.dart b/utils/pub/entrypoint.dart
index 2758707385ebd577c65b46c00a9819d6009fb562..306da57101a544dab4e75965d894094cb2d4b949 100644
--- a/utils/pub/entrypoint.dart
+++ b/utils/pub/entrypoint.dart
@@ -148,7 +148,9 @@ class Entrypoint {
if (id.source is RootSource) return new Future.immediate(id);
return install(id);
}));
- }).chain(_saveLockFile).chain(_installSelfReference);
+ }).chain(_saveLockFile)
+ .chain(_installSelfReference)
+ .chain(_linkSecondaryPackageDirs);
}
/**
@@ -227,6 +229,64 @@ class Entrypoint {
}
/**
+ * If `bin/` or `test/` directories exist, symlink `packages/` into them so
+ * that their entrypoints can be run. Do the same for any subdirectories of
+ * `test/`.
+ */
+ Future _linkSecondaryPackageDirs(_) {
+ var binDir = join(root.dir, 'bin');
+ var testDir = join(root.dir, 'test');
+ return dirExists(binDir).chain((exists) {
+ if (!exists) return new Future.immediate(null);
+ return _linkSecondaryPackageDir(binDir);
+ }).chain((_) => dirExists(testDir)).chain((exists) {
+ if (!exists) return new Future.immediate(null);
+ return _linkSecondaryPackageDir(testDir)
+ .chain((_) => _listDirWithoutPackages(testDir))
+ .chain((testFiles) {
+ return Futures.wait(testFiles.map((testFile) {
+ return dirExists(testFile).chain((isDir) {
+ if (!isDir) return new Future.immediate(null);
+ return _linkSecondaryPackageDir(testFile);
+ });
+ }));
+ });
+ });
+ }
+
+ // TODO(nweiz): roll this into [listDir] in io.dart once issue 4775 is fixed.
+ /**
+ * Recursively lists the contents of [dir], excluding hidden `.DS_Store` files
+ * and `package` files.
+ */
+ Future<List<String>> _listDirWithoutPackages(dir) {
Bob Nystrom 2012/08/29 16:56:48 Instead of recurisively building up a list of dire
nweiz 2012/08/29 19:57:58 I didn't do that because it doesn't seem like that
+ return listDir(dir).chain((files) {
+ return Futures.wait(files.map((file) {
+ if (basename(file) == 'packages') return new Future.immediate([]);
+ return dirExists(file).chain((isDir) {
+ if (!isDir) return new Future.immediate([]);
+ return _listDirWithoutPackages(file);
+ }).transform((subfiles) {
+ var fileAndSubfiles = [file];
+ fileAndSubfiles.addAll(subfiles);
+ return fileAndSubfiles;
+ });
+ }));
+ }).transform(flatten);
+ }
+
+ /**
+ * Creates a symlink to the `packages` directory in [dir] if none exists.
+ */
+ Future _linkSecondaryPackageDir(String dir) {
+ var to = join(dir, 'packages');
+ return exists(to).chain((exists) {
+ if (exists) return new Future.immediate(null);
+ return createSymlink(path, to);
+ });
+ }
+
+ /**
* Validate that the pubspec for the entrypoint exists and specifies the name
* of the root package.
*/
« no previous file with comments | « no previous file | utils/tests/pub/pub_install_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698