Skip to content

Commit 4f4c49b

Browse files
committed
Migrate x to using clap
1 parent b5c8c32 commit 4f4c49b

File tree

10 files changed

+452
-725
lines changed

10 files changed

+452
-725
lines changed

src/bootstrap/Cargo.lock

+73-18
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ version = "0.0.0"
3838
dependencies = [
3939
"build_helper",
4040
"cc",
41+
"clap",
4142
"cmake",
4243
"fd-lock",
4344
"filetime",
44-
"getopts",
4545
"hex",
4646
"ignore",
4747
"libc",
@@ -87,6 +87,40 @@ version = "1.0.0"
8787
source = "registry+https://github.com/rust-lang/crates.io-index"
8888
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
8989

90+
[[package]]
91+
name = "clap"
92+
version = "4.1.4"
93+
source = "registry+https://github.com/rust-lang/crates.io-index"
94+
checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76"
95+
dependencies = [
96+
"bitflags",
97+
"clap_derive",
98+
"clap_lex",
99+
"once_cell",
100+
]
101+
102+
[[package]]
103+
name = "clap_derive"
104+
version = "4.1.0"
105+
source = "registry+https://github.com/rust-lang/crates.io-index"
106+
checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8"
107+
dependencies = [
108+
"heck",
109+
"proc-macro-error",
110+
"proc-macro2",
111+
"quote",
112+
"syn",
113+
]
114+
115+
[[package]]
116+
name = "clap_lex"
117+
version = "0.3.1"
118+
source = "registry+https://github.com/rust-lang/crates.io-index"
119+
checksum = "783fe232adfca04f90f56201b26d79682d4cd2625e0bc7290b95123afe558ade"
120+
dependencies = [
121+
"os_str_bytes",
122+
]
123+
90124
[[package]]
91125
name = "cmake"
92126
version = "0.1.48"
@@ -256,15 +290,6 @@ dependencies = [
256290
"version_check",
257291
]
258292

259-
[[package]]
260-
name = "getopts"
261-
version = "0.2.21"
262-
source = "registry+https://github.com/rust-lang/crates.io-index"
263-
checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
264-
dependencies = [
265-
"unicode-width",
266-
]
267-
268293
[[package]]
269294
name = "globset"
270295
version = "0.4.8"
@@ -278,6 +303,12 @@ dependencies = [
278303
"regex",
279304
]
280305

306+
[[package]]
307+
name = "heck"
308+
version = "0.4.1"
309+
source = "registry+https://github.com/rust-lang/crates.io-index"
310+
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
311+
281312
[[package]]
282313
name = "hermit-abi"
283314
version = "0.1.19"
@@ -424,6 +455,12 @@ dependencies = [
424455
"winapi",
425456
]
426457

458+
[[package]]
459+
name = "os_str_bytes"
460+
version = "6.4.1"
461+
source = "registry+https://github.com/rust-lang/crates.io-index"
462+
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
463+
427464
[[package]]
428465
name = "output_vt100"
429466
version = "0.1.3"
@@ -451,6 +488,30 @@ dependencies = [
451488
"yansi",
452489
]
453490

491+
[[package]]
492+
name = "proc-macro-error"
493+
version = "1.0.4"
494+
source = "registry+https://github.com/rust-lang/crates.io-index"
495+
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
496+
dependencies = [
497+
"proc-macro-error-attr",
498+
"proc-macro2",
499+
"quote",
500+
"syn",
501+
"version_check",
502+
]
503+
504+
[[package]]
505+
name = "proc-macro-error-attr"
506+
version = "1.0.4"
507+
source = "registry+https://github.com/rust-lang/crates.io-index"
508+
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
509+
dependencies = [
510+
"proc-macro2",
511+
"quote",
512+
"version_check",
513+
]
514+
454515
[[package]]
455516
name = "proc-macro2"
456517
version = "1.0.46"
@@ -526,9 +587,9 @@ checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64"
526587

527588
[[package]]
528589
name = "rustix"
529-
version = "0.36.3"
590+
version = "0.36.7"
530591
source = "registry+https://github.com/rust-lang/crates.io-index"
531-
checksum = "0b1fbb4dfc4eb1d390c02df47760bb19a84bb80b301ecc947ab5406394d8223e"
592+
checksum = "d4fdebc4b395b7fbb9ab11e462e20ed9051e7b16e42d24042c776eca0ac81b03"
532593
dependencies = [
533594
"bitflags",
534595
"errno",
@@ -668,12 +729,6 @@ version = "1.0.0"
668729
source = "registry+https://github.com/rust-lang/crates.io-index"
669730
checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee"
670731

671-
[[package]]
672-
name = "unicode-width"
673-
version = "0.1.9"
674-
source = "registry+https://github.com/rust-lang/crates.io-index"
675-
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
676-
677732
[[package]]
678733
name = "version_check"
679734
version = "0.9.4"

src/bootstrap/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ build_helper = { path = "../tools/build_helper" }
3434
cmake = "0.1.38"
3535
fd-lock = "3.0.8"
3636
filetime = "0.2"
37-
getopts = "0.2.19"
3837
cc = "1.0.69"
38+
clap = { version = "4.1.4", features = ["std", "usage", "help", "derive", "error-context"], default-features = false}
3939
libc = "0.2"
4040
hex = "0.4"
4141
object = { version = "0.29.0", default-features = false, features = ["archive", "coff", "read_core", "unaligned"] }

src/bootstrap/builder.rs

+18-12
Original file line numberDiff line numberDiff line change
@@ -546,19 +546,24 @@ impl<'a> ShouldRun<'a> {
546546
}
547547
}
548548

549-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
549+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, clap::ValueEnum)]
550550
pub enum Kind {
551+
#[clap(aliases = ["b"])]
551552
Build,
553+
#[clap(aliases = ["c"])]
552554
Check,
553555
Clippy,
554556
Fix,
555557
Format,
558+
#[clap(aliases = ["t"])]
556559
Test,
557560
Bench,
561+
#[clap(aliases = ["d"])]
558562
Doc,
559563
Clean,
560564
Dist,
561565
Install,
566+
#[clap(aliases = ["r"])]
562567
Run,
563568
Setup,
564569
}
@@ -846,18 +851,19 @@ impl<'a> Builder<'a> {
846851
}
847852

848853
pub fn new(build: &Build) -> Builder<'_> {
854+
let paths = &build.config.paths;
849855
let (kind, paths) = match build.config.cmd {
850-
Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
851-
Subcommand::Check { ref paths } => (Kind::Check, &paths[..]),
852-
Subcommand::Clippy { ref paths, .. } => (Kind::Clippy, &paths[..]),
853-
Subcommand::Fix { ref paths } => (Kind::Fix, &paths[..]),
854-
Subcommand::Doc { ref paths, .. } => (Kind::Doc, &paths[..]),
855-
Subcommand::Test { ref paths, .. } => (Kind::Test, &paths[..]),
856-
Subcommand::Bench { ref paths, .. } => (Kind::Bench, &paths[..]),
857-
Subcommand::Dist { ref paths } => (Kind::Dist, &paths[..]),
858-
Subcommand::Install { ref paths } => (Kind::Install, &paths[..]),
859-
Subcommand::Run { ref paths, .. } => (Kind::Run, &paths[..]),
860-
Subcommand::Clean { ref paths, .. } => (Kind::Clean, &paths[..]),
856+
Subcommand::Build => (Kind::Build, &paths[..]),
857+
Subcommand::Check { .. } => (Kind::Check, &paths[..]),
858+
Subcommand::Clippy { .. } => (Kind::Clippy, &paths[..]),
859+
Subcommand::Fix => (Kind::Fix, &paths[..]),
860+
Subcommand::Doc { .. } => (Kind::Doc, &paths[..]),
861+
Subcommand::Test { .. } => (Kind::Test, &paths[..]),
862+
Subcommand::Bench { .. } => (Kind::Bench, &paths[..]),
863+
Subcommand::Dist => (Kind::Dist, &paths[..]),
864+
Subcommand::Install => (Kind::Install, &paths[..]),
865+
Subcommand::Run { .. } => (Kind::Run, &paths[..]),
866+
Subcommand::Clean { .. } => (Kind::Clean, &paths[..]),
861867
Subcommand::Format { .. } => (Kind::Format, &[][..]),
862868
Subcommand::Setup { profile: ref path } => (
863869
Kind::Setup,

src/bootstrap/builder/tests.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ mod defaults {
236236
fn doc_default() {
237237
let mut config = configure("doc", &["A"], &["A"]);
238238
config.compiler_docs = true;
239-
config.cmd = Subcommand::Doc { paths: Vec::new(), open: false, json: false };
239+
config.cmd = Subcommand::Doc { open: false, json: false };
240240
let mut cache = run_build(&[], config);
241241
let a = TargetSelection::from_user("A");
242242

@@ -545,19 +545,21 @@ mod dist {
545545
fn test_with_no_doc_stage0() {
546546
let mut config = configure(&["A"], &["A"]);
547547
config.stage = 0;
548+
config.paths = vec!["library/std".into()];
548549
config.cmd = Subcommand::Test {
549-
paths: vec!["library/std".into()],
550550
test_args: vec![],
551551
rustc_args: vec![],
552-
fail_fast: true,
553-
doc_tests: DocTests::No,
552+
no_fail_fast: false,
553+
no_doc: true,
554+
doc: false,
554555
bless: false,
555556
force_rerun: false,
556557
compare_mode: None,
557558
rustfix_coverage: false,
558559
pass: None,
559560
run: None,
560561
only_modified: false,
562+
skip: vec![],
561563
};
562564

563565
let build = Build::new(config);
@@ -588,7 +590,7 @@ mod dist {
588590
fn doc_ci() {
589591
let mut config = configure(&["A"], &["A"]);
590592
config.compiler_docs = true;
591-
config.cmd = Subcommand::Doc { paths: Vec::new(), open: false, json: false };
593+
config.cmd = Subcommand::Doc { open: false, json: false };
592594
let build = Build::new(config);
593595
let mut builder = Builder::new(&build);
594596
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Doc), &[]);
@@ -617,18 +619,19 @@ mod dist {
617619
// Behavior of `x.py test` doing various documentation tests.
618620
let mut config = configure(&["A"], &["A"]);
619621
config.cmd = Subcommand::Test {
620-
paths: vec![],
621622
test_args: vec![],
622623
rustc_args: vec![],
623-
fail_fast: true,
624-
doc_tests: DocTests::Yes,
624+
no_fail_fast: false,
625+
doc: true,
626+
no_doc: false,
625627
bless: false,
626628
force_rerun: false,
627629
compare_mode: None,
628630
rustfix_coverage: false,
629631
pass: None,
630632
run: None,
631633
only_modified: false,
634+
skip: vec![],
632635
};
633636
// Make sure rustfmt binary not being found isn't an error.
634637
config.channel = "beta".to_string();

src/bootstrap/check.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,7 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
2020
arr.iter().copied().map(String::from)
2121
}
2222

23-
if let Subcommand::Clippy {
24-
fix,
25-
clippy_lint_allow,
26-
clippy_lint_deny,
27-
clippy_lint_warn,
28-
clippy_lint_forbid,
29-
..
30-
} = &builder.config.cmd
31-
{
23+
if let Subcommand::Clippy { fix, allow, deny, warn, forbid, .. } = &builder.config.cmd {
3224
// disable the most spammy clippy lints
3325
let ignored_lints = vec![
3426
"many_single_char_names", // there are a lot in stdarch
@@ -53,10 +45,10 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
5345
args.extend(strings(&["--", "--cap-lints", "warn"]));
5446
args.extend(ignored_lints.iter().map(|lint| format!("-Aclippy::{}", lint)));
5547
let mut clippy_lint_levels: Vec<String> = Vec::new();
56-
clippy_lint_allow.iter().for_each(|v| clippy_lint_levels.push(format!("-A{}", v)));
57-
clippy_lint_deny.iter().for_each(|v| clippy_lint_levels.push(format!("-D{}", v)));
58-
clippy_lint_warn.iter().for_each(|v| clippy_lint_levels.push(format!("-W{}", v)));
59-
clippy_lint_forbid.iter().for_each(|v| clippy_lint_levels.push(format!("-F{}", v)));
48+
allow.iter().for_each(|v| clippy_lint_levels.push(format!("-A{}", v)));
49+
deny.iter().for_each(|v| clippy_lint_levels.push(format!("-D{}", v)));
50+
warn.iter().for_each(|v| clippy_lint_levels.push(format!("-W{}", v)));
51+
forbid.iter().for_each(|v| clippy_lint_levels.push(format!("-F{}", v)));
6052
args.extend(clippy_lint_levels);
6153
args.extend(builder.config.free_args.clone());
6254
args

src/bootstrap/config.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ pub struct Config {
231231
pub initial_rustfmt: RefCell<RustfmtState>,
232232
pub out: PathBuf,
233233
pub rust_info: channel::GitInfo,
234+
235+
pub paths: Vec<PathBuf>,
234236
}
235237

236238
#[derive(Default, Deserialize)]
@@ -366,6 +368,12 @@ pub struct TargetSelection {
366368
file: Option<Interned<String>>,
367369
}
368370

371+
impl<'a> From<&'a str> for TargetSelection {
372+
fn from(s: &'a str) -> Self {
373+
Self::from_user(s)
374+
}
375+
}
376+
369377
impl TargetSelection {
370378
pub fn from_user(selection: &str) -> Self {
371379
let path = Path::new(selection);
@@ -854,25 +862,26 @@ impl Config {
854862
}
855863

856864
fn parse_inner<'a>(args: &[String], get_toml: impl 'a + Fn(&Path) -> TomlConfig) -> Config {
857-
let flags = Flags::parse(&args);
865+
let mut flags = Flags::parse(&args);
858866
let mut config = Config::default_opts();
859867

860868
// Set flags.
869+
config.paths = std::mem::take(&mut flags.paths);
861870
config.exclude = flags.exclude.into_iter().map(|path| TaskPath::parse(path)).collect();
862871
config.include_default_paths = flags.include_default_paths;
863-
config.rustc_error_format = flags.rustc_error_format;
872+
config.rustc_error_format = flags.error_format;
864873
config.json_output = flags.json_output;
865874
config.on_fail = flags.on_fail;
866-
config.jobs = flags.jobs.map(threads_from_config);
875+
config.jobs = Some(threads_from_config(flags.jobs as u32));
867876
config.cmd = flags.cmd;
868877
config.incremental = flags.incremental;
869878
config.dry_run = if flags.dry_run { DryRun::UserSelected } else { DryRun::Disabled };
870879
config.keep_stage = flags.keep_stage;
871880
config.keep_stage_std = flags.keep_stage_std;
872881
config.color = flags.color;
873882
config.free_args = flags.free_args.clone().unwrap_or_default();
874-
if let Some(value) = flags.deny_warnings {
875-
config.deny_warnings = value;
883+
if matches!(flags.deny_warnings, crate::flags::Warnings::Deny) {
884+
config.deny_warnings = true;
876885
}
877886
config.llvm_profile_use = flags.llvm_profile_use;
878887
config.llvm_profile_generate = flags.llvm_profile_generate;
@@ -1045,7 +1054,7 @@ impl Config {
10451054
set(&mut config.print_step_rusage, build.print_step_rusage);
10461055
set(&mut config.patch_binaries_for_nix, build.patch_binaries_for_nix);
10471056

1048-
config.verbose = cmp::max(config.verbose, flags.verbose);
1057+
config.verbose = cmp::max(config.verbose, flags.verbose as usize);
10491058

10501059
if let Some(install) = toml.install {
10511060
config.prefix = install.prefix.map(PathBuf::from);
@@ -1123,7 +1132,6 @@ impl Config {
11231132
config.rustc_default_linker = rust.default_linker;
11241133
config.musl_root = rust.musl_root.map(PathBuf::from);
11251134
config.save_toolstates = rust.save_toolstates.map(PathBuf::from);
1126-
set(&mut config.deny_warnings, flags.deny_warnings.or(rust.deny_warnings));
11271135
set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
11281136
set(&mut config.rust_verify_llvm_ir, rust.verify_llvm_ir);
11291137
config.rust_thin_lto_import_instr_limit = rust.thin_lto_import_instr_limit;

0 commit comments

Comments
 (0)