Chromium Code Reviews| 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..6bb2f61bdca4af33c96e57689375f1e13fd93fec 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. |
|
ricow1
2014/11/20 07:38:30
comment don't match the case where we hit pkg?
|
| + while (!found && base != 'sdk' && base != 'pkg') { |
|
ricow1
2014/11/20 07:38:30
looking at the 3 examples in the function comment
|
| 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. |
|
ricow1
2014/11/20 07:38:30
could you elaborate on _why_ it is important for t
|
| + 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,27 @@ 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(withoutEdge(version)); |
| +} |
| + |
| +/// Returns a version string with the bleeding edge revision number removed, |
| +/// if it was present. |
| +String withoutEdge(String version) => |
| + version.substring(0, edgePosition(version)); |
|
ricow1
2014/11/20 07:38:30
remove edgePosition below and just do:
Sting witho
ricow1
2014/11/20 07:55:00
s/Sting/String :-)
|
| + |
| +/// Returns the index in version in which the bleeding edge indicator "edge." |
| +/// occurs. |
| +int edgePosition(String version) => |
| + version.indexOf("edge.") == -1 ? version.length : version.indexOf("edge"); |
| + |
| /// 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. |