Rollup merge of #111770 - liushuyu:ubuntu/beta-rev-no-git, r=ozkanonur
Read beta version from the version file if building from a source tarball This pull request changes the `bootstrap` behaviour so that when building `rustc` from a source tarball, the beta revision number is correctly read from the `version` file instead of erroring out by invoking `git`. The `version` file is observed to only exist in the official source tarball and has the following format: ``` 1.70.0-beta.4 (2013813b6 2023-05-07) ```
This commit is contained in:
commit
6ccc3de998
2 changed files with 43 additions and 6 deletions
|
@ -146,6 +146,22 @@ fn alias_and_path_for_library() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_beta_rev_parsing() {
|
||||||
|
use crate::extract_beta_rev;
|
||||||
|
|
||||||
|
// single digit revision
|
||||||
|
assert_eq!(extract_beta_rev("1.99.9-beta.7 (xxxxxx)"), Some("7".to_string()));
|
||||||
|
// multiple digits
|
||||||
|
assert_eq!(extract_beta_rev("1.99.9-beta.777 (xxxxxx)"), Some("777".to_string()));
|
||||||
|
// nightly channel (no beta revision)
|
||||||
|
assert_eq!(extract_beta_rev("1.99.9-nightly (xxxxxx)"), None);
|
||||||
|
// stable channel (no beta revision)
|
||||||
|
assert_eq!(extract_beta_rev("1.99.9 (xxxxxxx)"), None);
|
||||||
|
// invalid string
|
||||||
|
assert_eq!(extract_beta_rev("invalid"), None);
|
||||||
|
}
|
||||||
|
|
||||||
mod defaults {
|
mod defaults {
|
||||||
use super::{configure, first, run_build};
|
use super::{configure, first, run_build};
|
||||||
use crate::builder::*;
|
use crate::builder::*;
|
||||||
|
|
|
@ -1324,7 +1324,7 @@ impl Build {
|
||||||
match &self.config.channel[..] {
|
match &self.config.channel[..] {
|
||||||
"stable" => num.to_string(),
|
"stable" => num.to_string(),
|
||||||
"beta" => {
|
"beta" => {
|
||||||
if self.rust_info().is_managed_git_subrepository() && !self.config.omit_git_hash {
|
if !self.config.omit_git_hash {
|
||||||
format!("{}-beta.{}", num, self.beta_prerelease_version())
|
format!("{}-beta.{}", num, self.beta_prerelease_version())
|
||||||
} else {
|
} else {
|
||||||
format!("{}-beta", num)
|
format!("{}-beta", num)
|
||||||
|
@ -1336,18 +1336,28 @@ impl Build {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn beta_prerelease_version(&self) -> u32 {
|
fn beta_prerelease_version(&self) -> u32 {
|
||||||
|
fn extract_beta_rev_from_file<P: AsRef<Path>>(version_file: P) -> Option<String> {
|
||||||
|
let version = fs::read_to_string(version_file).ok()?;
|
||||||
|
|
||||||
|
extract_beta_rev(&version)
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(s) = self.prerelease_version.get() {
|
if let Some(s) = self.prerelease_version.get() {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Figure out how many merge commits happened since we branched off master.
|
// First check if there is a version file available.
|
||||||
// That's our beta number!
|
// If available, we read the beta revision from that file.
|
||||||
// (Note that we use a `..` range, not the `...` symmetric difference.)
|
// This only happens when building from a source tarball when Git should not be used.
|
||||||
let count =
|
let count = extract_beta_rev_from_file(self.src.join("version")).unwrap_or_else(|| {
|
||||||
|
// Figure out how many merge commits happened since we branched off master.
|
||||||
|
// That's our beta number!
|
||||||
|
// (Note that we use a `..` range, not the `...` symmetric difference.)
|
||||||
output(self.config.git().arg("rev-list").arg("--count").arg("--merges").arg(format!(
|
output(self.config.git().arg("rev-list").arg("--count").arg("--merges").arg(format!(
|
||||||
"refs/remotes/origin/{}..HEAD",
|
"refs/remotes/origin/{}..HEAD",
|
||||||
self.config.stage0_metadata.config.nightly_branch
|
self.config.stage0_metadata.config.nightly_branch
|
||||||
)));
|
)))
|
||||||
|
});
|
||||||
let n = count.trim().parse().unwrap();
|
let n = count.trim().parse().unwrap();
|
||||||
self.prerelease_version.set(Some(n));
|
self.prerelease_version.set(Some(n));
|
||||||
n
|
n
|
||||||
|
@ -1707,6 +1717,17 @@ to download LLVM rather than building it.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Extract the beta revision from the full version string.
|
||||||
|
///
|
||||||
|
/// The full version string looks like "a.b.c-beta.y". And we need to extract
|
||||||
|
/// the "y" part from the string.
|
||||||
|
pub fn extract_beta_rev(version: &str) -> Option<String> {
|
||||||
|
let parts = version.splitn(2, "-beta.").collect::<Vec<_>>();
|
||||||
|
let count = parts.get(1).and_then(|s| s.find(' ').map(|p| (&s[..p]).to_string()));
|
||||||
|
|
||||||
|
count
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn chmod(path: &Path, perms: u32) {
|
fn chmod(path: &Path, perms: u32) {
|
||||||
use std::os::unix::fs::*;
|
use std::os::unix::fs::*;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue