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