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
8 changed files with 23 additions and 21 deletions

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.