Chromium Code Reviews| 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 var aboveExecutable = p.dirname(p.dirname(Platform.executable)); |
|
Bob Nystrom
2015/05/20 22:00:57
Document this.
nweiz
2015/05/21 00:43:10
Done.
| |
| 26 path.dirname(path.dirname(Platform.executable)); | 27 assert(fileExists(p.join(aboveExecutable, 'version'))); |
| 28 return aboveExecutable; | |
| 29 })(); | |
| 27 | 30 |
| 28 /// The SDK's revision number formatted to be a semantic version. | 31 /// The SDK's revision number formatted to be a semantic version. |
| 29 /// | 32 /// |
| 30 /// This can be set so that the version solver tests can artificially select | 33 /// This can be set so that the version solver tests can artificially select |
| 31 /// different SDK versions. | 34 /// different SDK versions. |
| 32 Version version = _getVersion(); | 35 Version version = _getVersion(); |
| 33 | 36 |
| 34 /// Determine the SDK's version number. | 37 /// Determine the SDK's version number. |
| 35 Version _getVersion() { | 38 Version _getVersion() { |
| 36 // Some of the pub integration tests require an SDK version number, but the | 39 // 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 | 40 // tests on the bots are not run from a built SDK so this lets us avoid |
| 38 // parsing the missing version file. | 41 // parsing the missing version file. |
| 39 var sdkVersion = Platform.environment["_PUB_TEST_SDK_VERSION"]; | 42 var sdkVersion = Platform.environment["_PUB_TEST_SDK_VERSION"]; |
| 40 if (sdkVersion != null) return new Version.parse(sdkVersion); | 43 if (sdkVersion != null) return new Version.parse(sdkVersion); |
| 41 | 44 |
| 42 if (runningFromSdk) { | 45 if (!runningFromDartRepo) { |
| 43 // Read the "version" file. | 46 // Read the "version" file. |
| 44 var version = readTextFile(path.join(_rootDirectory, "version")).trim(); | 47 var version = readTextFile(p.join(rootDirectory, "version")).trim(); |
| 45 return new Version.parse(version); | 48 return new Version.parse(version); |
| 46 } | 49 } |
| 47 | 50 |
| 48 // When running from the repo, read the canonical VERSION file in tools/. | 51 // 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. | 52 // This makes it possible to run pub without having built the SDK first. |
| 50 var contents = readTextFile(path.join(repoRoot, "tools/VERSION")); | 53 var contents = readTextFile(p.join(dartRepoRoot, "tools/VERSION")); |
| 51 | 54 |
| 52 parseField(name) { | 55 parseField(name) { |
| 53 var pattern = new RegExp("^$name ([a-z0-9]+)", multiLine: true); | 56 var pattern = new RegExp("^$name ([a-z0-9]+)", multiLine: true); |
| 54 var match = pattern.firstMatch(contents); | 57 var match = pattern.firstMatch(contents); |
| 55 return match[1]; | 58 return match[1]; |
| 56 } | 59 } |
| 57 | 60 |
| 58 var channel = parseField("CHANNEL"); | 61 var channel = parseField("CHANNEL"); |
| 59 var major = parseField("MAJOR"); | 62 var major = parseField("MAJOR"); |
| 60 var minor = parseField("MINOR"); | 63 var minor = parseField("MINOR"); |
| 61 var patch = parseField("PATCH"); | 64 var patch = parseField("PATCH"); |
| 62 var prerelease = parseField("PRERELEASE"); | 65 var prerelease = parseField("PRERELEASE"); |
| 63 var prereleasePatch = parseField("PRERELEASE_PATCH"); | 66 var prereleasePatch = parseField("PRERELEASE_PATCH"); |
| 64 | 67 |
| 65 var version = "$major.$minor.$patch"; | 68 var version = "$major.$minor.$patch"; |
| 66 if (channel == "be") { | 69 if (channel == "be") { |
| 67 // TODO(rnystrom): tools/utils.py includes the svn commit here. Should we? | 70 // TODO(rnystrom): tools/utils.py includes the svn commit here. Should we? |
| 68 version += "-edge"; | 71 version += "-edge"; |
| 69 } else if (channel == "dev") { | 72 } else if (channel == "dev") { |
| 70 version += "-dev.$prerelease.$prereleasePatch"; | 73 version += "-dev.$prerelease.$prereleasePatch"; |
| 71 } | 74 } |
| 72 | 75 |
| 73 return new Version.parse(version); | 76 return new Version.parse(version); |
| 74 } | 77 } |
| OLD | NEW |