Skip to content

Commit 50e38e9

Browse files
committed
Read beta version from the version file ...
... if building from a source tarball
1 parent 77f4f82 commit 50e38e9

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

Diff for: src/bootstrap/lib.rs

+27-6
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,7 @@ impl Build {
13241324
match &self.config.channel[..] {
13251325
"stable" => num.to_string(),
13261326
"beta" => {
1327-
if self.rust_info().is_managed_git_subrepository() && !self.config.omit_git_hash {
1327+
if !self.config.omit_git_hash {
13281328
format!("{}-beta.{}", num, self.beta_prerelease_version())
13291329
} else {
13301330
format!("{}-beta", num)
@@ -1336,18 +1336,28 @@ impl Build {
13361336
}
13371337

13381338
fn beta_prerelease_version(&self) -> u32 {
1339+
fn extract_beta_rev_from_file<P: AsRef<Path>>(version_file: P) -> Option<String> {
1340+
let version = fs::read_to_string(version_file).ok()?;
1341+
1342+
extract_beta_rev(&version)
1343+
}
1344+
13391345
if let Some(s) = self.prerelease_version.get() {
13401346
return s;
13411347
}
13421348

1343-
// Figure out how many merge commits happened since we branched off master.
1344-
// That's our beta number!
1345-
// (Note that we use a `..` range, not the `...` symmetric difference.)
1346-
let count =
1349+
// First check if there is a version file available.
1350+
// If available, we read the beta revision from that file.
1351+
// This only happens when building from a source tarball when Git should not be used.
1352+
let count = extract_beta_rev_from_file(self.src.join("version")).unwrap_or_else(|| {
1353+
// Figure out how many merge commits happened since we branched off master.
1354+
// That's our beta number!
1355+
// (Note that we use a `..` range, not the `...` symmetric difference.)
13471356
output(self.config.git().arg("rev-list").arg("--count").arg("--merges").arg(format!(
13481357
"refs/remotes/origin/{}..HEAD",
13491358
self.config.stage0_metadata.config.nightly_branch
1350-
)));
1359+
)))
1360+
});
13511361
let n = count.trim().parse().unwrap();
13521362
self.prerelease_version.set(Some(n));
13531363
n
@@ -1707,6 +1717,17 @@ to download LLVM rather than building it.
17071717
}
17081718
}
17091719

1720+
/// Extract the beta revision from the full version string.
1721+
///
1722+
/// The full version string looks like "a.b.c-beta.y". And we need to extract
1723+
/// the "y" part from the string.
1724+
pub fn extract_beta_rev(version: &str) -> Option<String> {
1725+
let parts = version.splitn(2, "-beta.").collect::<Vec<_>>();
1726+
let count = parts.get(1).and_then(|s| s.find(' ').map(|p| (&s[..p]).to_string()));
1727+
1728+
count
1729+
}
1730+
17101731
#[cfg(unix)]
17111732
fn chmod(path: &Path, perms: u32) {
17121733
use std::os::unix::fs::*;

0 commit comments

Comments
 (0)