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 pub.sdk; | 6 library pub.sdk; |
7 | 7 |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
11 | 11 |
12 import 'io.dart'; | 12 import 'io.dart'; |
13 import 'version.dart'; | 13 import 'version.dart'; |
14 | 14 |
15 /// Matches an Eclipse-style SDK version number. This is four dotted numbers | |
16 /// (major, minor, patch, build) with an optional suffix attached to the build | |
17 /// number. | |
18 final _versionPattern = new RegExp(r'^(\d+)\.(\d+)\.(\d+)\.(\d+.*)$'); | |
19 | |
20 /// Gets the path to the root directory of the SDK. | 15 /// Gets the path to the root directory of the SDK. |
21 String get rootDirectory { | 16 String get rootDirectory { |
22 // Assume the Dart executable is always coming from the SDK. | 17 // Assume the Dart executable is always coming from the SDK. |
23 return path.dirname(path.dirname(Platform.executable)); | 18 return path.dirname(path.dirname(Platform.executable)); |
24 } | 19 } |
25 | 20 |
26 /// The SDK's revision number formatted to be a semantic version. | 21 /// The SDK's revision number formatted to be a semantic version. |
27 /// | 22 /// |
28 /// This can be set so that the version solver tests can artificially select | 23 /// This can be set so that the version solver tests can artificially select |
29 /// different SDK versions. | 24 /// different SDK versions. |
30 Version version = _getVersion(); | 25 Version version = _getVersion(); |
31 | 26 |
32 /// Is `true` if the current SDK is an unreleased bleeding edge version. | |
33 bool get isBleedingEdge { | |
34 // The live build is locked to the magical old number "0.1.2+<stuff>". | |
35 return version.major == 0 && version.minor == 1 && version.patch == 2; | |
36 } | |
37 | |
38 /// Parse an Eclipse-style version number using the SDK's versioning convention. | |
39 Version parseVersion(String version) { | |
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: $version"); | |
46 } | |
47 | |
48 // Semantic versions cannot use "_". | |
49 var build = match[4].replaceAll('_', '.'); | |
50 | |
51 return new Version( | |
52 int.parse(match[1]), int.parse(match[2]), int.parse(match[3]), | |
53 build: build); | |
54 } | |
55 | |
56 /// Determine the SDK's version number. | 27 /// Determine the SDK's version number. |
57 Version _getVersion() { | 28 Version _getVersion() { |
58 // Some of the pub integration tests require an SDK version number, but the | 29 // Some of the pub integration tests require an SDK version number, but the |
59 // tests on the bots are not run from a built SDK so this lets us avoid | 30 // tests on the bots are not run from a built SDK so this lets us avoid |
60 // parsing the missing version file. | 31 // parsing the missing version file. |
61 var sdkVersion = Platform.environment["_PUB_TEST_SDK_VERSION"]; | 32 var sdkVersion = Platform.environment["_PUB_TEST_SDK_VERSION"]; |
62 if (sdkVersion != null) return new Version.parse(sdkVersion); | 33 if (sdkVersion != null) return new Version.parse(sdkVersion); |
63 | 34 |
64 // Read the "version" file. | 35 // Read the "version" file. |
65 var revisionPath = path.join(rootDirectory, "version"); | 36 var revisionPath = path.join(rootDirectory, "version"); |
66 var version = readTextFile(revisionPath).trim(); | 37 var version = readTextFile(revisionPath).trim(); |
67 return parseVersion(version); | 38 return new Version.parse(version); |
68 } | 39 } |
OLD | NEW |