-
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
Emit errors with cargo:error= #11312
Conversation
r? @epage (rustbot has picked a reviewer for you, use r? to override) |
let msg = "The following warnings were emitted during compilation:"; | ||
self.emit_warnings(Some(msg), &unit, cx)?; |
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.
Note: this is a change of behavior
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.
Is this necessary? AFAIK there's no such message for regular (rustc) compilation errors.
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.
My intention wasn't to say "this is a bad change of behavior" but to just raise awareness of how the message is changing. We used to have an introductory statement in this case but will no longer. I felt this would be worth highlighting when this gets a wider view during FCP
let errors = match errors_seen { | ||
0 => " due to a custom build script failure".to_string(), | ||
1 => " due to the previous error".to_string(), | ||
count => format!(" due to {count} previous errors"), | ||
}; | ||
let warnings = match warnings_seen { | ||
0 => String::new(), | ||
1 => "; 1 warning emitted".to_string(), | ||
count => format!("; {count} warnings emitted"), | ||
}; |
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.
Should we be covering more of these cases in tests?
"warning" => diagnostics.push(Diagnostic::Warning(value.to_owned())), | ||
"error" => diagnostics.push(Diagnostic::Error(value.to_owned())), | ||
"warning+" => { |
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 we split this out into a separate Issue/PR so we can make sure we are agreed on the semantics we want for this before going to the review stage and so we don't block your other work on it?
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.
Do you mean just the +=
syntax?
I've considered alternatives:
-
do nothing. Authors of crates like openssl-sys have a lot of explaining to do, so they will either have to cram everything into a one long line, or they will emit lots of lines with
cargo:error=
orcargo:warning=
. Long lines are unclear, and repeatedcargo:warning=
directives give noisy formatting that is inconsistent with rustc error output. -
support line breaks with a character sequence inside a one-liner message. No obvious sequence comes to my mind. Something recognizable like
\n
would be ambiguous with line breaks in string literals and require double-escapingprintln!("\\n")
and escaping of backslashes inside the error message. It's a hassle. -
there could be some other line prefix syntax for "append to previous line" instead of
error+=
, e.g. start next line with a tab character (like HTTP/1.1 headers)"\tsecond line"
or some other syntax like"...second line"
, but keepingcargo:
prefix seems safe, and=
vs+=
should be intuitive to Rust programmers.
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.
Yes, +=
syntax. While discussing alternatives can be interesting, again I feel its best that we have a dedicated discussion on this, so please split this out. This is not strictly required for merging error messages.
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.
This was discussed in the cargo team meeting. We came up with several concerns and it would be best to have a dedicated Issue for finishing the conversation on them.
} else if let Some(error) = stdout.strip_prefix(CARGO_ERROR) { | ||
diagnostics.push(Diagnostic::Error(error.to_owned())); |
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.
Please add a test for this
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.
It is covered by custom_build_script_failed_custom_error
test
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.
That test is in the commit for +=
and will be split out of this PR.
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've moved part of the test to earlier commits
@@ -735,7 +743,8 @@ impl BuildOutput { | |||
env.push((key, val)); | |||
} | |||
} | |||
"warning" => warnings.push(value.to_string()), | |||
// "error" is not parsed here for backwards compatibility, and because this function is for successful outputs |
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 haven't made cargo:error fail the compilation, which remains dependent on the script's exit code. This way this feature is technically backwards-compatible with crates that might have used cargo:error as their custom key-value metadata.
This is referring to
cargo:KEY=VALUE — Metadata, used by links scripts.
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script
That is a bit of a compatibility trap as theoretically any new directive is a breaking change.
The previous direction from the cargo team was
Treat the script as having errored whether or not it returns an error code.
I feel like not doing this is a behavior trap for users. I would recommend re-raising this in the Issue and for us to come up with a compatible solution that allows erroring.
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've elaborated on the design here: #10159 (comment)
da8263d
to
2def6a9
Compare
@epage @joshtriplett I'm waiting on the decisions:
I think you should be able to discuss these issues without me changing the code back and forth, so I don't think they're blocked on the PR changes, but rather the PR is waiting for team's decisions. |
As I've previously said, we should decouple the I have not been able to meet with the team for the past while. I'm hoping I can this next time. I have added these to the agenda. |
☔ The latest upstream changes (presumably #11252) made this pull request unmergeable. Please resolve the merge conflicts. |
I'm curious if @kornelski is considering picking this up again (given his other patch?), Edit: moved some comments here to #13233 |
|
As this is over a year stale, I'm going to go ahead and close this
|
Fixes #10159 (#10159 (comment))
This adds support for
cargo:error
directive similar tocargo:warning
to let custom build scripts fail in a clear way.Presence of a
cargo:error
directive hides the full dump of stderr/stdout (unless--verbose
is used). This is under assumption that scripts which opt-in to fail withcargo:error
will make this message comprehensive, and any other output would be only a distraction.I haven't made
cargo:error
fail the compilation, which remains dependent on the script's exit code. This way this feature is technically backwards-compatible with crates that might have usedcargo:error
as their custom key-value metadata.To let crate authors to emit high-quality errors with explanations, I've added support for multi-line errors and warnings. The syntax for it is
+=
, which appends extra line to the preceding error/warning: