Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library docgen.package_helpers; | 5 library docgen.package_helpers; |
| 6 | 6 |
| 7 import 'exports/source_mirrors.dart'; | 7 import 'exports/source_mirrors.dart'; |
| 8 import 'generator.dart' show pubScript; | 8 import 'generator.dart' show pubScript; |
| 9 | 9 |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| 11 import 'package:path/path.dart' as path; | 11 import 'package:path/path.dart' as path; |
| 12 import 'package:yaml/yaml.dart'; | 12 import 'package:yaml/yaml.dart'; |
| 13 | 13 |
| 14 /// Helper accessor to determine the full pathname of the root of the dart | 14 /// Helper accessor to determine the full pathname of the root of the dart |
|
ricow1
2014/11/20 07:38:30
this comment seems out of date, we are not necessa
| |
| 15 /// checkout. We can be in one of three situations: | 15 /// checkout. We can be in one of three situations: |
| 16 /// 1) Running from pkg/docgen/bin/docgen.dart | 16 /// 1) Running from pkg/docgen/bin/docgen.dart |
| 17 /// 2) Running from a snapshot in a build, | 17 /// 2) Running from a snapshot in a build, |
| 18 /// e.g. xcodebuild/ReleaseIA32/dart-sdk/bin | 18 /// e.g. xcodebuild/ReleaseIA32/dart-sdk/bin |
| 19 /// 3) Running from a built distribution, | 19 /// 3) Running from a built distribution, |
| 20 /// e.g. ...somename/dart-sdk/bin/snapshots | 20 /// e.g. ...somename/dart-sdk/bin/snapshots |
| 21 String get rootDirectory { | 21 String get rootDirectory { |
| 22 if (_rootDirectoryCache != null) return _rootDirectoryCache; | 22 if (_rootDirectoryCache != null) return _rootDirectoryCache; |
| 23 var scriptDir = path.absolute(path.dirname(Platform.script.toFilePath())); | 23 var scriptDir = path.absolute(path.dirname(Platform.script.toFilePath())); |
| 24 var root = scriptDir; | 24 var root = scriptDir; |
| 25 var base = path.basename(root); | 25 var base = path.basename(root); |
| 26 // When we find dart-sdk or sdk we are one level below the root. | 26 var found = false; |
| 27 while (base != 'dart-sdk' && base != 'sdk' && base != 'pkg') { | 27 // 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?
| |
| 28 while (!found && base != 'sdk' && base != 'pkg') { | |
|
ricow1
2014/11/20 07:38:30
looking at the 3 examples in the function comment
| |
| 28 root = path.dirname(root); | 29 root = path.dirname(root); |
| 29 base = path.basename(root); | 30 base = path.basename(root); |
| 31 // Look for something that looks like the dart-sdk directory, which we | |
| 32 // expect to be in the path above us and to have a 'version' file containing | |
| 33 // the same version as we are running. | |
|
ricow1
2014/11/20 07:38:30
could you elaborate on _why_ it is important for t
| |
| 34 if (hasMatchingVersionFile(root)) { | |
| 35 found = true; | |
| 36 } | |
| 30 if (root == base) { | 37 if (root == base) { |
| 31 // We have reached the root of the filesystem without finding anything. | 38 // We have reached the root of the filesystem without finding anything. |
| 32 throw new FileSystemException("Cannot find SDK directory starting from ", | 39 throw new FileSystemException("Cannot find SDK directory starting from ", |
| 33 scriptDir); | 40 scriptDir); |
| 34 } | 41 } |
| 35 } | 42 } |
| 36 _rootDirectoryCache = path.dirname(root); | 43 _rootDirectoryCache = path.dirname(root); |
| 37 return _rootDirectoryCache; | 44 return _rootDirectoryCache; |
| 38 } | 45 } |
| 39 String _rootDirectoryCache; | 46 String _rootDirectoryCache; |
| 40 | 47 |
| 48 | |
| 49 /// Does this directory contain a version file that has the same version as | |
| 50 /// we do. | |
| 51 bool hasMatchingVersionFile(String root) { | |
| 52 var versionFile = new File(path.join(root, 'version')); | |
| 53 if (!versionFile.existsSync()) return false; | |
| 54 var version = versionFile.readAsStringSync().trim(); | |
| 55 var vmVersion = Platform.version; | |
| 56 return vmVersion.startsWith(withoutEdge(version)); | |
| 57 } | |
| 58 | |
| 59 /// Returns a version string with the bleeding edge revision number removed, | |
| 60 /// if it was present. | |
| 61 String withoutEdge(String version) => | |
| 62 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 :-)
| |
| 63 | |
| 64 /// Returns the index in version in which the bleeding edge indicator "edge." | |
| 65 /// occurs. | |
| 66 int edgePosition(String version) => | |
| 67 version.indexOf("edge.") == -1 ? version.length : version.indexOf("edge"); | |
| 68 | |
| 41 /// Given a LibraryMirror that is a library, return the name of the directory | 69 /// Given a LibraryMirror that is a library, return the name of the directory |
| 42 /// holding the package information for that library. If the library is not | 70 /// holding the package information for that library. If the library is not |
| 43 /// part of a package, return null. | 71 /// part of a package, return null. |
| 44 String getPackageDirectory(LibraryMirror mirror) { | 72 String getPackageDirectory(LibraryMirror mirror) { |
| 45 var file = mirror.uri.toFilePath(); | 73 var file = mirror.uri.toFilePath(); |
| 46 // Any file that's in a package will be in a directory of the form | 74 // Any file that's in a package will be in a directory of the form |
| 47 // packagename/lib/.../filename.dart, so we know that a possible | 75 // packagename/lib/.../filename.dart, so we know that a possible |
| 48 // package directory is at least in the directory above the one containing | 76 // package directory is at least in the directory above the one containing |
| 49 // [file] | 77 // [file] |
| 50 var directoryAbove = path.dirname(path.dirname(file)); | 78 var directoryAbove = path.dirname(path.dirname(file)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 while (!_pubspecFor(dir).existsSync()) { | 145 while (!_pubspecFor(dir).existsSync()) { |
| 118 var newDir = path.dirname(dir); | 146 var newDir = path.dirname(dir); |
| 119 if (newDir == dir) return null; | 147 if (newDir == dir) return null; |
| 120 dir = newDir; | 148 dir = newDir; |
| 121 } | 149 } |
| 122 return dir; | 150 return dir; |
| 123 } | 151 } |
| 124 | 152 |
| 125 File _pubspecFor(String directoryName) => | 153 File _pubspecFor(String directoryName) => |
| 126 new File(path.join(directoryName, 'pubspec.yaml')); | 154 new File(path.join(directoryName, 'pubspec.yaml')); |
| OLD | NEW |