From 72a3e570dbbfa1a9f2accef4e97e0a5e60dc09c5 Mon Sep 17 00:00:00 2001 From: est31 Date: Tue, 14 Jun 2022 06:00:36 +0200 Subject: [PATCH] bootstrap: compactify --check-cfg arguments The current code creates more --check-cfg arguments than needed, especially one argument per bare name. To save arguments, we now collect the name specific arguments into one. Before, the code this commit changes would have generated these arguments for a typical compiler crate: '--check-cfg=values(bootstrap)' '--check-cfg=values(parallel_compiler)' '--check-cfg=values(no_btreemap_remove_entry)' '--check-cfg=values(crossbeam_loom)' '--check-cfg=values(span_locations)' Now it generates: '--check-cfg=names(bootstrap,parallel_compiler,no_btreemap_remove_entry,crossbeam_loom,span_locations)' --- src/bootstrap/builder.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 38d4f15d3c858..38741722cdad4 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1410,20 +1410,27 @@ impl<'a> Builder<'a> { // cargo would implicitly add it, it was discover that sometimes bootstrap only use // `rustflags` without `cargo` making it required. rustflags.arg("-Zunstable-options"); + // First pass: find all the names without values and put them into one argument + let names = EXTRA_CHECK_CFGS + .iter() + .filter(|(restricted_mode, ..)| { + restricted_mode.is_none() || *restricted_mode == Some(mode) + }) + .filter(|(_, _, values)| values.is_none()) + .map(|(_, name, _)| *name) + .collect::>(); + if !names.is_empty() { + rustflags.arg(&format!("--check-cfg=names({})", names.join(","))); + } + // Second pass: find all the names that have a list of possible values for (restricted_mode, name, values) in EXTRA_CHECK_CFGS { - if *restricted_mode == None || *restricted_mode == Some(mode) { - // Creating a string of the values by concatenating each value: - // ',"tvos","watchos"' or '' (nothing) when there are no values - let values = match values { - Some(values) => values - .iter() - .map(|val| [",", "\"", val, "\""]) - .flatten() - .collect::(), - None => String::new(), - }; - rustflags.arg(&format!("--check-cfg=values({name}{values})")); + if !(restricted_mode.is_none() || *restricted_mode == Some(mode)) { + continue; } + let values = if let Some(values) = values { values } else { continue }; + let values = + values.iter().map(|val| [",", "\"", val, "\""]).flatten().collect::(); + rustflags.arg(&format!("--check-cfg=values({name}{values})")); } }