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

Fix freshness when linking is interrupted. #8078

Closed
wants to merge 1 commit into from

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Apr 7, 2020

Cargo was incorrectly determining a build is fresh in the following scenario.

  1. cargo build
  2. Modify source file.
  3. cargo build.
  4. Hit ctrl-c while the linker is running.
  5. cargo run — Cargo will think it is "fresh" because the output file exists, but will attempt to run a corrupt file.

The solution here is to delete the fingerprint when something is determined to be dirty. There are a variety of other possible approaches, but this seemed the simplest.

I was only able to reproduce this with gcc on Linux.

I couldn't think of a good way to write a test for this. I did test this a bit locally, by using the repro steps above. I also did some tests with a custom linker that wrote out an empty file and then went to sleep so I could kill Cargo. I was reluctant to include a test using that technique because it needs to parse the linker command-line flags to find the output filename, and I'm not sure how stable/reliable that would be with different platforms and linker flavors. It is also a bit cumbersome to signal when linking has started.

Fixes #7767

@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 Apr 7, 2020
@alexcrichton
Copy link
Member

Nice find! This is definitely a good fix to have.

I do think it'd be good if we could get a test for this though since it seems very easy to accidentally leave out in a refactoring. For signaling when the linker started I think a TCP server should work (the test waits for a connection and the linker hangs after making a connection). For identifying the output filename I think we could get something semi-robust by basically looking at all arguments that look like they're paths starting with the target directory, and make sure that all of those exist as files or directories?

@ehuss
Copy link
Contributor Author

ehuss commented Apr 7, 2020

I'm glad you said something. The technique I was using to repro this wasn't valid (I was deleting the outputs instead of changing the mtime of the inputs). It'll need some more investigation to figure out the original issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Killing cargo test midway can leave target in unstable stage
3 participants