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

initial working version of cargo fix --clippy #7069

Merged
merged 22 commits into from
Jul 19, 2019
Merged

Conversation

yaahc
Copy link
Member

@yaahc yaahc commented Jun 24, 2019

closes #7006

@rust-highfive
Copy link

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 24, 2019
src/cargo/ops/fix.rs Outdated Show resolved Hide resolved
@yaahc
Copy link
Member Author

yaahc commented Jun 25, 2019

The argument pass-through logic doesn't currently work and I dont know why. When I make it output the command that it is running before shelling out to clippy-driver it has the arguments that I added. And if I copy paste that command and run it manually the arg works and it suppresses the warning I was trying to allow. But when it runs via cargo fix it still outputs the warning.

I initially assumed it was something clippy was doing to force allowed lints to output, but trying to pass --help through to clippy-driver likewise fails to do anything.

@yaahc
Copy link
Member Author

yaahc commented Jun 25, 2019

Actually I think it is doing stuff, just very silently. When I put poorly formatted arguments into the passthrough list it silently fails and doesnt apply any changes, and instead warns on everything. My guess is that there is a final step after applying all fixes where it doesn't capture json output and instead just lets it output the remaining warnings to the user, and that the args im passing through aren't being applied to that step.

@yaahc
Copy link
Member Author

yaahc commented Jun 25, 2019

It seems to be outputting leftover lints at least twice, possibly equal to the number of times it is invoked.

@yaahc
Copy link
Member Author

yaahc commented Jun 25, 2019

@ehuss RE: Metadata fingerprint concerns

The metadata already includes a hash of Rustc::verbose_version which resolves to something like

master ✗ $ clippy-driver -vV
rustc 1.35.0 (3c235d560 2019-05-20)
binary: rustc
commit-hash: 3c235d5600393dfe6c36eeed34042efad8d4f26e
commit-date: 2019-05-20
host: x86_64-unknown-linux-gnu
release: 1.35.0
LLVM version: 8.0
master ✗ $ rustc -vV
rustc 1.35.0 (3c235d560 2019-05-20)
binary: rustc
commit-hash: 3c235d5600393dfe6c36eeed34042efad8d4f26e
commit-date: 2019-05-20
host: x86_64-unknown-linux-gnu
release: 1.35.0
LLVM version: 8.0

Is it fair to say this should be sufficient for our needs and that I don't need to add the path and timestamp of the rustc binary to the metadata hash?

If this is sufficient then I think the only thing I need to do is write tests and make sure it passes CI and then get it through review. Woooo!

yaahc added 2 commits June 24, 2019 20:58
the clippy args passthrough only allows one arg per instance of the flag
and does not resplit on spaces, as such it should be more obvious to the
user that you need to specify the flag once per clippy argument.
src/cargo/ops/fix.rs Outdated Show resolved Hide resolved
src/bin/cargo/commands/fix.rs Outdated Show resolved Hide resolved
@yaahc
Copy link
Member Author

yaahc commented Jun 25, 2019

Seems like all that's left is resolution on the fingerprint requirement and the clippy-driver error handling requirement and if any changes are needed along with final code review and approval.

Lets hope the current version passes CI :)

tests/testsuite/clippy.rs Outdated Show resolved Hide resolved
yaahc added 2 commits June 25, 2019 14:44
This is only a warning because rustup(?) already warns and is much more
verbose about how to recover from the error, so I would like to call
into the clippy-driver shim or w/e is outputting nice error messages.

But incase rustup is not available or some other shenanigans occur,
cargo will also output the warning so the error isn't a mystery.
src/bin/cargo/commands/fix.rs Outdated Show resolved Hide resolved
src/bin/cargo/commands/fix.rs Outdated Show resolved Hide resolved
src/cargo/ops/fix.rs Show resolved Hide resolved
src/cargo/ops/fix.rs Outdated Show resolved Hide resolved
src/cargo/util/config.rs Outdated Show resolved Hide resolved
src/cargo/util/config.rs Outdated Show resolved Hide resolved
tests/testsuite/clippy.rs Outdated Show resolved Hide resolved
tests/testsuite/clippy.rs Outdated Show resolved Hide resolved
tests/testsuite/clippy.rs Outdated Show resolved Hide resolved
src/cargo/ops/fix.rs Outdated Show resolved Hide resolved
src/bin/cargo/commands/fix.rs Outdated Show resolved Hide resolved
@ehuss
Copy link
Contributor

ehuss commented Jun 30, 2019

Sorry for the delay in response. I've been a bit busy lately, and I'll be gone most of this week. I'll try to check in later, just beware if it takes me a while to respond.

@yaahc
Copy link
Member Author

yaahc commented Jul 18, 2019

rustc_wrapper and primary_unit_rustc are doing different things though. In the context of a Rustc object rustc_wrapper is an override for its wrapper member and primary_unit_rustc is an override for its path member.

Clippy could use primary_unit_rustc instead of wrapper because it just discards the first arg if its rustc but rustfix relies on rustc_wrapper to invoke the cargo subprocess. All the work I did was to get the invocation of the subprocess to change from cargo rustc ... for primary crates to cargo clippy-driver ....

@ehuss
Copy link
Contributor

ehuss commented Jul 18, 2019

rustc_wrapper and primary_unit_rustc are doing different things though.

Yea, but I don't think it is necessary.

rustfix relies on rustc_wrapper to invoke the cargo subprocess

If primary_unit_rustc is changed to a ProcessBuilder, then fix should be fine. That is, fix would have:

opts.compile_opts.build_config.primary_unit_rustc = Some(wrapper);

This means the dependencies will be built like in a normal build. That's all that is necessary for fix. The "cargo as a wrapper" only needs to happen for primary units.

Making fix work with clippy then becomes a relatively simple change of something like:

    let rustc = if env::var(CLIPPY_FIX_ARGS).is_ok() {
        util::config::clippy_driver()
    } else {
        args.rustc.as_ref().expect("fix wrapper rustc was not set").clone()
    };

instead of encoding clippy-driver into the wrapper.

@yaahc
Copy link
Member Author

yaahc commented Jul 18, 2019

So for non primary crates we never go into the subprocess cargo and rely on the fall through path? Didn't know that was allowed and in that context everything you've been saying makes way more sense.

@ehuss
Copy link
Contributor

ehuss commented Jul 18, 2019

So for non primary crates we never go into the subprocess cargo and rely on the fall through path?

Yes. I believe the current design is just an artifact of how it evolved (using the existing wrapper machinery).

@yaahc
Copy link
Member Author

yaahc commented Jul 18, 2019

Ok I think I did everything correctly but now its failing, my quick checking didnt show anything obviously wrong.

    fix::do_not_fix_non_relevant_deps
    fix::only_warn_for_relevant_crates

I'll try digging into the behavior and tracing where everything is going tonight.

@ehuss
Copy link
Contributor

ehuss commented Jul 19, 2019

Thanks!!

@bors r+

@bors
Copy link
Contributor

bors commented Jul 19, 2019

📌 Commit 22b430d has been approved by ehuss

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 19, 2019
@bors
Copy link
Contributor

bors commented Jul 19, 2019

⌛ Testing commit 22b430d with merge 9f7bd62...

bors added a commit that referenced this pull request Jul 19, 2019
initial working version of cargo fix --clippy

closes #7006
@bors
Copy link
Contributor

bors commented Jul 19, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: ehuss
Pushing 9f7bd62 to master...

@bors bors merged commit 22b430d into rust-lang:master Jul 19, 2019
bors added a commit to rust-lang/rust that referenced this pull request Jul 26, 2019
Update cargo

11 commits in e3563dbdcd2e370bc4f11d080f739d82d25773fd..d0f828419d6ce6be21a90866964f58eb2c07cd56
2019-07-16 19:22:44 +0000 to 2019-07-23 21:58:59 +0000
- Remove include/exclude glob warning. (rust-lang/cargo#7170)
- Optimize lock file format for git merge conflicts (rust-lang/cargo#7070)
- Set up CI with Azure Pipelines (rust-lang/cargo#7139)
- Force clippy to run. (rust-lang/cargo#7157)
- Work around #61440 (rust-lang/cargo#7158)
- initial working version of cargo fix --clippy (rust-lang/cargo#7069)
- Optimize runtime of `#[cargo_test_macro]` (rust-lang/cargo#7146)
- Don't fail if we can't acquire readonly lock (rust-lang/cargo#7149)
- Add support for multiple --features options (rust-lang/cargo#7084)
- Fix a typo in an env var name (rust-lang/cargo#7145)
- Add a way to disable all nightly tests (rust-lang/cargo#7142)
@nhynes
Copy link

nhynes commented Aug 2, 2019

Would it be possible to add back CARGO_PRIMARY_PACKAGE in some form so that non-clippy rustc wrappers can get this useful information? I love the tooling, but imho, the rust-lang[-nursery] ones occupy a far too blessed position in the ecosystem.

@Manishearth
Copy link
Member

I think a blessed position is good, these are official tools and totally could be just maintained as a single unit if we wanted to. Creating good APIs for this requires a lot of consensus building, for an area that doesn't have many users. Y'all are free to RFC for more wrapper functionality, but here we're blocked on getting important cargo fix/cargo clippy functionality out

@nhynes
Copy link

nhynes commented Aug 2, 2019

I think a blessed position is good

Sorry if my initial frustration leaked out; I really do appreciate the few people who are making everything good. I guess I'm just being idealistic when hoping for the apis to be general and extensible :)

I'll make a PR real quick. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

call clippy-driver directly rather than as a rustc_wrapper
8 participants