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

Warn when rustc output conflicts with existing directories #47203

Merged

Conversation

varkor
Copy link
Member

@varkor varkor commented Jan 5, 2018

When the compiled executable would conflict with a directory, display a
rustc error instead of a verbose and potentially-confusing linker
error. This is a usability improvement, and doesn’t actually change
behaviour with regards to compilation success. This addresses the
concern in #35887. Fixes #13098.

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

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

@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 5, 2018
if let Some(dir_path) = outputs.conflicts_with_dir() {
sess.err(&format!(
"the generated executable for the input file \"{}\" conflicts with the \
existing directory \"{}\'",
Copy link
Member

@kennytm kennytm Jan 5, 2018

Choose a reason for hiding this comment

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

OK so why the existing directory part ends with a single quote?

Copy link
Member Author

Choose a reason for hiding this comment

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

An inadvertent stylistic experiment... Fixed.

@kennytm
Copy link
Member

kennytm commented Jan 5, 2018

The run-make/compiler-lookup-paths-2 test is still failing.

if input_path.is_none() {
return false
}
fn check_output<F, T>(&self, f: F) -> Option<T> where F: Fn(PathBuf) -> Option<T> {
Copy link
Member

@pnkfelix pnkfelix Jan 5, 2018

Choose a reason for hiding this comment

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

This code was able to limp along without a comment before since it was singly-purposed. But if you're going to generalize it with a higher-order function, you should add documentation stating what it does. (E.g. something like "Runs f on every potential output file path, returning this first for which f returns non-none, or None if f is none for all paths.")

@pnkfelix
Copy link
Member

pnkfelix commented Jan 5, 2018

As @kennytm notes, the run-make/compiler-lookup-paths-2 is failing.

From what I can tell, this is happening because your code is (reasonably?) assuming that the paths enumerated by the contains_path (aka check_output after your changes) represent the exact set of paths that we will try to write to in this compilation attempt.

However, from what I can tell, when the OutputType is OutputType::Exe, we may apply target-dependent transformations to find the actual file path. See rustc_trans_utils::link::out_filename for more details here.

@pnkfelix
Copy link
Member

pnkfelix commented Jan 5, 2018

However you decide to resolve this, it would probably be good to ensure that driver::write_out_deps and your routine share code as appropriate to enumerate the output filenames, perhaps via similar generalization as you did when you generalized contains_path to check_output. (I again ask that you add documentation when doing such generalization.)

@pnkfelix pnkfelix added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 5, 2018
@varkor
Copy link
Member Author

varkor commented Jan 7, 2018

Thanks for the pointers @pnkfelix — they were helpful in getting on the right track. I've only got a line or so of documentation for the two new functions at the moment — let me know if you think it's still too sparse! This uncovered (the same) bug in the "don't overwrite the input file" check too, so it was helpful to run into it here.

let output_paths = generated_output_paths(sess, &outputs, &crate_name);

// Ensure the source file isn't accidentally overwritten during compilation.
match *input_path {
Copy link
Member

Choose a reason for hiding this comment

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

I'd personally use if let Some(ref input_path) = *input_path { ... } here, especially since the None branch is empty.

Copy link
Member

Choose a reason for hiding this comment

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

(oh but I guess the pre-existing code that you're refactoring used match. Fine to leave it as is to ease reading the diff here, I guess.)

Copy link
Member Author

Choose a reason for hiding this comment

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

It turns out the diffing algorithm doesn't catch on anyway, so I'll change it (considering the change is currently breaking on x86_64-pc-windows-msvc).

@pnkfelix
Copy link
Member

pnkfelix commented Jan 8, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Jan 8, 2018

📌 Commit eba03fa has been approved by pnkfelix

@pnkfelix pnkfelix 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 8, 2018
@bors
Copy link
Contributor

bors commented Jan 8, 2018

⌛ Testing commit eba03fa06e2550a62135c8f4d094fa3fb1ab3724 with merge 0dd43d7a6794e3f5aeb9d4559cbea953e48ede21...

@bors
Copy link
Contributor

bors commented Jan 8, 2018

💔 Test failed - status-appveyor

@kennytm
Copy link
Member

kennytm commented Jan 8, 2018

What a rare sight.

@bors retry #42693

@bors
Copy link
Contributor

bors commented Jan 9, 2018

⌛ Testing commit eba03fa06e2550a62135c8f4d094fa3fb1ab3724 with merge 72c51266f24476d376160243aed05d1f36fae8cc...

@bors
Copy link
Contributor

bors commented Jan 9, 2018

💔 Test failed - status-appveyor

@kennytm
Copy link
Member

kennytm commented Jan 9, 2018

Likely legit error on x86_64-pc-windows-msvc. The output is empty in the new tests run-make\output-filename-conflicts-with-directory and run-make\output-filename-overwrites-input.

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 9, 2018
@varkor
Copy link
Member Author

varkor commented Jan 9, 2018

I guess generated_output_paths is not returning the actual output files on x86_64-pc-windows-msvc. It's going to be a little hard to test without access to a machine, but I'll try looking into it.

The failing run-make tests shouldn't be the issue, because run-make\output-filename-overwrites-input was passing before this change.

@kennytm kennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 17, 2018
@kennytm
Copy link
Member

kennytm commented Jan 17, 2018

Hi @varkor,

I guess generated_output_paths is not returning the actual output files on x86_64-pc-windows-msvc. It's going to be a little hard to test without access to a machine, but I'll try looking into it.

Have you checked the problem, or is it ready to be r+'ed again?

@varkor varkor force-pushed the output-filename-conflicts-with-directory branch from a23fb80 to 9a2f02d Compare January 29, 2018 12:51
@varkor
Copy link
Member Author

varkor commented Jan 29, 2018

@pnkfelix: I think the latest changes should fix the issues on Windows! Do you think you could have a quick look over?

@kennytm kennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 29, 2018
@pietroalbini
Copy link
Member

@pnkfelix and @rust-lang/compiler, ping from triage! This PR needs a review.

@estebank
Copy link
Contributor

estebank commented Feb 5, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Feb 5, 2018

📌 Commit e92bdb9 has been approved by estebank

@kennytm kennytm 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 Feb 5, 2018
@bors
Copy link
Contributor

bors commented Feb 6, 2018

⌛ Testing commit e92bdb9 with merge dd7be09...

bors added a commit that referenced this pull request Feb 6, 2018
…y, r=estebank

Warn when rustc output conflicts with existing directories

When the compiled executable would conflict with a directory, display a
rustc error instead of a verbose and potentially-confusing linker
error. This is a usability improvement, and doesn’t actually change
behaviour with regards to compilation success. This addresses the
concern in #35887. Fixes #13098.
@bors
Copy link
Contributor

bors commented Feb 6, 2018

💥 Test timed out

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 6, 2018
@kennytm
Copy link
Member

kennytm commented Feb 6, 2018

@bors retry

The macs were not scheduled to start.

@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 Feb 6, 2018
@bors
Copy link
Contributor

bors commented Feb 6, 2018

⌛ Testing commit e92bdb9 with merge ca7d839...

bors added a commit that referenced this pull request Feb 6, 2018
…y, r=estebank

Warn when rustc output conflicts with existing directories

When the compiled executable would conflict with a directory, display a
rustc error instead of a verbose and potentially-confusing linker
error. This is a usability improvement, and doesn’t actually change
behaviour with regards to compilation success. This addresses the
concern in #35887. Fixes #13098.
@bors
Copy link
Contributor

bors commented Feb 6, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: estebank
Pushing ca7d839 to master...

@bors bors merged commit e92bdb9 into rust-lang:master Feb 6, 2018
@varkor varkor deleted the output-filename-conflicts-with-directory branch February 6, 2018 12:43
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.

9 participants