Chromium Code Reviews| 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. |
| */ |