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

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

Issue 737903002: Let docgen detect a dart-sdk directory that's differently named (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cleanup Created 6 years, 1 month 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/src/package_helpers.dart
diff --git a/pkg/docgen/lib/src/package_helpers.dart b/pkg/docgen/lib/src/package_helpers.dart
index ca189fa15c08d64b463e791d02f2a1805d744819..e082d49dac733a5af21a1013db73da4c93912dfc 100644
--- a/pkg/docgen/lib/src/package_helpers.dart
+++ b/pkg/docgen/lib/src/package_helpers.dart
@@ -23,10 +23,17 @@ String get rootDirectory {
var scriptDir = path.absolute(path.dirname(Platform.script.toFilePath()));
var root = scriptDir;
var base = path.basename(root);
- // When we find dart-sdk or sdk we are one level below the root.
- while (base != 'dart-sdk' && base != 'sdk' && base != 'pkg') {
+ var found = false;
+ // When we find a version file or sdk we are one level below the root.
+ while (!found && base != 'sdk' && base != 'pkg') {
root = path.dirname(root);
base = path.basename(root);
+ // Look for something that looks like the dart-sdk directory, which we
+ // expect to be in the path above us and to have a 'version' file containing
+ // the same version as we are running.
+ if (hasMatchingVersionFile(root)) {
+ found = true;
+ }
if (root == base) {
// We have reached the root of the filesystem without finding anything.
throw new FileSystemException("Cannot find SDK directory starting from ",
@@ -38,6 +45,17 @@ String get rootDirectory {
}
String _rootDirectoryCache;
+
+/// Does this directory contain a version file that has the same version as
+/// we do.
+bool hasMatchingVersionFile(String root) {
+ var versionFile = new File(path.join(root, 'version'));
+ if (!versionFile.existsSync()) return false;
+ var version = versionFile.readAsStringSync().trim();
+ var vmVersion = Platform.version;
+ return vmVersion.startsWith(version);
+}
+
/// Given a LibraryMirror that is a library, return the name of the directory
/// holding the package information for that library. If the library is not
/// part of a package, return null.
« 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