Skip to content

Commit 06913a5

Browse files
committed
Automaticaly calculate beta prerelease numbers
This is a forward-port of: * 9426dda * cbfb985 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.
1 parent 3bd4af8 commit 06913a5

File tree

4 files changed

+57
-8
lines changed

4 files changed

+57
-8
lines changed

src/bootstrap/channel.rs

-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ use config::Config;
2626
// The version number
2727
pub const CFG_RELEASE_NUM: &str = "1.25.0";
2828

29-
// An optional number to put after the label, e.g. '.2' -> '-beta.2'
30-
// Be sure to make this starts with a dot to conform to semver pre-release
31-
// versions (section 9)
32-
pub const CFG_PRERELEASE_VERSION: &str = ".1";
33-
3429
pub struct GitInfo {
3530
inner: Option<Info>,
3631
}

src/bootstrap/dist.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,6 @@ fn add_env(build: &Build, cmd: &mut Command, target: Interned<String>) {
16521652
cmd.env("CFG_RELEASE_INFO", build.rust_version())
16531653
.env("CFG_RELEASE_NUM", channel::CFG_RELEASE_NUM)
16541654
.env("CFG_RELEASE", build.rust_release())
1655-
.env("CFG_PRERELEASE_VERSION", channel::CFG_PRERELEASE_VERSION)
16561655
.env("CFG_VER_MAJOR", parts.next().unwrap())
16571656
.env("CFG_VER_MINOR", parts.next().unwrap())
16581657
.env("CFG_VER_PATCH", parts.next().unwrap())

src/bootstrap/lib.rs

+51-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ extern crate toml;
134134
#[cfg(unix)]
135135
extern crate libc;
136136

137-
use std::cell::RefCell;
137+
use std::cell::{RefCell, Cell};
138138
use std::collections::{HashSet, HashMap};
139139
use std::env;
140140
use std::fs::{self, File};
@@ -250,6 +250,7 @@ pub struct Build {
250250
is_sudo: bool,
251251
ci_env: CiEnv,
252252
delayed_failures: RefCell<Vec<String>>,
253+
prerelease_version: Cell<Option<u32>>,
253254
}
254255

255256
#[derive(Debug)]
@@ -335,6 +336,7 @@ impl Build {
335336
is_sudo,
336337
ci_env: CiEnv::current(),
337338
delayed_failures: RefCell::new(Vec::new()),
339+
prerelease_version: Cell::new(None),
338340
}
339341
}
340342

@@ -774,12 +776,59 @@ impl Build {
774776
fn release(&self, num: &str) -> String {
775777
match &self.config.channel[..] {
776778
"stable" => num.to_string(),
777-
"beta" => format!("{}-beta{}", num, channel::CFG_PRERELEASE_VERSION),
779+
"beta" => format!("{}-beta.{}", num, self.beta_prerelease_version()),
778780
"nightly" => format!("{}-nightly", num),
779781
_ => format!("{}-dev", num),
780782
}
781783
}
782784

785+
fn beta_prerelease_version(&self) -> u32 {
786+
if let Some(s) = self.prerelease_version.get() {
787+
return s
788+
}
789+
790+
let beta = output(
791+
Command::new("git")
792+
.arg("ls-remote")
793+
.arg("origin")
794+
.arg("beta")
795+
.current_dir(&self.src)
796+
);
797+
let beta = beta.trim().split_whitespace().next().unwrap();
798+
let master = output(
799+
Command::new("git")
800+
.arg("ls-remote")
801+
.arg("origin")
802+
.arg("master")
803+
.current_dir(&self.src)
804+
);
805+
let master = master.trim().split_whitespace().next().unwrap();
806+
807+
// Figure out where the current beta branch started.
808+
let base = output(
809+
Command::new("git")
810+
.arg("merge-base")
811+
.arg(beta)
812+
.arg(master)
813+
.current_dir(&self.src),
814+
);
815+
let base = base.trim();
816+
817+
// Next figure out how many merge commits happened since we branched off
818+
// beta. That's our beta number!
819+
let count = output(
820+
Command::new("git")
821+
.arg("rev-list")
822+
.arg("--count")
823+
.arg("--merges")
824+
.arg(format!("{}...HEAD", base))
825+
.current_dir(&self.src),
826+
);
827+
let n = count.trim().parse().unwrap();
828+
self.prerelease_version.set(Some(n));
829+
n
830+
}
831+
783832
/// Returns the value of `release` above for Rust itself.
784833
fn rust_release(&self) -> String {
785834
self.release(channel::CFG_RELEASE_NUM)

src/ci/init_repo.sh

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ fi
3636
rm -rf "$CACHE_DIR"
3737
mkdir "$CACHE_DIR"
3838

39+
# On the beta channel we'll be automatically calculating the prerelease version
40+
# via the git history, so unshallow our shallow clone from CI.
41+
if grep -q RUST_RELEASE_CHANNEL=beta src/ci/run.sh; then
42+
git fetch origin --unshallow beta master
43+
fi
44+
3945
travis_fold start update_cache
4046
travis_time_start
4147

0 commit comments

Comments
 (0)