Skip to content

Commit f6c87ab

Browse files
committed
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.
1 parent 66bf391 commit f6c87ab

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

src/bootstrap/builder.rs

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -860,28 +860,16 @@ impl<'a> Builder<'a> {
860860
stage = compiler.stage;
861861
}
862862

863-
let mut extra_args = String::new();
863+
let mut rustflags = Rustflags::new();
864+
rustflags.env(&format!("RUSTFLAGS_STAGE_{}", stage));
864865
if stage != 0 {
865-
let s = env::var("RUSTFLAGS_NOT_BOOTSTRAP").unwrap_or_default();
866-
extra_args.push_str(&s);
866+
rustflags.env("RUSTFLAGS_NOT_BOOTSTRAP");
867867
} else {
868-
let s = env::var("RUSTFLAGS_BOOTSTRAP").unwrap_or_default();
869-
extra_args.push_str(&s);
868+
rustflags.env("RUSTFLAGS_BOOTSTRAP");
870869
}
871870

872871
if cmd == "clippy" {
873-
extra_args.push_str("-Zforce-unstable-if-unmarked");
874-
}
875-
876-
if !extra_args.is_empty() {
877-
cargo.env(
878-
"RUSTFLAGS",
879-
format!(
880-
"{} {}",
881-
env::var("RUSTFLAGS").unwrap_or_default(),
882-
extra_args
883-
),
884-
);
872+
rustflags.arg("-Zforce-unstable-if-unmarked");
885873
}
886874

887875
let want_rustdoc = self.doc_tests != DocTests::No;
@@ -1171,6 +1159,8 @@ impl<'a> Builder<'a> {
11711159

11721160
self.ci_env.force_coloring_in_ci(&mut cargo);
11731161

1162+
cargo.env("RUSTFLAGS", &rustflags.0);
1163+
11741164
cargo
11751165
}
11761166

@@ -1271,3 +1261,30 @@ impl<'a> Builder<'a> {
12711261

12721262
#[cfg(test)]
12731263
mod tests;
1264+
1265+
struct Rustflags(String);
1266+
1267+
impl Rustflags {
1268+
fn new() -> Rustflags {
1269+
let mut ret = Rustflags(String::new());
1270+
ret.env("RUSTFLAGS");
1271+
return ret;
1272+
}
1273+
1274+
fn env(&mut self, env: &str) {
1275+
if let Ok(s) = env::var(env) {
1276+
for part in s.split_whitespace() {
1277+
self.arg(part);
1278+
}
1279+
}
1280+
}
1281+
1282+
fn arg(&mut self, arg: &str) -> &mut Self {
1283+
assert_eq!(arg.split_whitespace().count(), 1);
1284+
if self.0.len() > 0 {
1285+
self.0.push_str(" ");
1286+
}
1287+
self.0.push_str(arg);
1288+
self
1289+
}
1290+
}

0 commit comments

Comments
 (0)