Skip to content

Commit 32e27cc

Browse files
committed
Migrate bootstrap to Clap-based arguments
1 parent 74c4821 commit 32e27cc

File tree

10 files changed

+481
-730
lines changed

10 files changed

+481
-730
lines changed

src/bootstrap/Cargo.lock

+70-22
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ dependencies = [
1111
"memchr",
1212
]
1313

14+
[[package]]
15+
name = "anstyle"
16+
version = "1.0.0"
17+
source = "registry+https://github.com/rust-lang/crates.io-index"
18+
checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d"
19+
1420
[[package]]
1521
name = "autocfg"
1622
version = "1.1.0"
@@ -38,10 +44,10 @@ version = "0.0.0"
3844
dependencies = [
3945
"build_helper",
4046
"cc",
47+
"clap",
4148
"cmake",
4249
"fd-lock",
4350
"filetime",
44-
"getopts",
4551
"hex",
4652
"ignore",
4753
"is-terminal",
@@ -91,6 +97,46 @@ version = "1.0.0"
9197
source = "registry+https://github.com/rust-lang/crates.io-index"
9298
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
9399

100+
[[package]]
101+
name = "clap"
102+
version = "4.2.4"
103+
source = "registry+https://github.com/rust-lang/crates.io-index"
104+
checksum = "956ac1f6381d8d82ab4684768f89c0ea3afe66925ceadb4eeb3fc452ffc55d62"
105+
dependencies = [
106+
"clap_builder",
107+
"clap_derive",
108+
"once_cell",
109+
]
110+
111+
[[package]]
112+
name = "clap_builder"
113+
version = "4.2.4"
114+
source = "registry+https://github.com/rust-lang/crates.io-index"
115+
checksum = "84080e799e54cff944f4b4a4b0e71630b0e0443b25b985175c7dddc1a859b749"
116+
dependencies = [
117+
"anstyle",
118+
"bitflags",
119+
"clap_lex",
120+
]
121+
122+
[[package]]
123+
name = "clap_derive"
124+
version = "4.2.0"
125+
source = "registry+https://github.com/rust-lang/crates.io-index"
126+
checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4"
127+
dependencies = [
128+
"heck",
129+
"proc-macro2",
130+
"quote",
131+
"syn 2.0.15",
132+
]
133+
134+
[[package]]
135+
name = "clap_lex"
136+
version = "0.4.1"
137+
source = "registry+https://github.com/rust-lang/crates.io-index"
138+
checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1"
139+
94140
[[package]]
95141
name = "cmake"
96142
version = "0.1.48"
@@ -175,7 +221,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
175221
checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c"
176222
dependencies = [
177223
"quote",
178-
"syn",
224+
"syn 1.0.102",
179225
]
180226

181227
[[package]]
@@ -260,15 +306,6 @@ dependencies = [
260306
"version_check",
261307
]
262308

263-
[[package]]
264-
name = "getopts"
265-
version = "0.2.21"
266-
source = "registry+https://github.com/rust-lang/crates.io-index"
267-
checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
268-
dependencies = [
269-
"unicode-width",
270-
]
271-
272309
[[package]]
273310
name = "globset"
274311
version = "0.4.8"
@@ -282,6 +319,12 @@ dependencies = [
282319
"regex",
283320
]
284321

322+
[[package]]
323+
name = "heck"
324+
version = "0.4.1"
325+
source = "registry+https://github.com/rust-lang/crates.io-index"
326+
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
327+
285328
[[package]]
286329
name = "hermit-abi"
287330
version = "0.1.19"
@@ -486,18 +529,18 @@ dependencies = [
486529

487530
[[package]]
488531
name = "proc-macro2"
489-
version = "1.0.46"
532+
version = "1.0.56"
490533
source = "registry+https://github.com/rust-lang/crates.io-index"
491-
checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b"
534+
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
492535
dependencies = [
493536
"unicode-ident",
494537
]
495538

496539
[[package]]
497540
name = "quote"
498-
version = "1.0.18"
541+
version = "1.0.26"
499542
source = "registry+https://github.com/rust-lang/crates.io-index"
500-
checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1"
543+
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
501544
dependencies = [
502545
"proc-macro2",
503546
]
@@ -606,7 +649,7 @@ checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be"
606649
dependencies = [
607650
"proc-macro2",
608651
"quote",
609-
"syn",
652+
"syn 1.0.102",
610653
]
611654

612655
[[package]]
@@ -642,6 +685,17 @@ dependencies = [
642685
"unicode-ident",
643686
]
644687

688+
[[package]]
689+
name = "syn"
690+
version = "2.0.15"
691+
source = "registry+https://github.com/rust-lang/crates.io-index"
692+
checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
693+
dependencies = [
694+
"proc-macro2",
695+
"quote",
696+
"unicode-ident",
697+
]
698+
645699
[[package]]
646700
name = "sysinfo"
647701
version = "0.26.7"
@@ -707,12 +761,6 @@ version = "1.0.0"
707761
source = "registry+https://github.com/rust-lang/crates.io-index"
708762
checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee"
709763

710-
[[package]]
711-
name = "unicode-width"
712-
version = "0.1.9"
713-
source = "registry+https://github.com/rust-lang/crates.io-index"
714-
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
715-
716764
[[package]]
717765
name = "version_check"
718766
version = "0.9.4"

src/bootstrap/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ is-terminal = "0.4"
3434
build_helper = { path = "../tools/build_helper" }
3535
cmake = "0.1.38"
3636
filetime = "0.2"
37-
getopts = "0.2.19"
3837
cc = "1.0.69"
3938
libc = "0.2"
4039
hex = "0.4"
@@ -56,6 +55,7 @@ walkdir = "2"
5655

5756
# Dependencies needed by the build-metrics feature
5857
sysinfo = { version = "0.26.0", optional = true }
58+
clap = { version = "4.2.4", default-features = false, features = ["std", "usage", "help", "derive", "error-context"] }
5959

6060
# Solaris doesn't support flock() and thus fd-lock is not option now
6161
[target.'cfg(not(target_os = "solaris"))'.dependencies]
@@ -86,6 +86,7 @@ build-metrics = ["sysinfo"]
8686
# dependencies, only bootstrap itself.
8787
[profile.dev]
8888
debug = 0
89+
8990
[profile.dev.package]
9091
# Only use debuginfo=1 to further reduce compile times.
9192
bootstrap.debug = 1

src/bootstrap/builder.rs

+19-12
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub use crate::Compiler;
3333
// - use std::lazy for `Lazy`
3434
// - use std::cell for `OnceCell`
3535
// Once they get stabilized and reach beta.
36+
use clap::ValueEnum;
3637
use once_cell::sync::{Lazy, OnceCell};
3738

3839
pub struct Builder<'a> {
@@ -576,19 +577,24 @@ impl<'a> ShouldRun<'a> {
576577
}
577578
}
578579

579-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
580+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, ValueEnum)]
580581
pub enum Kind {
582+
#[clap(alias = "b")]
581583
Build,
584+
#[clap(alias = "c")]
582585
Check,
583586
Clippy,
584587
Fix,
585588
Format,
589+
#[clap(alias = "t")]
586590
Test,
587591
Bench,
592+
#[clap(alias = "d")]
588593
Doc,
589594
Clean,
590595
Dist,
591596
Install,
597+
#[clap(alias = "r")]
592598
Run,
593599
Setup,
594600
Suggest,
@@ -887,18 +893,19 @@ impl<'a> Builder<'a> {
887893
}
888894

889895
pub fn new(build: &Build) -> Builder<'_> {
896+
let paths = &build.config.paths;
890897
let (kind, paths) = match build.config.cmd {
891-
Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
892-
Subcommand::Check { ref paths } => (Kind::Check, &paths[..]),
893-
Subcommand::Clippy { ref paths, .. } => (Kind::Clippy, &paths[..]),
894-
Subcommand::Fix { ref paths } => (Kind::Fix, &paths[..]),
895-
Subcommand::Doc { ref paths, .. } => (Kind::Doc, &paths[..]),
896-
Subcommand::Test { ref paths, .. } => (Kind::Test, &paths[..]),
897-
Subcommand::Bench { ref paths, .. } => (Kind::Bench, &paths[..]),
898-
Subcommand::Dist { ref paths } => (Kind::Dist, &paths[..]),
899-
Subcommand::Install { ref paths } => (Kind::Install, &paths[..]),
900-
Subcommand::Run { ref paths, .. } => (Kind::Run, &paths[..]),
901-
Subcommand::Clean { ref paths, .. } => (Kind::Clean, &paths[..]),
898+
Subcommand::Build => (Kind::Build, &paths[..]),
899+
Subcommand::Check { .. } => (Kind::Check, &paths[..]),
900+
Subcommand::Clippy { .. } => (Kind::Clippy, &paths[..]),
901+
Subcommand::Fix => (Kind::Fix, &paths[..]),
902+
Subcommand::Doc { .. } => (Kind::Doc, &paths[..]),
903+
Subcommand::Test { .. } => (Kind::Test, &paths[..]),
904+
Subcommand::Bench { .. } => (Kind::Bench, &paths[..]),
905+
Subcommand::Dist => (Kind::Dist, &paths[..]),
906+
Subcommand::Install => (Kind::Install, &paths[..]),
907+
Subcommand::Run { .. } => (Kind::Run, &paths[..]),
908+
Subcommand::Clean { .. } => (Kind::Clean, &paths[..]),
902909
Subcommand::Format { .. } => (Kind::Format, &[][..]),
903910
Subcommand::Suggest { .. } => (Kind::Suggest, &[][..]),
904911
Subcommand::Setup { profile: ref path } => (

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);
@@ -587,7 +589,7 @@ mod dist {
587589
fn doc_ci() {
588590
let mut config = configure(&["A"], &["A"]);
589591
config.compiler_docs = true;
590-
config.cmd = Subcommand::Doc { paths: Vec::new(), open: false, json: false };
592+
config.cmd = Subcommand::Doc { open: false, json: false };
591593
let build = Build::new(config);
592594
let mut builder = Builder::new(&build);
593595
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Doc), &[]);
@@ -616,11 +618,12 @@ mod dist {
616618
// Behavior of `x.py test` doing various documentation tests.
617619
let mut config = configure(&["A"], &["A"]);
618620
config.cmd = Subcommand::Test {
619-
paths: vec![],
620621
test_args: vec![],
621622
rustc_args: vec![],
622-
fail_fast: true,
623-
doc_tests: DocTests::Yes,
623+
no_fail_fast: false,
624+
doc: true,
625+
no_doc: false,
626+
skip: vec![],
624627
bless: false,
625628
force_rerun: false,
626629
compare_mode: None,

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

0 commit comments

Comments
 (0)