bootstrap: Add a helper for managing RUSTFLAGS

Most of `bootstrap/bin/rustc.rs` doesn't need to exist with the advent
of `RUSTFLAGS` (yes this is super old) so this starts by refactoring a
bit to make it easier locally in the `Builder::cargo` method to append
to `RUSTFLAGS` that gets down to rustc.
This commit is contained in:
Alex Crichton 2019-08-15 13:42:39 -07:00
parent 66bf391c3a
commit f6c87aba32

View File

@ -860,28 +860,16 @@ impl<'a> Builder<'a> {
stage = compiler.stage; stage = compiler.stage;
} }
let mut extra_args = String::new(); let mut rustflags = Rustflags::new();
rustflags.env(&format!("RUSTFLAGS_STAGE_{}", stage));
if stage != 0 { if stage != 0 {
let s = env::var("RUSTFLAGS_NOT_BOOTSTRAP").unwrap_or_default(); rustflags.env("RUSTFLAGS_NOT_BOOTSTRAP");
extra_args.push_str(&s);
} else { } else {
let s = env::var("RUSTFLAGS_BOOTSTRAP").unwrap_or_default(); rustflags.env("RUSTFLAGS_BOOTSTRAP");
extra_args.push_str(&s);
} }
if cmd == "clippy" { if cmd == "clippy" {
extra_args.push_str("-Zforce-unstable-if-unmarked"); rustflags.arg("-Zforce-unstable-if-unmarked");
}
if !extra_args.is_empty() {
cargo.env(
"RUSTFLAGS",
format!(
"{} {}",
env::var("RUSTFLAGS").unwrap_or_default(),
extra_args
),
);
} }
let want_rustdoc = self.doc_tests != DocTests::No; let want_rustdoc = self.doc_tests != DocTests::No;
@ -1171,6 +1159,8 @@ impl<'a> Builder<'a> {
self.ci_env.force_coloring_in_ci(&mut cargo); self.ci_env.force_coloring_in_ci(&mut cargo);
cargo.env("RUSTFLAGS", &rustflags.0);
cargo cargo
} }
@ -1271,3 +1261,30 @@ impl<'a> Builder<'a> {
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
struct Rustflags(String);
impl Rustflags {
fn new() -> Rustflags {
let mut ret = Rustflags(String::new());
ret.env("RUSTFLAGS");
return ret;
}
fn env(&mut self, env: &str) {
if let Ok(s) = env::var(env) {
for part in s.split_whitespace() {
self.arg(part);
}
}
}
fn arg(&mut self, arg: &str) -> &mut Self {
assert_eq!(arg.split_whitespace().count(), 1);
if self.0.len() > 0 {
self.0.push_str(" ");
}
self.0.push_str(arg);
self
}
}