| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /// Operations relative to the user's installed Dart SDK. | |
| 6 library sdk; | |
| 7 | |
| 8 import 'dart:io'; | |
| 9 | |
| 10 import 'package:pathos/path.dart' as path; | |
| 11 | |
| 12 import 'io.dart'; | |
| 13 import 'log.dart' as log; | |
| 14 import 'version.dart'; | |
| 15 | |
| 16 /// Matches an Eclipse-style SDK version number. This is four dotted numbers | |
| 17 /// (major, minor, patch, build) with an optional suffix attached to the build | |
| 18 /// number. | |
| 19 final _versionPattern = new RegExp(r'^(\d+)\.(\d+)\.(\d+)\.(\d+.*)$'); | |
| 20 | |
| 21 /// Gets the path to the root directory of the SDK. | |
| 22 String get rootDirectory { | |
| 23 // If the environment variable was provided, use it. This is mainly used for | |
| 24 // the pub tests. | |
| 25 var dir = Platform.environment["DART_SDK"]; | |
| 26 if (dir != null) { | |
| 27 log.fine("Using DART_SDK to find SDK at $dir"); | |
| 28 return dir; | |
| 29 } | |
| 30 | |
| 31 var pubDir = path.dirname(new Options().script); | |
| 32 dir = path.normalize(path.join(pubDir, "../../")); | |
| 33 log.fine("Located SDK at $dir"); | |
| 34 return dir; | |
| 35 } | |
| 36 | |
| 37 /// Gets the SDK's revision number formatted to be a semantic version. | |
| 38 Version version = _getVersion(); | |
| 39 | |
| 40 /// Is `true` if the current SDK is an unreleased bleeding edge version. | |
| 41 bool get isBleedingEdge { | |
| 42 // The live build is locked to the magical old number "0.1.2+<stuff>". | |
| 43 return version.major == 0 && version.minor == 1 && version.patch == 2; | |
| 44 } | |
| 45 | |
| 46 /// Determine the SDK's version number. | |
| 47 Version _getVersion() { | |
| 48 var revisionPath = path.join(rootDirectory, "version"); | |
| 49 var version = readTextFile(revisionPath).trim(); | |
| 50 | |
| 51 // Given a version file like: 0.1.2.0_r17495 | |
| 52 // We create a semver like: 0.1.2+0.r17495 | |
| 53 var match = _versionPattern.firstMatch(version); | |
| 54 if (match == null) { | |
| 55 throw new FormatException("The Dart SDK's 'version' file was not in a " | |
| 56 "format pub could recognize. Found: $version"); | |
| 57 } | |
| 58 | |
| 59 // Semantic versions cannot use "_". | |
| 60 var build = match[4].replaceAll('_', '.'); | |
| 61 | |
| 62 return new Version( | |
| 63 int.parse(match[1]), int.parse(match[2]), int.parse(match[3]), | |
| 64 build: build); | |
| 65 } | |
| OLD | NEW |