@@ -39,8 +39,11 @@ String get _computeSdkPath {
39
39
/// A utility class for finding and referencing paths within the Dart SDK.
40
40
class Sdk {
41
41
final String sdkPath;
42
+ final String version;
42
43
43
- Sdk () : sdkPath = _computeSdkPath;
44
+ Sdk ()
45
+ : sdkPath = _computeSdkPath,
46
+ version = Runtime .runtime.version;
44
47
45
48
// Assume that we want to use the same Dart executable that we used to spawn
46
49
// DartDev. We should be able to run programs with out/ReleaseX64/dart even
@@ -97,25 +100,20 @@ class Runtime {
97
100
static Runtime runtime = Runtime ._();
98
101
99
102
// Match "2.10.0-edge.0b2da6e7 (be) ...".
100
- static RegExp channelRegex = RegExp (r'.* \(([\d\w]+)\) .*' );
103
+ static final RegExp _channelRegex = RegExp (r'.* \(([\d\w]+)\) .*' );
101
104
102
- String _channel;
103
-
104
- Runtime ._() {
105
- _parseVersion ();
106
- }
105
+ /// The SDK's version number (x.y.z-a.b.channel).
106
+ final String version;
107
107
108
108
/// The SDK's release channel (`be` , `dev` , `beta` , `stable` ).
109
- String get channel => _channel ;
109
+ final String channel;
110
110
111
- /// Return whether the SDK is from the stable release channel.
112
- bool get stableChannel => channel == 'stable' ;
111
+ Runtime ._()
112
+ : version = _computeVersion (Platform .version),
113
+ channel = _computeChannel (Platform .version);
113
114
114
- void _parseVersion () {
115
- final version = Platform .version;
116
- final match = channelRegex.firstMatch (version);
117
- if (match != null ) {
118
- _channel = match.group (1 );
119
- }
120
- }
115
+ static String _computeVersion (String version) =>
116
+ version.substring (0 , version.indexOf (' ' ));
117
+ static String _computeChannel (String version) =>
118
+ _channelRegex.firstMatch (version)? .group (1 );
121
119
}
0 commit comments