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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/pub/pub.dart ('k') | utils/tests/pub/install/pub_install_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /// Operations relative to the user's installed Dart SDK. 5 /// Operations relative to the user's installed Dart SDK.
6 library sdk; 6 library sdk;
7 7
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import '../../pkg/path/lib/path.dart' as path; 10 import '../../pkg/path/lib/path.dart' as path;
11 import 'log.dart' as log; 11 import 'log.dart' as log;
12 import 'version.dart'; 12 import 'version.dart';
13 13
14 /// Matches an Eclipse-style SDK version number. This is four dotted numbers
15 /// (major, minor, patch, build) with an optional suffix attached to the build
16 /// number.
17 final _versionPattern = new RegExp(r'^(\d+)\.(\d+)\.(\d+)\.(\d+)(.*)$');
18
14 /// Gets the path to the root directory of the SDK. 19 /// Gets the path to the root directory of the SDK.
15 String get rootDirectory { 20 String get rootDirectory {
16 // If the environment variable was provided, use it. This is mainly used for 21 // If the environment variable was provided, use it. This is mainly used for
17 // the pub tests. 22 // the pub tests.
18 var dir = Platform.environment["DART_SDK"]; 23 var dir = Platform.environment["DART_SDK"];
19 if (dir != null) { 24 if (dir != null) {
20 log.fine("Using DART_SDK to find SDK at $dir"); 25 log.fine("Using DART_SDK to find SDK at $dir");
21 return dir; 26 return dir;
22 } 27 }
23 28
24 var pubDir = path.dirname(new Options().script); 29 var pubDir = path.dirname(new Options().script);
25 dir = path.normalize(path.join(pubDir, "../../")); 30 dir = path.normalize(path.join(pubDir, "../../"));
26 log.fine("Located SDK at $dir"); 31 log.fine("Located SDK at $dir");
27 return dir; 32 return dir;
28 } 33 }
29 34
30 /// Gets the SDK's revision number formatted to be a semantic version. 35 /// Gets the SDK's revision number formatted to be a semantic version.
31 Version version = _getVersion(); 36 Version version = _getVersion();
32 37
33 /// Determine the SDK revision number. 38 /// Determine the SDK's version number.
34 Version _getVersion() { 39 Version _getVersion() {
35 var revisionPath = path.join(rootDirectory, "revision"); 40 var revisionPath = path.join(rootDirectory, "version");
36 var revision = new File(revisionPath).readAsStringSync(); 41 var version = new File(revisionPath).readAsStringSync().trim();
37 return new Version.parse("0.0.0-r.${revision.trim()}"); 42
43 // Given a version file like: 0.1.2.0_r17495
44 // We create a semver like: 0.1.2+0._r17495
45 var match = _versionPattern.firstMatch(version);
46 if (match == null) {
47 throw new FormatException("The Dart SDK's 'version' file was not in a "
48 "format pub could recognize. Found: $revision");
49 }
50
51 var build = match[4];
52 if (match[5].length > 0) build = '$build.${match[5]}';
53
54 return new Version(
55 int.parse(match[1]), int.parse(match[2]), int.parse(match[3]),
56 build: build);
38 } 57 }
OLDNEW
« 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