OLD | NEW |
---|---|
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 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.
| |
15 | |
14 /// Gets the path to the root directory of the SDK. | 16 /// Gets the path to the root directory of the SDK. |
15 String get rootDirectory { | 17 String get rootDirectory { |
16 // If the environment variable was provided, use it. This is mainly used for | 18 // If the environment variable was provided, use it. This is mainly used for |
17 // the pub tests. | 19 // the pub tests. |
18 var dir = Platform.environment["DART_SDK"]; | 20 var dir = Platform.environment["DART_SDK"]; |
19 if (dir != null) { | 21 if (dir != null) { |
20 log.fine("Using DART_SDK to find SDK at $dir"); | 22 log.fine("Using DART_SDK to find SDK at $dir"); |
21 return dir; | 23 return dir; |
22 } | 24 } |
23 | 25 |
24 var pubDir = path.dirname(new Options().script); | 26 var pubDir = path.dirname(new Options().script); |
25 dir = path.normalize(path.join(pubDir, "../../")); | 27 dir = path.normalize(path.join(pubDir, "../../")); |
26 log.fine("Located SDK at $dir"); | 28 log.fine("Located SDK at $dir"); |
27 return dir; | 29 return dir; |
28 } | 30 } |
29 | 31 |
30 /// Gets the SDK's revision number formatted to be a semantic version. | 32 /// Gets the SDK's revision number formatted to be a semantic version. |
31 Version version = _getVersion(); | 33 Version version = _getVersion(); |
32 | 34 |
33 /// Determine the SDK revision number. | 35 /// Determine the SDK's version number. |
34 Version _getVersion() { | 36 Version _getVersion() { |
35 var revisionPath = path.join(rootDirectory, "revision"); | 37 var revisionPath = path.join(rootDirectory, "version"); |
36 var revision = new File(revisionPath).readAsStringSync(); | 38 var version = new File(revisionPath).readAsStringSync().trim(); |
37 return new Version.parse("0.0.0-r.${revision.trim()}"); | 39 |
40 // Given a version file like: 0.1.2.0_r17495 | |
41 // We create a semver like: 0.1.2+0._r17495 | |
42 var match = _versionPattern.firstMatch(version); | |
43 if (match == null) { | |
44 throw new FormatException("The Dart SDK's 'version' file was not in a " | |
45 "format pub could recognize. Found: $revision"); | |
46 } | |
47 | |
48 var build = match[4]; | |
49 if (match[5].length > 0) build = '$build.${match[5]}'; | |
50 | |
51 return new Version( | |
52 int.parse(match[1]), int.parse(match[2]), int.parse(match[3]), | |
53 build: build); | |
38 } | 54 } |
OLD | NEW |