diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2018-01-21 23:11:40 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-01-21 23:11:40 +0100 |
| commit | 35221d8d68911d0b14262f7f46e9783e335ba298 (patch) | |
| tree | 2d27c6bbab0a546f9065c24a8e020355c7a6878b /src/bootstrap | |
| parent | a1c3449a9c386d7a9f950e03b9d7cd03c21bce17 (diff) | |
| parent | 06913a5b1d19284ae2c2ff6cfac130842334e886 (diff) | |
Rollup merge of #47582 - alexcrichton:auto-beta, r=kennytm
Automaticaly calculate beta prerelease numbers This is a forward-port of: * 9426dda83d7a928d6ced377345e14b84b0f11c21 * cbfb9858951da7aee22d82178405306fca9decb1 from the beta branch which is used to automatically calculate the beta number based on the number of merges to the beta branch so far.
Diffstat (limited to 'src/bootstrap')
| -rw-r--r-- | src/bootstrap/channel.rs | 5 | ||||
| -rw-r--r-- | src/bootstrap/dist.rs | 1 | ||||
| -rw-r--r-- | src/bootstrap/lib.rs | 53 |
3 files changed, 51 insertions, 8 deletions
diff --git a/src/bootstrap/channel.rs b/src/bootstrap/channel.rs index 4e3f3a00b15..e412dd9e3e6 100644 --- a/src/bootstrap/channel.rs +++ b/src/bootstrap/channel.rs @@ -26,11 +26,6 @@ use config::Config; // The version number pub const CFG_RELEASE_NUM: &str = "1.25.0"; -// An optional number to put after the label, e.g. '.2' -> '-beta.2' -// Be sure to make this starts with a dot to conform to semver pre-release -// versions (section 9) -pub const CFG_PRERELEASE_VERSION: &str = ".1"; - pub struct GitInfo { inner: Option<Info>, } diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 7f0613aabe6..224b31ef268 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -1652,7 +1652,6 @@ fn add_env(build: &Build, cmd: &mut Command, target: Interned<String>) { cmd.env("CFG_RELEASE_INFO", build.rust_version()) .env("CFG_RELEASE_NUM", channel::CFG_RELEASE_NUM) .env("CFG_RELEASE", build.rust_release()) - .env("CFG_PRERELEASE_VERSION", channel::CFG_PRERELEASE_VERSION) .env("CFG_VER_MAJOR", parts.next().unwrap()) .env("CFG_VER_MINOR", parts.next().unwrap()) .env("CFG_VER_PATCH", parts.next().unwrap()) diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 948bf29bbac..3738828a4ba 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -134,7 +134,7 @@ extern crate toml; #[cfg(unix)] extern crate libc; -use std::cell::RefCell; +use std::cell::{RefCell, Cell}; use std::collections::{HashSet, HashMap}; use std::env; use std::fs::{self, File}; @@ -250,6 +250,7 @@ pub struct Build { is_sudo: bool, ci_env: CiEnv, delayed_failures: RefCell<Vec<String>>, + prerelease_version: Cell<Option<u32>>, } #[derive(Debug)] @@ -335,6 +336,7 @@ impl Build { is_sudo, ci_env: CiEnv::current(), delayed_failures: RefCell::new(Vec::new()), + prerelease_version: Cell::new(None), } } @@ -774,12 +776,59 @@ impl Build { fn release(&self, num: &str) -> String { match &self.config.channel[..] { "stable" => num.to_string(), - "beta" => format!("{}-beta{}", num, channel::CFG_PRERELEASE_VERSION), + "beta" => format!("{}-beta.{}", num, self.beta_prerelease_version()), "nightly" => format!("{}-nightly", num), _ => format!("{}-dev", num), } } + fn beta_prerelease_version(&self) -> u32 { + if let Some(s) = self.prerelease_version.get() { + return s + } + + let beta = output( + Command::new("git") + .arg("ls-remote") + .arg("origin") + .arg("beta") + .current_dir(&self.src) + ); + let beta = beta.trim().split_whitespace().next().unwrap(); + let master = output( + Command::new("git") + .arg("ls-remote") + .arg("origin") + .arg("master") + .current_dir(&self.src) + ); + let master = master.trim().split_whitespace().next().unwrap(); + + // Figure out where the current beta branch started. + let base = output( + Command::new("git") + .arg("merge-base") + .arg(beta) + .arg(master) + .current_dir(&self.src), + ); + let base = base.trim(); + + // Next figure out how many merge commits happened since we branched off + // beta. That's our beta number! + let count = output( + Command::new("git") + .arg("rev-list") + .arg("--count") + .arg("--merges") + .arg(format!("{}...HEAD", base)) + .current_dir(&self.src), + ); + let n = count.trim().parse().unwrap(); + self.prerelease_version.set(Some(n)); + n + } + /// Returns the value of `release` above for Rust itself. fn rust_release(&self) -> String { self.release(channel::CFG_RELEASE_NUM) |
