-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Adding display of which target failed to compile #11636
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ehuss (or someone else) soon. Please see the contribution instructions for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pull request!
What do you think of following what #10834 (comment) told? That is "doing what a warning already does".
Besides, here is a guide for writing tests for cargo. Adding tests to verify the change is beneficial for reviewers to look into the change, making it more likely to get merged.
Edit: The Cargo project prefers a descriptive title for the pull request. That makes it easier when scrolling back to search a PR in the haystack.
r? @weihanglo |
Can you edit the title of the PR to say what it does instead of referencing an issue number? Perhaps something like "Display which target failed to compile", or something similarly descriptive. That can make it easier to understand what the PR does without needing to reference something else. |
Thanks for replying @weihanglo, sorry but i'm new to Rust & OS world 😅 I've doubts about the first sentence. I think i just included what the comment said, adding the "(unit.target.description_named)" to the display output, so the message would output:
What am i missing here? 🥲 I'm also checking the testing guide you pointed out, in this case, i've seen other tests that would get invalidated by this PR, for example here . Should i also update those tests? |
Nothing wrong with your current fix. I am just suggesting the already existing approarch. It is effectively your solution plus more compile mode information. It would be great to have a consistent style between warning and error messages. cargo/src/cargo/core/compiler/job_queue.rs Lines 1265 to 1273 in ca0557a
Ahh! They are the missing pieces in the contributing guide. We should include the expectation of a pull request in it. And yeah, a pull is supposed to pass all test suites before merge. That is to say, if your fix affects some other error messages beyond your expectation, you should figure out why it has changed. Then decide to either fix them or fix your patch. |
This reverts commit 09f3293.
Ping @aortizpimentel. Just checking in to see if you are still interested in working on this. Let us know if you had any questions. |
Hi @weihanglo, let me try to resume this, problably this saturday morning. The problem i've encountered so far was the "overwhelming" failed tests that i've got. I think the problem was the previous message hardcoded on several tests if i can remember well. |
That was intentionally hardcoded. Today we could write tests in UI test flavour, so that we don't get the pain of updating assertion strings — they will be done automatically. However, we haven't yet managed to migrate tests from the old style, and some of them should not be migrated. Contributor experience is also a part we want to improve, so if you got some please share thoughts with us. |
With current build, there's still 86 tests to review & fix 😅
|
Can you figure out why it failed on so many tests? It didn't look like that many in Cargo CI pipeline (only 8 failures), and only 11 failures on my machine with commit d1309e3. You could leave error messages here or ping me on Zuilp if that make you feel more comfortable :) BTW, before fixing assertions, is it possible to extract this piece of code and reuse it for both warnings and errors? That will make messages more consistent. Thank you! cargo/src/cargo/core/compiler/job_queue/mod.rs Lines 1003 to 1010 in aaf08a0
|
This is weird, i've run into this issue #6943. But there's nothing running, as i've tried to restart also. Deleting/Moving each conflict is manual + time consuming and deleting all target folder takes so much also (but auto) |
Hi @weihanglo, it's ok now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for extracting function for reuse. That looks pretty in general! I left some minor style suggestions.
Also, before this gets merged, could you
- Assert each error message verbatim if possible. Don't use
[..]
to omit them. - Clean up commit history. You don't need to squash all into one.
I personally follow the creed of “atomic commits” and cleanup intermediate commits generated during development, such as “run rustfmt” or “revert X”. Those commits make little sense to others in collaboration.
tests/testsuite/build.rs
Outdated
@@ -639,7 +639,7 @@ fn cargo_compile_with_invalid_code() { | |||
|
|||
p.cargo("build") | |||
.with_status(101) | |||
.with_stderr_contains("[ERROR] could not compile `foo` due to previous error\n") | |||
.with_stderr_contains("[ERROR] could not compile `foo` [..] due to previous error\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like it shouldn't be omitted. Could you assert the actual error message? And other tests as well. Thanks!
.with_stderr_contains("[ERROR] could not compile `foo` [..] due to previous error\n") | |
.with_stderr_contains("[ERROR] could not compile `foo` (bin "foo") due to previous error\n") |
src/cargo/core/compiler/mod.rs
Outdated
/// Provides a common compilation errors/warnings base message | ||
fn compile_error_msg( | ||
msg_prefix: Option<&str>, | ||
name: &str, | ||
target: &Target, | ||
mode: &CompileMode, | ||
) -> String { | ||
let mut message: String = "".to_string(); | ||
|
||
match msg_prefix { | ||
None => {} | ||
Some(m) => message.push_str(m), | ||
} | ||
message.push_str(&format!("`{}` ({}", name, target.description_named())); | ||
if mode.is_rustc_test() && !(target.is_test() || target.is_bench()) { | ||
message.push_str(" test"); | ||
} else if mode.is_doc_test() { | ||
message.push_str(" doctest"); | ||
} else if mode.is_doc() { | ||
message.push_str(" doc"); | ||
} | ||
message.push_str(") generated "); | ||
message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- To make the purpose of this
fn
clearer, we can scope it to provide a descriptive package name. That also reduce one function argument. - The current message looks like
which
could not compile `foo` (bin "foo") generated due to previous error
generated
is weird being there, and an extra space appears. I think it should be- could not compile `foo` (bin "foo") generated due to previous error + could not compile `foo` (bin "foo") due to previous error
How about change it to this one?
/// Provides a common compilation errors/warnings base message | |
fn compile_error_msg( | |
msg_prefix: Option<&str>, | |
name: &str, | |
target: &Target, | |
mode: &CompileMode, | |
) -> String { | |
let mut message: String = "".to_string(); | |
match msg_prefix { | |
None => {} | |
Some(m) => message.push_str(m), | |
} | |
message.push_str(&format!("`{}` ({}", name, target.description_named())); | |
if mode.is_rustc_test() && !(target.is_test() || target.is_bench()) { | |
message.push_str(" test"); | |
} else if mode.is_doc_test() { | |
message.push_str(" doctest"); | |
} else if mode.is_doc() { | |
message.push_str(" doc"); | |
} | |
message.push_str(") generated "); | |
message | |
/// Provides a package name with descriptive target information, | |
/// e.g., `` `foo` (bin "bar" test) ``, `` `foo` (lib doctest) ``. | |
fn descriptive_pkg_name(name: &str, target: &Target, mode: &CompileMode) -> String { | |
let desc_name = target.description_named(); | |
let mode = if mode.is_rustc_test() && !(target.is_test() || target.is_bench()) { | |
" test" | |
} else if mode.is_doc_test() { | |
" doctest" | |
} else if mode.is_doc() { | |
" doc" | |
} else { | |
"" | |
}; | |
format!("`{name}` ({desc_name}{mode})") | |
} | |
src/cargo/core/compiler/mod.rs
Outdated
let mut message = | ||
compile_error_msg(Some("could not compile "), &name, &target, &mode); | ||
message.push_str(&errors); | ||
message.push_str(&warnings); | ||
message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do this if using the suggested descriptive_pkg_name
function.
let mut message = | |
compile_error_msg(Some("could not compile "), &name, &target, &mode); | |
message.push_str(&errors); | |
message.push_str(&warnings); | |
message | |
let name = descriptive_pkg_name(&name, &target, &mode); | |
format!("could not compile {name}{errors}{warnings}") |
message.push_str(" doc"); | ||
} | ||
message.push_str(") generated "); | ||
let mut message = compile_error_msg(None, &unit.pkg.name(), &unit.target, &unit.mode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do this if using the suggested descriptive_pkg_name
function.
let mut message = compile_error_msg(None, &unit.pkg.name(), &unit.target, &unit.mode); | |
let mut message = descriptive_pkg_name(&unit.pkg.name(), &unit.target, &unit.mode); | |
message.push_str(" generated "); |
They're failing by "os error 3" (windows paths problem maybe?) but there's also something weird apening, this test was run OK and a few seconds later re-executed (no changes) and it's failing by permissionDenied:
cargo clean is also failing:
|
Interesting! On Windows then it is probably related to #11442. |
- Adding display of which target failed to compile - Consistent messages for warnings/errors. - Fixing assertions on related tests.
bbf6143
to
db457d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are finally here. Looks awesome! Thank you for the contribution :)
@bors r+ |
☀️ Test successful - checks-actions |
23 commits in 9880b408a3af50c08fab3dbf4aa2a972df71e951..c1334b059c6dcceab3c10c81413f79bb832c8d9d 2023-02-28 19:39:39 +0000 to 2023-03-07 19:21:50 +0000 - Add `CARGO_PKG_README` (rust-lang/cargo#11645) - path dependency: fix cargo-util version (rust-lang/cargo#11807) - Adding display of which target failed to compile (rust-lang/cargo#11636) - Fix `CARGO_CFG_` vars for configs defined both with and without value (rust-lang/cargo#11790) - Breaking endless loop on cyclic features in added dependency in cargo-add (rust-lang/cargo#11805) - Enhance the doc of timing report with graphs (rust-lang/cargo#11798) - Make `sparse` the default protocol for crates.io (rust-lang/cargo#11791) - Use sha2 to calculate SHA256 (rust-lang/cargo#11795) - gitoxide progress bar fixes (rust-lang/cargo#11800) - Check publish_to_alt_registry publish content (rust-lang/cargo#11799) - chore: fix missing files in autolabel trigger_files (rust-lang/cargo#11797) - chore: Update base64 (rust-lang/cargo#11796) - Fix some doc typos (rust-lang/cargo#11794) - chore(ci): Enforce cargo-deny in CI (rust-lang/cargo#11761) - Some cleanup for unstable docs (rust-lang/cargo#11793) - gitoxide integration: fetch (rust-lang/cargo#11448) - patch can conflict on not activated packages (rust-lang/cargo#11770) - fix(toml): Provide a way to show unused manifest keys for dependencies (rust-lang/cargo#11630) - Improve error for missing crate in --offline mode for sparse index (rust-lang/cargo#11783) - feat(resolver): `-Zdirect-minimal-versions` (rust-lang/cargo#11688) - feat: Use test name for dir when running tests (rust-lang/cargo#11738) - Jobserver cleanup (rust-lang/cargo#11764) - Fix help string for "--charset" option of "cargo tree" (rust-lang/cargo#11785) Note that some 3rd-party licensing allowed list changed due to the introducion of `gix` dependency
Update cargo 25 commits in 9880b408a3af50c08fab3dbf4aa2a972df71e951..7d3033d2e59383fd76193daf9423c3d141972a7d 2023-02-28 19:39:39 +0000 to 2023-03-08 17:05:08 +0000 - Revert "rust-lang/cargo#11738" - Use test name for dir when running tests (rust-lang/cargo#11812) - Update CHANGELOG for 1.68 backports (rust-lang/cargo#11810) - Add `CARGO_PKG_README` (rust-lang/cargo#11645) - path dependency: fix cargo-util version (rust-lang/cargo#11807) - Adding display of which target failed to compile (rust-lang/cargo#11636) - Fix `CARGO_CFG_` vars for configs defined both with and without value (rust-lang/cargo#11790) - Breaking endless loop on cyclic features in added dependency in cargo-add (rust-lang/cargo#11805) - Enhance the doc of timing report with graphs (rust-lang/cargo#11798) - Make `sparse` the default protocol for crates.io (rust-lang/cargo#11791) - Use sha2 to calculate SHA256 (rust-lang/cargo#11795) - gitoxide progress bar fixes (rust-lang/cargo#11800) - Check publish_to_alt_registry publish content (rust-lang/cargo#11799) - chore: fix missing files in autolabel trigger_files (rust-lang/cargo#11797) - chore: Update base64 (rust-lang/cargo#11796) - Fix some doc typos (rust-lang/cargo#11794) - chore(ci): Enforce cargo-deny in CI (rust-lang/cargo#11761) - Some cleanup for unstable docs (rust-lang/cargo#11793) - gitoxide integration: fetch (rust-lang/cargo#11448) - patch can conflict on not activated packages (rust-lang/cargo#11770) - fix(toml): Provide a way to show unused manifest keys for dependencies (rust-lang/cargo#11630) - Improve error for missing crate in --offline mode for sparse index (rust-lang/cargo#11783) - feat(resolver): `-Zdirect-minimal-versions` (rust-lang/cargo#11688) - feat: Use test name for dir when running tests (rust-lang/cargo#11738) - Jobserver cleanup (rust-lang/cargo#11764) - Fix help string for "--charset" option of "cargo tree" (rust-lang/cargo#11785) --- ~~This update is primarily for making rust-lang/cargo#11630 into 1.69~~ (will file a beta backport then). However, just look into the licenses and dependencies permitted list, it looks a bit unfortunate but inevitable I guess? r? `@ehuss` cc `@Muscraft`
Update cargo 25 commits in 9880b408a3af50c08fab3dbf4aa2a972df71e951..7d3033d2e59383fd76193daf9423c3d141972a7d 2023-02-28 19:39:39 +0000 to 2023-03-08 17:05:08 +0000 - Revert "rust-lang/cargo#11738" - Use test name for dir when running tests (rust-lang/cargo#11812) - Update CHANGELOG for 1.68 backports (rust-lang/cargo#11810) - Add `CARGO_PKG_README` (rust-lang/cargo#11645) - path dependency: fix cargo-util version (rust-lang/cargo#11807) - Adding display of which target failed to compile (rust-lang/cargo#11636) - Fix `CARGO_CFG_` vars for configs defined both with and without value (rust-lang/cargo#11790) - Breaking endless loop on cyclic features in added dependency in cargo-add (rust-lang/cargo#11805) - Enhance the doc of timing report with graphs (rust-lang/cargo#11798) - Make `sparse` the default protocol for crates.io (rust-lang/cargo#11791) - Use sha2 to calculate SHA256 (rust-lang/cargo#11795) - gitoxide progress bar fixes (rust-lang/cargo#11800) - Check publish_to_alt_registry publish content (rust-lang/cargo#11799) - chore: fix missing files in autolabel trigger_files (rust-lang/cargo#11797) - chore: Update base64 (rust-lang/cargo#11796) - Fix some doc typos (rust-lang/cargo#11794) - chore(ci): Enforce cargo-deny in CI (rust-lang/cargo#11761) - Some cleanup for unstable docs (rust-lang/cargo#11793) - gitoxide integration: fetch (rust-lang/cargo#11448) - patch can conflict on not activated packages (rust-lang/cargo#11770) - fix(toml): Provide a way to show unused manifest keys for dependencies (rust-lang/cargo#11630) - Improve error for missing crate in --offline mode for sparse index (rust-lang/cargo#11783) - feat(resolver): `-Zdirect-minimal-versions` (rust-lang/cargo#11688) - feat: Use test name for dir when running tests (rust-lang/cargo#11738) - Jobserver cleanup (rust-lang/cargo#11764) - Fix help string for "--charset" option of "cargo tree" (rust-lang/cargo#11785) --- ~~This update is primarily for making rust-lang/cargo#11630 into 1.69~~ (will file a beta backport then). However, just look into the licenses and dependencies permitted list, it looks a bit unfortunate but inevitable I guess? r? `@ehuss` cc `@Muscraft`
Closes #10834
Attached example.zip is the same as the one mentioned on the issue. You could use it to test the fix by using the new built cargo:
./cargo build --manifest-path C:\Rust\example_cargo_error\Cargo.toml
Before fixing:
After fixing:
example.zip