Skip to content

Commit a52564d

Browse files
authored
Revert clap from arg parsing during setup (rust-lang#3078)
`--help` and `--version` commands were being overriden by clap, so we are going back to the simple parsing with the added logic for `use-local-toolchain`. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent 6dfe0a0 commit a52564d

File tree

3 files changed

+52
-116
lines changed

3 files changed

+52
-116
lines changed

Cargo.lock

Lines changed: 5 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,6 @@ dependencies = [
3333
"memchr",
3434
]
3535

36-
[[package]]
37-
name = "ansi_term"
38-
version = "0.12.1"
39-
source = "registry+https://github.com/rust-lang/crates.io-index"
40-
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
41-
dependencies = [
42-
"winapi",
43-
]
44-
4536
[[package]]
4637
name = "anstream"
4738
version = "0.6.13"
@@ -96,17 +87,6 @@ version = "1.0.80"
9687
source = "registry+https://github.com/rust-lang/crates.io-index"
9788
checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1"
9889

99-
[[package]]
100-
name = "atty"
101-
version = "0.2.14"
102-
source = "registry+https://github.com/rust-lang/crates.io-index"
103-
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
104-
dependencies = [
105-
"hermit-abi",
106-
"libc",
107-
"winapi",
108-
]
109-
11090
[[package]]
11191
name = "autocfg"
11292
version = "1.1.0"
@@ -145,7 +125,7 @@ version = "0.48.0"
145125
dependencies = [
146126
"anyhow",
147127
"cargo_metadata",
148-
"clap 4.5.2",
128+
"clap",
149129
"which",
150130
]
151131

@@ -187,21 +167,6 @@ version = "1.0.0"
187167
source = "registry+https://github.com/rust-lang/crates.io-index"
188168
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
189169

190-
[[package]]
191-
name = "clap"
192-
version = "2.34.0"
193-
source = "registry+https://github.com/rust-lang/crates.io-index"
194-
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
195-
dependencies = [
196-
"ansi_term",
197-
"atty",
198-
"bitflags 1.3.2",
199-
"strsim 0.8.0",
200-
"textwrap",
201-
"unicode-width",
202-
"vec_map",
203-
]
204-
205170
[[package]]
206171
name = "clap"
207172
version = "4.5.2"
@@ -221,7 +186,7 @@ dependencies = [
221186
"anstream",
222187
"anstyle",
223188
"clap_lex",
224-
"strsim 0.11.0",
189+
"strsim",
225190
]
226191

227192
[[package]]
@@ -427,15 +392,6 @@ version = "0.4.1"
427392
source = "registry+https://github.com/rust-lang/crates.io-index"
428393
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
429394

430-
[[package]]
431-
name = "hermit-abi"
432-
version = "0.1.19"
433-
source = "registry+https://github.com/rust-lang/crates.io-index"
434-
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
435-
dependencies = [
436-
"libc",
437-
]
438-
439395
[[package]]
440396
name = "home"
441397
version = "0.5.9"
@@ -481,7 +437,7 @@ dependencies = [
481437
name = "kani-compiler"
482438
version = "0.48.0"
483439
dependencies = [
484-
"clap 4.5.2",
440+
"clap",
485441
"cprover_bindings",
486442
"home",
487443
"itertools",
@@ -504,7 +460,7 @@ version = "0.48.0"
504460
dependencies = [
505461
"anyhow",
506462
"cargo_metadata",
507-
"clap 4.5.2",
463+
"clap",
508464
"comfy-table",
509465
"console",
510466
"glob",
@@ -531,7 +487,6 @@ name = "kani-verifier"
531487
version = "0.48.0"
532488
dependencies = [
533489
"anyhow",
534-
"clap 2.34.0",
535490
"home",
536491
"os_info",
537492
]
@@ -550,7 +505,7 @@ dependencies = [
550505
name = "kani_metadata"
551506
version = "0.48.0"
552507
dependencies = [
553-
"clap 4.5.2",
508+
"clap",
554509
"cprover_bindings",
555510
"serde",
556511
"strum 0.26.2",
@@ -1095,12 +1050,6 @@ dependencies = [
10951050
"serde",
10961051
]
10971052

1098-
[[package]]
1099-
name = "strsim"
1100-
version = "0.8.0"
1101-
source = "registry+https://github.com/rust-lang/crates.io-index"
1102-
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
1103-
11041053
[[package]]
11051054
name = "strsim"
11061055
version = "0.11.0"
@@ -1178,15 +1127,6 @@ dependencies = [
11781127
"windows-sys",
11791128
]
11801129

1181-
[[package]]
1182-
name = "textwrap"
1183-
version = "0.11.0"
1184-
source = "registry+https://github.com/rust-lang/crates.io-index"
1185-
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
1186-
dependencies = [
1187-
"unicode-width",
1188-
]
1189-
11901130
[[package]]
11911131
name = "thiserror"
11921132
version = "1.0.57"
@@ -1365,12 +1305,6 @@ version = "0.1.0"
13651305
source = "registry+https://github.com/rust-lang/crates.io-index"
13661306
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
13671307

1368-
[[package]]
1369-
name = "vec_map"
1370-
version = "0.8.2"
1371-
source = "registry+https://github.com/rust-lang/crates.io-index"
1372-
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
1373-
13741308
[[package]]
13751309
name = "version_check"
13761310
version = "0.9.4"

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ include = ["/src", "/build.rs", "/rust-toolchain.toml", "/LICENSE-*", "/README.m
1919
[dependencies]
2020
anyhow = "1"
2121
home = "0.5"
22-
clap = "2.33.3"
2322
os_info = { version = "3", default-features = false }
2423

2524
[[bin]]

src/lib.rs

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ mod cmd;
1616
mod os_hacks;
1717
mod setup;
1818

19-
use clap::{App, Arg, SubCommand};
2019
use std::ffi::OsString;
2120
use std::os::unix::prelude::CommandExt;
2221
use std::path::{Path, PathBuf};
@@ -60,50 +59,54 @@ enum ArgsResult {
6059

6160
/// Parse `args` and decide what to do.
6261
fn parse_args(args: Vec<OsString>) -> ArgsResult {
63-
let matches = App::new("kani")
64-
.subcommand(
65-
SubCommand::with_name("setup")
66-
.arg(Arg::with_name("use-local-bundle").long("use-local-bundle").takes_value(true))
67-
.arg(
68-
Arg::with_name("use-local-toolchain")
69-
.long("use-local-toolchain")
70-
.takes_value(true),
71-
),
72-
)
73-
.subcommand(
74-
SubCommand::with_name("kani").subcommand(
75-
SubCommand::with_name("setup")
76-
.arg(
77-
Arg::with_name("use-local-bundle")
78-
.long("use-local-bundle")
79-
.takes_value(true),
80-
)
81-
.arg(
82-
Arg::with_name("use-local-toolchain")
83-
.long("use-local-toolchain")
84-
.takes_value(true),
85-
),
86-
),
87-
)
88-
.get_matches_from(args);
89-
90-
// Default is the behaviour for Kani when cargo-kani/ cargo kani runs on its own and sees that there is no setup done yet
91-
// Explicit is when the user uses the sub-command cargo-kani setup explicitly
92-
if let Some(matches) = matches.subcommand_matches("setup") {
93-
let use_local_toolchain = matches.value_of_os("use-local-toolchain").map(OsString::from);
94-
let use_local_bundle = matches.value_of_os("use-local-bundle").map(OsString::from);
95-
ArgsResult::ExplicitSetup { use_local_bundle, use_local_toolchain }
96-
} else if let Some(matches) = matches.subcommand_matches("kani") {
97-
if let Some(matches) = matches.subcommand_matches("setup") {
98-
let use_local_toolchain =
99-
matches.value_of_os("use-local-toolchain").map(OsString::from);
100-
let use_local_bundle = matches.value_of_os("use-local-bundle").map(OsString::from);
101-
ArgsResult::ExplicitSetup { use_local_bundle, use_local_toolchain }
102-
} else {
103-
ArgsResult::Default
62+
// In an effort to keep our dependencies minimal, we do the bare minimum argument parsing manually.
63+
// `args_ez` makes it easy to do crude arg parsing with match.
64+
let args_ez: Vec<Option<&str>> = args.iter().map(|x| x.to_str()).collect();
65+
// "cargo kani setup" comes in as "cargo-kani kani setup"
66+
// "cargo-kani setup" comes in as "cargo-kani setup"
67+
match &args_ez[..] {
68+
&[_, Some("setup"), Some("--use-local-bundle"), _, Some("--use-local-toolchain"), _] => {
69+
ArgsResult::ExplicitSetup {
70+
use_local_bundle: Some(args[3].clone()),
71+
use_local_toolchain: Some(args[5].clone()),
72+
}
73+
}
74+
&[
75+
_,
76+
Some("kani"),
77+
Some("setup"),
78+
Some("--use-local-bundle"),
79+
_,
80+
Some("--use-local-toolchain"),
81+
_,
82+
] => ArgsResult::ExplicitSetup {
83+
use_local_bundle: Some(args[4].clone()),
84+
use_local_toolchain: Some(args[6].clone()),
85+
},
86+
&[_, Some("setup"), Some("--use-local-bundle"), _] => ArgsResult::ExplicitSetup {
87+
use_local_bundle: Some(args[3].clone()),
88+
use_local_toolchain: None,
89+
},
90+
&[_, Some("kani"), Some("setup"), Some("--use-local-bundle"), _] => {
91+
ArgsResult::ExplicitSetup {
92+
use_local_bundle: Some(args[4].clone()),
93+
use_local_toolchain: None,
94+
}
95+
}
96+
&[_, Some("setup"), Some("--use-local-toolchain"), _] => ArgsResult::ExplicitSetup {
97+
use_local_bundle: None,
98+
use_local_toolchain: Some(args[3].clone()),
99+
},
100+
&[_, Some("kani"), Some("setup"), Some("--use-local-toolchain"), _] => {
101+
ArgsResult::ExplicitSetup {
102+
use_local_bundle: None,
103+
use_local_toolchain: Some(args[4].clone()),
104+
}
105+
}
106+
&[_, Some("setup")] | &[_, Some("kani"), Some("setup")] => {
107+
ArgsResult::ExplicitSetup { use_local_bundle: None, use_local_toolchain: None }
104108
}
105-
} else {
106-
ArgsResult::Default
109+
_ => ArgsResult::Default,
107110
}
108111
}
109112

0 commit comments

Comments
 (0)