Skip to content

Commit 597549e

Browse files
committed
Auto merge of #47396 - alexcrichton:beta-next, r=kennytm
[beta] Automaticaly calculate beta prerelease numbers This commit automatically calculates the beta prerelease number meaning we'll no longer need to manually change the beta version. Instead beta will automatically deploy any time a backport is merged, ensuring that backports are released for testing ASAP. More details about this can be found on the internal [forums] The only bit of trickiness here was that on CI we do shallow clones by default but the git history probing here requires some more information. Do cope with that this commit chooses the strategy of converting the repository to a full clone via the `--unshallow` flag to `git`. That way this should work for local developers as well as CI changes. Note that this commit is coming first to the beta branch to test it, and if successful we can go back and land it on master. [forums]: https://internals.rust-lang.org/t/tweaking-how-betas-are-produced/6526
2 parents bb9be9e + 9426dda commit 597549e

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-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.24.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 = ".3";
33-
3429
pub struct GitInfo {
3530
inner: Option<Info>,
3631
}

src/bootstrap/dist.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,6 @@ fn add_env(build: &Build, cmd: &mut Command, target: Interned<String>) {
16501650
cmd.env("CFG_RELEASE_INFO", build.rust_version())
16511651
.env("CFG_RELEASE_NUM", channel::CFG_RELEASE_NUM)
16521652
.env("CFG_RELEASE", build.rust_release())
1653-
.env("CFG_PRERELEASE_VERSION", channel::CFG_PRERELEASE_VERSION)
16541653
.env("CFG_VER_MAJOR", parts.next().unwrap())
16551654
.env("CFG_VER_MINOR", parts.next().unwrap())
16561655
.env("CFG_VER_PATCH", parts.next().unwrap())

src/bootstrap/lib.rs

+47-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

@@ -769,12 +771,55 @@ impl Build {
769771
fn release(&self, num: &str) -> String {
770772
match &self.config.channel[..] {
771773
"stable" => num.to_string(),
772-
"beta" => format!("{}-beta{}", num, channel::CFG_PRERELEASE_VERSION),
774+
"beta" => format!("{}-beta.{}", num, self.beta_prerelease_version()),
773775
"nightly" => format!("{}-nightly", num),
774776
_ => format!("{}-dev", num),
775777
}
776778
}
777779

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