Skip to content

Commit 5b2352c

Browse files
committed
Don't crash when running cargo profdata --help
Previously, the cargo wrapper tried to access CLI flags that were only defined when `needs_build` was true. Omit the access for commands that don't need those flags. Before: ``` thread 'main' (13996246) panicked at src/lib.rs:283:37: Mismatch between definition and access of `features`. Unknown argument or group id. Make sure you are using the argument id and not the short or long flags ``` After: ``` Proxy for the `llvm-profdata` tool shipped with the Rust toolchain. Usage: cargo-profdata [OPTIONS] [-- <args>...] ... ```
1 parent fa6d682 commit 5b2352c

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/lib.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ To see all the flags the proxied tool accepts run `cargo-{} -- --help`.{}",
170170
.last(true)
171171
.num_args(1..)
172172
.help("The arguments to be proxied to the tool"),
173+
// We look at .cargo/config.toml even when we don't build the binary.
174+
Arg::new("manifest-path")
175+
.long("manifest-path")
176+
.help("Path to Cargo.tom")
173177
])
174178
.after_help(after_help);
175179

@@ -223,9 +227,6 @@ To see all the flags the proxied tool accepts run `cargo-{} -- --help`.{}",
223227
.long("profile")
224228
.value_name("PROFILE-NAME")
225229
.help("Build artifacts with the specified profile"),
226-
Arg::new("manifest-path")
227-
.long("manifest-path")
228-
.help("Path to Cargo.tom"),
229230
Arg::new("features")
230231
.long("features")
231232
.short('F')
@@ -280,16 +281,18 @@ To see all the flags the proxied tool accepts run `cargo-{} -- --help`.{}",
280281

281282
pub fn run(tool: Tool, matches: ArgMatches) -> Result<i32> {
282283
let mut metadata_command = MetadataCommand::new();
283-
if let Some(features) = matches.get_many::<String>("features") {
284-
metadata_command.features(CargoOpt::SomeFeatures(
285-
features.map(|s| s.to_owned()).collect(),
286-
));
287-
}
288-
if matches.get_flag("no-default-features") {
289-
metadata_command.features(CargoOpt::NoDefaultFeatures);
290-
}
291-
if matches.get_flag("all-features") {
292-
metadata_command.features(CargoOpt::AllFeatures);
284+
if tool.needs_build() {
285+
if let Some(features) = matches.get_many::<String>("features") {
286+
metadata_command.features(CargoOpt::SomeFeatures(
287+
features.map(|s| s.to_owned()).collect(),
288+
));
289+
}
290+
if matches.get_flag("no-default-features") {
291+
metadata_command.features(CargoOpt::NoDefaultFeatures);
292+
}
293+
if matches.get_flag("all-features") {
294+
metadata_command.features(CargoOpt::AllFeatures);
295+
}
293296
}
294297
if let Some(path) = matches.get_one::<String>("manifest-path") {
295298
metadata_command.manifest_path(path);

0 commit comments

Comments
 (0)