| 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 pub.sdk; | |
| 7 | |
| 8 import 'dart:io'; | |
| 9 | |
| 10 import 'package:path/path.dart' as path; | |
| 11 import 'package:pub_semver/pub_semver.dart'; | |
| 12 | |
| 13 import 'io.dart'; | |
| 14 | |
| 15 /// Gets the path to the root directory of the SDK. | |
| 16 /// | |
| 17 /// When running from the actual built SDK, this will be the SDK that contains | |
| 18 /// the running Dart executable. When running from the repo, it will be the | |
| 19 /// "sdk" directory in the Dart repository itself. | |
| 20 final String rootDirectory = | |
| 21 runningFromSdk ? _rootDirectory : path.join(repoRoot, "sdk"); | |
| 22 | |
| 23 /// Gets the path to the root directory of the SDK, assuming that the currently | |
| 24 /// running Dart executable is within it. | |
| 25 final String _rootDirectory = | |
| 26 path.dirname(path.dirname(Platform.executable)); | |
| 27 | |
| 28 /// The SDK's revision number formatted to be a semantic version. | |
| 29 /// | |
| 30 /// This can be set so that the version solver tests can artificially select | |
| 31 /// different SDK versions. | |
| 32 Version version = _getVersion(); | |
| 33 | |
| 34 /// Determine the SDK's version number. | |
| 35 Version _getVersion() { | |
| 36 // Some of the pub integration tests require an SDK version number, but the | |
| 37 // tests on the bots are not run from a built SDK so this lets us avoid | |
| 38 // parsing the missing version file. | |
| 39 var sdkVersion = Platform.environment["_PUB_TEST_SDK_VERSION"]; | |
| 40 if (sdkVersion != null) return new Version.parse(sdkVersion); | |
| 41 | |
| 42 if (runningFromSdk) { | |
| 43 // Read the "version" file. | |
| 44 var version = readTextFile(path.join(_rootDirectory, "version")).trim(); | |
| 45 return new Version.parse(version); | |
| 46 } | |
| 47 | |
| 48 // When running from the repo, read the canonical VERSION file in tools/. | |
| 49 // This makes it possible to run pub without having built the SDK first. | |
| 50 var contents = readTextFile(path.join(repoRoot, "tools/VERSION")); | |
| 51 | |
| 52 parseField(name) { | |
| 53 var pattern = new RegExp("^$name ([a-z0-9]+)", multiLine: true); | |
| 54 var match = pattern.firstMatch(contents); | |
| 55 return match[1]; | |
| 56 } | |
| 57 | |
| 58 var channel = parseField("CHANNEL"); | |
| 59 var major = parseField("MAJOR"); | |
| 60 var minor = parseField("MINOR"); | |
| 61 var patch = parseField("PATCH"); | |
| 62 var prerelease = parseField("PRERELEASE"); | |
| 63 var prereleasePatch = parseField("PRERELEASE_PATCH"); | |
| 64 | |
| 65 var version = "$major.$minor.$patch"; | |
| 66 if (channel == "be") { | |
| 67 // TODO(rnystrom): tools/utils.py includes the svn commit here. Should we? | |
| 68 version += "-edge"; | |
| 69 } else if (channel == "dev") { | |
| 70 version += "-dev.$prerelease.$prereleasePatch"; | |
| 71 } | |
| 72 | |
| 73 return new Version.parse(version); | |
| 74 } | |
| OLD | NEW |