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

Unified Diff: utils/pub/sdk.dart

Issue 12036065: Make pub use the SDK's "version" file for its version. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Comment regex. Created 7 years, 11 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 | « utils/pub/pub.dart ('k') | utils/tests/pub/install/pub_install_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/sdk.dart
diff --git a/utils/pub/sdk.dart b/utils/pub/sdk.dart
index f8db76c173ca4c1a0dc2090b8ae178d5c9ccd560..0365aab30e398ec9fb52a8065c57aac624116b75 100644
--- a/utils/pub/sdk.dart
+++ b/utils/pub/sdk.dart
@@ -11,6 +11,11 @@ import '../../pkg/path/lib/path.dart' as path;
import 'log.dart' as log;
import 'version.dart';
+/// Matches an Eclipse-style SDK version number. This is four dotted numbers
+/// (major, minor, patch, build) with an optional suffix attached to the build
+/// number.
+final _versionPattern = new RegExp(r'^(\d+)\.(\d+)\.(\d+)\.(\d+)(.*)$');
+
/// 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 +35,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);
}
« no previous file with comments | « utils/pub/pub.dart ('k') | utils/tests/pub/install/pub_install_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698