bootstrap: move the version number to a plaintext file

The Rust version number is currently embedded in bootstrap's source
code, which makes it hard to update it automatically or access it
outside of ./x.py (as you'd have to parse the source code).

This commit moves the version number to a standalone plaintext file,
which makes accessing or updating it trivial.
This commit is contained in:
Pietro Albini 2020-09-18 14:58:22 +02:00
parent 95386b656e
commit b9af3e30a9
No known key found for this signature in database
GPG Key ID: 3E06ABE80BAAF19C
8 changed files with 23 additions and 21 deletions

View File

@ -12,9 +12,6 @@ use build_helper::output;
use crate::Build;
// The version number
pub const CFG_RELEASE_NUM: &str = "1.48.0";
pub struct GitInfo {
inner: Option<Info>,
}

View File

@ -18,7 +18,6 @@ use build_helper::{output, t};
use crate::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::cache::{Interned, INTERNER};
use crate::channel;
use crate::compile;
use crate::config::TargetSelection;
use crate::tool::{self, Tool};
@ -569,7 +568,7 @@ impl Step for Rustc {
&page_dst,
&[
("<INSERT DATE HERE>", &month_year),
("<INSERT VERSION HERE>", channel::CFG_RELEASE_NUM),
("<INSERT VERSION HERE>", &builder.version),
],
);
}
@ -2289,9 +2288,9 @@ impl Step for Extended {
}
fn add_env(builder: &Builder<'_>, cmd: &mut Command, target: TargetSelection) {
let mut parts = channel::CFG_RELEASE_NUM.split('.');
let mut parts = builder.version.split('.');
cmd.env("CFG_RELEASE_INFO", builder.rust_version())
.env("CFG_RELEASE_NUM", channel::CFG_RELEASE_NUM)
.env("CFG_RELEASE_NUM", &builder.version)
.env("CFG_RELEASE", builder.rust_release())
.env("CFG_VER_MAJOR", parts.next().unwrap())
.env("CFG_VER_MINOR", parts.next().unwrap())

View File

@ -433,7 +433,7 @@ impl Step for Std {
.arg("-Z")
.arg("unstable-options")
.arg("--resource-suffix")
.arg(crate::channel::CFG_RELEASE_NUM)
.arg(&builder.version)
.arg("--index-page")
.arg(&builder.src.join("src/doc/index.md"));
@ -659,7 +659,7 @@ impl Step for ErrorIndex {
let mut index = tool::ErrorIndex::command(builder, self.compiler);
index.arg("html");
index.arg(out.join("error-index.html"));
index.arg(crate::channel::CFG_RELEASE_NUM);
index.arg(&builder.version);
builder.run(&mut index);
}

View File

@ -218,6 +218,9 @@ pub struct Build {
/// User-specified configuration from `config.toml`.
config: Config,
// Version information
version: String,
// Properties derived from the above configuration
src: PathBuf,
out: PathBuf,
@ -380,6 +383,10 @@ impl Build {
.unwrap()
.to_path_buf();
let version = std::fs::read_to_string(src.join("src").join("version"))
.expect("failed to read src/version");
let version = version.trim();
let mut build = Build {
initial_rustc: config.initial_rustc.clone(),
initial_cargo: config.initial_cargo.clone(),
@ -395,6 +402,7 @@ impl Build {
targets: config.targets.clone(),
config,
version: version.to_string(),
src,
out,
@ -433,8 +441,7 @@ impl Build {
.next()
.unwrap()
.trim();
let my_version = channel::CFG_RELEASE_NUM;
if local_release.split('.').take(2).eq(my_version.split('.').take(2)) {
if local_release.split('.').take(2).eq(version.split('.').take(2)) {
build.verbose(&format!("auto-detected local-rebuild {}", local_release));
build.local_rebuild = true;
}
@ -785,7 +792,7 @@ impl Build {
match which {
GitRepo::Rustc => {
let sha = self.rust_sha().unwrap_or(channel::CFG_RELEASE_NUM);
let sha = self.rust_sha().unwrap_or(&self.version);
Some(format!("/rustc/{}", sha))
}
GitRepo::Llvm => Some(String::from("/rustc/llvm")),
@ -1016,7 +1023,7 @@ impl Build {
/// Returns the value of `release` above for Rust itself.
fn rust_release(&self) -> String {
self.release(channel::CFG_RELEASE_NUM)
self.release(&self.version)
}
/// Returns the "package version" for a component given the `num` release
@ -1036,7 +1043,7 @@ impl Build {
/// Returns the value of `package_vers` above for Rust itself.
fn rust_package_vers(&self) -> String {
self.package_vers(channel::CFG_RELEASE_NUM)
self.package_vers(&self.version)
}
/// Returns the value of `package_vers` above for Cargo
@ -1070,7 +1077,7 @@ impl Build {
}
fn llvm_tools_package_vers(&self) -> String {
self.package_vers(channel::CFG_RELEASE_NUM)
self.package_vers(&self.version)
}
fn llvm_tools_vers(&self) -> String {
@ -1087,7 +1094,7 @@ impl Build {
/// Note that this is a descriptive string which includes the commit date,
/// sha, version, etc.
fn rust_version(&self) -> String {
self.rust_info.version(self, channel::CFG_RELEASE_NUM)
self.rust_info.version(self, &self.version)
}
/// Returns the full commit hash.

View File

@ -19,7 +19,6 @@ use std::process::Command;
use build_helper::{output, t};
use crate::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::channel;
use crate::config::TargetSelection;
use crate::util::{self, exe};
use crate::GitRepo;
@ -296,7 +295,7 @@ impl Step for Llvm {
// release number on the dev channel.
cfg.define("LLVM_VERSION_SUFFIX", "-rust-dev");
} else {
let suffix = format!("-rust-{}-{}", channel::CFG_RELEASE_NUM, builder.config.channel);
let suffix = format!("-rust-{}-{}", builder.version, builder.config.channel);
cfg.define("LLVM_VERSION_SUFFIX", suffix);
}

View File

@ -636,7 +636,7 @@ impl Step for RustdocJSStd {
.arg("--crate-name")
.arg("std")
.arg("--resource-suffix")
.arg(crate::channel::CFG_RELEASE_NUM)
.arg(&builder.version)
.arg("--doc-folder")
.arg(builder.doc_out(self.target))
.arg("--test-folder")

View File

@ -7,7 +7,6 @@ use std::process::{exit, Command};
use build_helper::t;
use crate::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step};
use crate::channel;
use crate::channel::GitInfo;
use crate::compile;
use crate::config::TargetSelection;
@ -255,7 +254,7 @@ pub fn prepare_tool_cargo(
cargo.env("CFG_RELEASE", builder.rust_release());
cargo.env("CFG_RELEASE_CHANNEL", &builder.config.channel);
cargo.env("CFG_VERSION", builder.rust_version());
cargo.env("CFG_RELEASE_NUM", channel::CFG_RELEASE_NUM);
cargo.env("CFG_RELEASE_NUM", &builder.version);
let info = GitInfo::new(builder.config.ignore_git, &dir);
if let Some(sha) = info.sha() {

1
src/version Normal file
View File

@ -0,0 +1 @@
1.48.0