Chromium Code Reviews| Index: pkg/docgen/lib/docgen.dart |
| diff --git a/pkg/docgen/lib/docgen.dart b/pkg/docgen/lib/docgen.dart |
| index c4aa90598bdf50fd298f2ffcd0ea556457a55aa2..47c7cdb931b9d7c8d2a61670441948e7f0e06696 100644 |
| --- a/pkg/docgen/lib/docgen.dart |
| +++ b/pkg/docgen/lib/docgen.dart |
| @@ -1448,7 +1448,7 @@ class Library extends Indexable { |
| /// Given a LibraryMirror that is a library, return the name of the directory |
| /// holding that library. |
| static String _getRootdir(LibraryMirror mirror) => |
| - path.dirname(path.dirname(mirror.uri.toFilePath())); |
| + _packageDirectoryFor(path.dirname(path.dirname(mirror.uri.toFilePath()))); |
|
kevmoo
2014/02/24 17:49:02
Could you break this out and explain why there are
Alan Knight
2014/02/24 18:14:02
Done.
|
| /// Read a pubspec and return the library name given a [LibraryMirror]. |
| static String _packageName(LibraryMirror mirror) { |
| @@ -1457,6 +1457,21 @@ class Library extends Indexable { |
| return packageNameFor(rootdir); |
| } |
| + /// Recursively walk up from directory name looking for a pubspec. Return |
| + /// the directory that contains it, or null if none is found. |
| + static String _packageDirectoryFor(String directoryName) { |
| + var dir = directoryName; |
| + while (!_pubspecFor(dir).existsSync()) { |
| + var newDir = path.dirname(dir); |
| + if (newDir == dir) return null; |
|
kevmoo
2014/02/24 17:49:02
What happens in the null case?
Alan Knight
2014/02/24 18:14:02
It should indicate that we're not in a package, so
|
| + dir = newDir; |
| + } |
| + return dir; |
| + } |
| + |
| + static File _pubspecFor(String directoryName) => |
| + new File(path.join(directoryName, 'pubspec.yaml')); |
| + |
| /// Read a pubspec and return the library name, given a directory |
| static String packageNameFor(String directoryName) { |
| var pubspecName = path.join(directoryName, 'pubspec.yaml'); |