Chromium Code Reviews| Index: utils/pub/sdk.dart |
| diff --git a/utils/pub/sdk.dart b/utils/pub/sdk.dart |
| index f8db76c173ca4c1a0dc2090b8ae178d5c9ccd560..f44ab6556e03c200a0b08dd5a30e9b9359ec0cd3 100644 |
| --- a/utils/pub/sdk.dart |
| +++ b/utils/pub/sdk.dart |
| @@ -11,6 +11,8 @@ import '../../pkg/path/lib/path.dart' as path; |
| import 'log.dart' as log; |
| import 'version.dart'; |
| +final _versionPattern = new RegExp(r'^(\d+)\.(\d+)\.(\d+)\.(\d+)(.*)$'); |
|
Emily Fortuna
2013/01/23 23:15:19
regex-licious! Want to put a comment above this ju
Bob Nystrom
2013/01/23 23:20:35
Done.
|
| + |
| /// Gets the path to the root directory of the SDK. |
| String get rootDirectory { |
| // If the environment variable was provided, use it. This is mainly used for |
| @@ -30,9 +32,23 @@ String get rootDirectory { |
| /// Gets the SDK's revision number formatted to be a semantic version. |
| Version version = _getVersion(); |
| -/// Determine the SDK revision number. |
| +/// Determine the SDK's version number. |
| Version _getVersion() { |
| - var revisionPath = path.join(rootDirectory, "revision"); |
| - var revision = new File(revisionPath).readAsStringSync(); |
| - return new Version.parse("0.0.0-r.${revision.trim()}"); |
| + var revisionPath = path.join(rootDirectory, "version"); |
| + var version = new File(revisionPath).readAsStringSync().trim(); |
| + |
| + // Given a version file like: 0.1.2.0_r17495 |
| + // We create a semver like: 0.1.2+0._r17495 |
| + var match = _versionPattern.firstMatch(version); |
| + if (match == null) { |
| + throw new FormatException("The Dart SDK's 'version' file was not in a " |
| + "format pub could recognize. Found: $revision"); |
| + } |
| + |
| + var build = match[4]; |
| + if (match[5].length > 0) build = '$build.${match[5]}'; |
| + |
| + return new Version( |
| + int.parse(match[1]), int.parse(match[2]), int.parse(match[3]), |
| + build: build); |
| } |