Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --manifest-path and --features #2085

Merged
merged 8 commits into from
Jan 12, 2023

Conversation

tedinski
Copy link
Contributor

@tedinski tedinski commented Jan 6, 2023

Description of changes:

  1. Add the two flags, resolving the feature requests below.
  2. Clap's parse_from calls exit on failure, so fix all tests to use try_parse_from().unwrap() (to panic instead of exit), otherwise the test suite runner can't handle failure properly.
  3. Use clap's derive more precisely: not everything is a Parser, some are just Subcommand or Args
  4. Refactor the cargo args together into a separate structure
  5. The test for --manifest-path requires more scripty tests. Compiletest mode for executing arbitrary commands #2059 continues to be a need :(

Resolved issues:

Resolves #1420
Resolves #1979

Call-outs:

Testing:

  • How is this change tested?

  • Is this a refactor change?

Checklist

  • Each commit message has a non-empty body, explaining why the change was made
  • Methods or procedures are documented
  • Regression or unit tests are included, or existing tests cover the modified code
  • My PR is restricted to a single feature or bugfix

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@tedinski tedinski requested a review from a team as a code owner January 6, 2023 00:12
Copy link
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the issue with the manifest flags.

@@ -273,6 +266,51 @@ impl KaniArgs {
}
}

/// Arguments that Kani pass down into Cargo essentially uninterpreted.
/// These generally have to do with selection of packages or activation of features.
/// These do not (currently) include cargo args that kani pays special attention to:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe say "these should not include"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it? I wasn't sure. I didn't want to make too strong of a statement if we decide otherwise later except someone sees this comment and wonders "well, why not?"...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think if we decide the other way around, we can always update the comments. I don't think writing it here is a one-way door. But I do think that this leaves space for inconsistency.
  2. I do think it would be odd to have a cargo argument being called as part of standalone kani flow. If we want to move stuff here, I would expect a counter part StandaloneArgs that basically duplicate the things that are relevant to both.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you misunderstood the comment? It's not about kani vs cargo-kani, it's about cargo args that kani is interpreting (hence the examples like --target-dir) versus those that we just kinda pass down.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I literally just said "kani is interpreting" again, which was maybe the confusion (between kani-the-project, and kani-the-binary)

"It's about cargo args that we are interpreting... versus those that we just pass down"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually wondering if this should be part of CargoKaniArgs instead of KaniArgs? None of these flags make sense in the standalone version, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, but this PR doesn't change that yet. There's more extensive work needed (e.g. in how arguments get plumbed through the session) to do that.

/// Do not activate the `default` feature
#[arg(long)]
pub no_default_features: bool,
// This tolerates spaces too, but we say "comma" only because this is the least error-prone approach...
Copy link
Contributor

@celinval celinval Jan 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that supports multiple delimiters?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why do you want to support multiple delimeters? Don't we want to only support comma or multiple usage of the same argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, cargo says it does?

cargo build --help
...
-F, --features <FEATURES>       Space or comma separated list of features to activate

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. You want to keep the same format as cargo. We should probably document the exact behavior in this case. Maybe say that comma is preferred.

Note that clap mentions that we shouldn't really be accepting options with multiple arguments and positional arguments:

A common mistake is to define an option which allows multiple values and a positional argument.

from: https://docs.rs/clap/4.0.32/clap/builder/struct.Arg.html#examples-20

I was wondering if explicitly setting the separator to ',' would fix this issue, but clap seems to just join all the space separated arguments into one. 🤦‍♀️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe say that comma is preferred

I already set our help text to just say comma, since I thought spaces was an odd choice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, if you want to match the cargo behavior, I believe you should set the action to append.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?? There's a test below showing it behaving how I expect?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. From reading the docs I thought that Set was the default

@@ -66,9 +60,20 @@ impl KaniSession {
let rustc_args = self.kani_rustc_flags();

let mut cargo_args: Vec<OsString> = vec!["rustc".into()];
if self.args.all_features {
if let Some(path) = &self.args.cargo.manifest_path {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance this can be auto generated? So we don't need to change two files whenever we just want to pass down the arguments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see any way to reverse the parsed args back into a vector, if that's what you mean. (I agree it'd be nice.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think at least creating a method that converts them might be nice. Not a blocker though.


let harness_none = mock_proof_harness("check_one", None, None);
let harness_some = mock_proof_harness("check_one", Some(3), None);

fn resolve(args: &[&str], harness: &HarnessMetadata) -> Option<u32> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but I was wondering if we could stop calling the parser as part of these unit tests.

Copy link
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My other comments are nice to have, not blockers.

@tedinski tedinski merged commit 29dd214 into model-checking:main Jan 12, 2023
@tedinski tedinski deleted the manifest-features branch January 12, 2023 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can cargo kani support --features option? Better Behavior for cargo kani: workspaces and --manifest-path
2 participants