Skip to content

Commit 5431a93

Browse files
committed
Pass Flags to Config::parse explicitly
1 parent 03ee7b5 commit 5431a93

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

src/bootstrap/src/bin/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ use bootstrap::{
1717

1818
fn main() {
1919
let args = env::args().skip(1).collect::<Vec<_>>();
20-
let config = Config::parse(&args);
2120

2221
if Flags::try_parse_verbose_help(&args) {
2322
return;
2423
}
2524

25+
let flags = Flags::parse(&args);
26+
let config = Config::parse(flags);
27+
2628
let mut build_lock;
2729
let _build_lock_guard;
2830

src/bootstrap/src/core/builder/tests.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ use std::thread;
33
use super::*;
44
use crate::core::build_steps::doc::DocumentationFormat;
55
use crate::core::config::Config;
6+
use crate::Flags;
67

78
fn configure(cmd: &str, host: &[&str], target: &[&str]) -> Config {
89
configure_with_args(&[cmd.to_owned()], host, target)
910
}
1011

1112
fn configure_with_args(cmd: &[String], host: &[&str], target: &[&str]) -> Config {
12-
let mut config = Config::parse(cmd);
13+
let mut config = Config::parse(Flags::parse(cmd));
1314
// don't save toolstates
1415
config.save_toolstates = None;
1516
config.dry_run = DryRun::SelfCheck;
@@ -23,7 +24,7 @@ fn configure_with_args(cmd: &[String], host: &[&str], target: &[&str]) -> Config
2324
let submodule_build = Build::new(Config {
2425
// don't include LLVM, so CI doesn't require ninja/cmake to be installed
2526
rust_codegen_backends: vec![],
26-
..Config::parse(&["check".to_owned()])
27+
..Config::parse(Flags::parse(&["check".to_owned()]))
2728
});
2829
submodule_build.require_submodule("src/doc/book", None);
2930
config.submodules = Some(false);

src/bootstrap/src/core/config/config.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ impl Config {
11881188
}
11891189
}
11901190

1191-
pub fn parse(args: &[String]) -> Config {
1191+
pub fn parse(flags: Flags) -> Config {
11921192
#[cfg(test)]
11931193
fn get_toml(_: &Path) -> TomlConfig {
11941194
TomlConfig::default()
@@ -1218,11 +1218,10 @@ impl Config {
12181218
exit!(2);
12191219
})
12201220
}
1221-
Self::parse_inner(args, get_toml)
1221+
Self::parse_inner(flags, get_toml)
12221222
}
12231223

1224-
pub(crate) fn parse_inner(args: &[String], get_toml: impl Fn(&Path) -> TomlConfig) -> Config {
1225-
let mut flags = Flags::parse(args);
1224+
pub(crate) fn parse_inner(mut flags: Flags, get_toml: impl Fn(&Path) -> TomlConfig) -> Config {
12261225
let mut config = Config::default_opts();
12271226

12281227
// Set flags.

src/bootstrap/src/core/config/tests.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ use crate::core::build_steps::clippy::get_clippy_rules_in_order;
1212
use crate::core::config::{LldMode, Target, TargetSelection, TomlConfig};
1313

1414
fn parse(config: &str) -> Config {
15-
Config::parse_inner(&["check".to_string(), "--config=/does/not/exist".to_string()], |&_| {
16-
toml::from_str(&config).unwrap()
17-
})
15+
Config::parse_inner(
16+
Flags::parse(&["check".to_string(), "--config=/does/not/exist".to_string()]),
17+
|&_| toml::from_str(&config).unwrap(),
18+
)
1819
}
1920

2021
#[test]
@@ -108,7 +109,7 @@ fn clap_verify() {
108109
#[test]
109110
fn override_toml() {
110111
let config = Config::parse_inner(
111-
&[
112+
Flags::parse(&[
112113
"check".to_owned(),
113114
"--config=/does/not/exist".to_owned(),
114115
"--set=change-id=1".to_owned(),
@@ -121,7 +122,7 @@ fn override_toml() {
121122
"--set=target.x86_64-unknown-linux-gnu.rpath=false".to_owned(),
122123
"--set=target.aarch64-unknown-linux-gnu.sanitizers=false".to_owned(),
123124
"--set=target.aarch64-apple-darwin.runner=apple".to_owned(),
124-
],
125+
]),
125126
|&_| {
126127
toml::from_str(
127128
r#"
@@ -201,12 +202,12 @@ runner = "x86_64-runner"
201202
#[should_panic]
202203
fn override_toml_duplicate() {
203204
Config::parse_inner(
204-
&[
205+
Flags::parse(&[
205206
"check".to_owned(),
206207
"--config=/does/not/exist".to_string(),
207208
"--set=change-id=1".to_owned(),
208209
"--set=change-id=2".to_owned(),
209-
],
210+
]),
210211
|&_| toml::from_str("change-id = 0").unwrap(),
211212
);
212213
}
@@ -226,7 +227,7 @@ fn profile_user_dist() {
226227
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
227228
.unwrap()
228229
}
229-
Config::parse_inner(&["check".to_owned()], get_toml);
230+
Config::parse_inner(Flags::parse(&["check".to_owned()]), get_toml);
230231
}
231232

232233
#[test]
@@ -301,7 +302,7 @@ fn order_of_clippy_rules() {
301302
"-Aclippy::foo1".to_string(),
302303
"-Aclippy::foo2".to_string(),
303304
];
304-
let config = Config::parse(&args);
305+
let config = Config::parse(Flags::parse(&args));
305306

306307
let actual = match &config.cmd {
307308
crate::Subcommand::Clippy { allow, deny, warn, forbid, .. } => {

src/bootstrap/src/utils/helpers/tests.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::path::PathBuf;
55
use crate::utils::helpers::{
66
check_cfg_arg, extract_beta_rev, hex_encode, make, program_out_of_date, symlink_dir,
77
};
8-
use crate::Config;
8+
use crate::{Config, Flags};
99

1010
#[test]
1111
fn test_make() {
@@ -58,7 +58,8 @@ fn test_check_cfg_arg() {
5858

5959
#[test]
6060
fn test_program_out_of_date() {
61-
let config = Config::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]);
61+
let config =
62+
Config::parse(Flags::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]));
6263
let tempfile = config.tempdir().join(".tmp-stamp-file");
6364
File::create(&tempfile).unwrap().write_all(b"dummy value").unwrap();
6465
assert!(tempfile.exists());
@@ -73,7 +74,8 @@ fn test_program_out_of_date() {
7374

7475
#[test]
7576
fn test_symlink_dir() {
76-
let config = Config::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]);
77+
let config =
78+
Config::parse(Flags::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]));
7779
let tempdir = config.tempdir().join(".tmp-dir");
7880
let link_path = config.tempdir().join(".tmp-link");
7981

0 commit comments

Comments
 (0)