Skip to content

Commit

Permalink
Rollup merge of #76878 - pietroalbini:version, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
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 PR moves the version number to a standalone plaintext file, which makes accessing or updating it trivial.

r? @Mark-Simulacrum
  • Loading branch information
RalfJung authored Sep 20, 2020
2 parents ad9ea71 + b9af3e3 commit 24980b7
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 21 deletions.
3 changes: 0 additions & 3 deletions src/bootstrap/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}
Expand Down
7 changes: 3 additions & 4 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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),
],
);
}
Expand Down Expand Up @@ -2301,9 +2300,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())
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down Expand Up @@ -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);
}
Expand Down
21 changes: 14 additions & 7 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand All @@ -395,6 +402,7 @@ impl Build {
targets: config.targets.clone(),

config,
version: version.to_string(),
src,
out,

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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")),
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions src/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.48.0

0 comments on commit 24980b7

Please sign in to comment.