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

Unified Diff: pkg/docgen/lib/docgen.dart

Issue 175693005: Don't assume the pubspec is only one level up from a library (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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');
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698