Skip to content

Commit 2470b6b

Browse files
Add ability to ignore git when building rust.
Some users of the build system change the git sha on every build due to utilizing git to push changes to a remote server. This allows them to simply configure that away instead of depending on custom patches to rustbuild.
1 parent 302a08c commit 2470b6b

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

src/bootstrap/channel.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::process::Command;
2121
use build_helper::output;
2222

2323
use Build;
24+
use config::Config;
2425

2526
// The version number
2627
pub const CFG_RELEASE_NUM: &str = "1.21.0";
@@ -41,9 +42,9 @@ struct Info {
4142
}
4243

4344
impl GitInfo {
44-
pub fn new(dir: &Path) -> GitInfo {
45+
pub fn new(config: &Config, dir: &Path) -> GitInfo {
4546
// See if this even begins to look like a git dir
46-
if !dir.join(".git").exists() {
47+
if config.ignore_git || !dir.join(".git").exists() {
4748
return GitInfo { inner: None }
4849
}
4950

src/bootstrap/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub struct Config {
5454
pub extended: bool,
5555
pub sanitizers: bool,
5656
pub profiler: bool,
57+
pub ignore_git: bool,
5758

5859
pub on_fail: Option<String>,
5960
pub stage: Option<u32>,
@@ -258,6 +259,7 @@ struct Rust {
258259
optimize_tests: Option<bool>,
259260
debuginfo_tests: Option<bool>,
260261
codegen_tests: Option<bool>,
262+
ignore_git: Option<bool>,
261263
}
262264

263265
/// TOML representation of how each build target is configured.
@@ -289,6 +291,7 @@ impl Config {
289291
config.rust_codegen_units = 1;
290292
config.channel = "dev".to_string();
291293
config.codegen_tests = true;
294+
config.ignore_git = false;
292295
config.rust_dist_src = true;
293296

294297
config.on_fail = flags.on_fail;
@@ -406,6 +409,7 @@ impl Config {
406409
set(&mut config.use_jemalloc, rust.use_jemalloc);
407410
set(&mut config.backtrace, rust.backtrace);
408411
set(&mut config.channel, rust.channel.clone());
412+
set(&mut config.ignore_git, rust.ignore_git);
409413
config.rustc_default_linker = rust.default_linker.clone();
410414
config.rustc_default_ar = rust.default_ar.clone();
411415
config.musl_root = rust.musl_root.clone().map(PathBuf::from);

src/bootstrap/config.toml.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@
254254
# saying that the FileCheck executable is missing, you may want to disable this.
255255
#codegen-tests = true
256256

257+
# Flag indicating whether git info will be retrieved from .git automatically.
258+
#ignore-git = false
259+
257260
# =============================================================================
258261
# Options for specific targets
259262
#

src/bootstrap/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ impl Build {
299299
}
300300
None => false,
301301
};
302-
let rust_info = channel::GitInfo::new(&src);
303-
let cargo_info = channel::GitInfo::new(&src.join("src/tools/cargo"));
304-
let rls_info = channel::GitInfo::new(&src.join("src/tools/rls"));
302+
let rust_info = channel::GitInfo::new(&config, &src);
303+
let cargo_info = channel::GitInfo::new(&config, &src.join("src/tools/cargo"));
304+
let rls_info = channel::GitInfo::new(&config, &src.join("src/tools/rls"));
305305

306306
Build {
307307
initial_rustc: config.initial_rustc.clone(),

src/bootstrap/tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl Step for ToolBuild {
109109

110110
cargo.env("CFG_RELEASE_CHANNEL", &build.config.channel);
111111

112-
let info = GitInfo::new(&dir);
112+
let info = GitInfo::new(&build.config, &dir);
113113
if let Some(sha) = info.sha() {
114114
cargo.env("CFG_COMMIT_HASH", sha);
115115
}

0 commit comments

Comments
 (0)