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

Support --test/--bin/--lib in cargo-miri #1525

Merged
merged 3 commits into from
Aug 28, 2020

Conversation

divergentdave
Copy link
Contributor

This PR addresses a FIXME in cargo-miri, and filters the targets to be checked when any of the --bin, '--test, or --lib` flags are passed.

match arg {
arg if arg == "--" => break,
arg if arg == "--lib" => lib_present = true,
arg if arg == "--bin" => {
Copy link
Member

Choose a reason for hiding this comment

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

This looks like it supports --bin name but not --bin=name.

@@ -430,10 +496,7 @@ fn in_cargo_miri() {
_ => continue,
}
// Forward user-defined `cargo` args until first `--`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Forward user-defined `cargo` args until first `--`.
// Forward further `cargo` args.

let mut additional_args = Vec::new();
while let Some(arg) = args.next() {
match arg {
arg if arg == "--" => break,
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment saying that this is where the Miri arguments start.

@RalfJung
Copy link
Member

RalfJung commented Aug 26, 2020

Thanks a lot! This looks much cleaner than I thought was possible. ;)

However, this now applies to both cargo miri run and cargo miri test. Does that make sense? cargo run does not have --lib or --test, so maybe it would make more sense to exclude those. Also I think cargo run only allow --bin to be specified once.

On the other hand, I hope to get around to resolving #739 within the next two weeks. So it does not seem worth the effort to spend a lot of time re-implementing cargo's logic here, if we are able to just reuse the existing logic. So in that sense I am fine landing this with the existing logic, but please add a FIXME.

// Now we run `cargo check $FLAGS $ARGS`, giving the user the
// change to add additional arguments. `FLAGS` is set to identify
// this target. The user gets to control what gets actually passed to Miri.
let mut cmd = cargo();
cmd.arg("check");
match (subcommand, kind.as_str()) {
(MiriCommand::Run, "bin") => {
// FIXME: we just run all the binaries here.
Copy link
Member

Choose a reason for hiding this comment

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

The first line here is still true -- cargo miri run runs all binaries when there are several, where cargo run picks default-run or errors of that key is not specified in Cargo.toml. So please don't fully remove this FIXME.

@divergentdave
Copy link
Contributor Author

OK, made those changes. Reusing cargo's logic sounds great.

show_error(format!("\"--bin\" takes one argument."));
}
}
arg if arg.starts_with("--bin=") => bin_targets.push((&arg[6..]).to_string()),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
arg if arg.starts_with("--bin=") => bin_targets.push((&arg[6..]).to_string()),
arg if arg.starts_with("--bin=") => bin_targets.push((&arg["--bin".len()..]).to_string()),

Let's avoid magic constants. Same goes for --test.

@RalfJung
Copy link
Member

Thanks, this is great! Let's land this. @bors r+

It would also be good to have some testcases (cargo-miri is being tested by test-cargo-miri/run-test.py). I'll certainly add some when I try to adjust this to reuse the cargo logic, but if you want to help then already having some tests for the part that is covered by this PR would be great. :)

@bors
Copy link
Contributor

bors commented Aug 28, 2020

📌 Commit 64e2d3e has been approved by RalfJung

@bors
Copy link
Contributor

bors commented Aug 28, 2020

⌛ Testing commit 64e2d3e with merge c2a2e25...

@bors
Copy link
Contributor

bors commented Aug 28, 2020

☀️ Test successful - checks-travis, status-appveyor
Approved by: RalfJung
Pushing c2a2e25 to master...

@bors bors merged commit c2a2e25 into rust-lang:master Aug 28, 2020
bors added a commit that referenced this pull request Aug 29, 2020
Test cargo miri target selection

This is a followup to #1525, adding a few test invocations with targets specified in the cargo arguments.
@divergentdave divergentdave deleted the cargo-miri-targets branch October 26, 2020 21:47
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.

3 participants