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

Always rebuild targets when using cargo-fix #5750

Closed

Conversation

killercup
Copy link
Member

Assume you run cargo fix and only get warnings that cannot be fixed.
Then, without changing the code, you run cargo fix again. The compiler
will see that no files have changed and output… nothing. This is very
confusing to the end user.

To mitigate this, we now touch the entry point files to trick
rustc/cargo into emitting the same warnings again.

This is a fix but a very "WIP" one for #5736

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

ws: &Workspace<'a>,
options: &CompileOptions<'a>,
) -> CargoResult<()> {
// Begin cargo cult from `ops::cargo_compile::compile_ws`
Copy link
Member Author

Choose a reason for hiding this comment

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

I've only pasted this code here because I couldn't find a quick way to get the compilation target entry-point files. I'd very happily change this :)

@matklad
Copy link
Member

matklad commented Jul 20, 2018

We do something similar for --build-plan which also needs to compile everything regardless of freshness: https://github.com/rust-lang/cargo/pull/5301/files#diff-36216dee2e5190f6c670787ea469e00aR97

Perhaps we can add a force_rebuild: bool flag to cover both of these use-cases

@Eh2406
Copy link
Contributor

Eh2406 commented Jul 20, 2018

I just noted that cargo clippy has the same problematic behavior.

@alexcrichton
Copy link
Member

Thanks for the PR @killercup! I agree though with @matklad that we probably want to avoid this duplication and plumb a boolean to the backend which forces rebuild and forces busting the cache. Would that be possible to implement?

Could you also add a test where there's a few top-level targets like an integration and a binary as well as a library?

@killercup
Copy link
Member Author

killercup commented Jul 21, 2018 via email

Assume you run `cargo fix` and only get warnings that cannot be fixed.
Then, without changing the code, you run `cargo fix` again. The compiler
will see that no files have changed and output… nothing. This is very
confusing to the end user.

To mitigate this, we now `touch` the entry point files to trick
rustc/cargo into emitting the same warnings again.

This is a fix but a very "WIP" one for rust-lang#5736
Sadly, this doesn't seem to work right now
@killercup killercup force-pushed the rustfix-likes-to-touch-files branch from 5dc17de to 1eacc05 Compare July 24, 2018 12:40
@@ -133,7 +135,7 @@ fn compile<'a, 'cfg: 'a>(
let dirty = work.then(link_targets(cx, unit, false)?).then(dirty);
let fresh = link_targets(cx, unit, true)?.then(fresh);

if exec.force_rebuild(unit) {
if exec.force_rebuild(unit) || force_rebuild {
Copy link
Member Author

Choose a reason for hiding this comment

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

@matklad I've not added a force_rebuild field to the BuildConfig struct, and from what I can tell this should be the right place to use it. Indeed, when I add a debug!("rebuilding {:?} (force? {:?})", unit, force_rebuild); here, my new test case triggers it and shows the correct data. But I don't get any diagnostics output! Do I… need to go deeper?

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 it's working. I think the issue is that the second call to cargo fix won't display "fixing" because the files have already been fixed in the first call.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh, damn, I copied the wrong example! Thank you!

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Thanks! I think though that the force_rebuild option here may be a bit too aggressive though? It forces a rebuild of the entire crate graph I think, right? Could this perhaps only be limited to a few packages selected by -p on the command line?

Turns out that using test cases that we can actually fix was not a good
way to test that warnings continue to show up cross runs.
@alexcrichton
Copy link
Member

ping @killercup, have you had a chance to take another look at this?

@killercup
Copy link
Member Author

killercup commented Jul 31, 2018 via email

@killercup killercup changed the title Touch entry-point files before running cargo-fix Always rebuild targets when using cargo-fix Jul 31, 2018
@alexcrichton
Copy link
Member

I'm gonna close this for now to help clear out the queue, but always up for merging a rebase :)

bors added a commit that referenced this pull request Aug 31, 2018
Force `cargo fix` to rebuild

Fixes #5736

This is a resubmit of @killercup's #5750, rebased on current master.

@alexcrichton From browsing the code I feel like `-p` would still restrict the packages to rebuild, despite the rebuild flag added. But I might be misreading or not-fully-reading the code. Could you give me some mentoring instructions for the test cases you're concerned with?
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.

6 participants