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

Ignore non-utf8 text in build script output #1583

Merged
merged 1 commit into from
Oct 8, 2022

Conversation

dae
Copy link
Contributor

@dae dae commented Oct 4, 2022

When compiling the latest zstd crate on a German locale in non-release mode on Windows, it outputs localized messages that are not UTF8, causing the compile to fail.

Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

Wow, this is a fun edge-case :D Thanks for the fix!

if let Some(bso) = BuildScriptOutput::new(&line) {
let mut buf = Vec::new();
while reader
.read_until(b'\n', &mut buf)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add a test that if the output doesn't end with a trailing newline, we still parse the last line of output? (i.e. can you remove the trailing newline from the example output in the test?)

Also, could you add a line of invalid utf-8 to the testdata in the test, to verify this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

.expect("Cannot read line")
!= 0
{
let line = &String::from_utf8_lossy(&buf);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like cargo actually completely skips any line which isn't utf-8: https://github.com/rust-lang/cargo/blob/0b84a35c2c7d70df4875a03eb19084b0e7a543ef/src/cargo/core/compiler/custom_build.rs#L566-L569

Can you do the same, rather than trying to parse the line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

Perfect, thanks!

@dae
Copy link
Contributor Author

dae commented Oct 7, 2022

Sorry, didn't notice the failed clippy test.

@illicitonion illicitonion enabled auto-merge (squash) October 7, 2022 13:57
@illicitonion
Copy link
Collaborator

Sorry, it looks like you need to merge main and then we can get this merged!

When compiling the latest zstd crate on a German locale in non-release
mode on Windows, it outputs localized messages that are not UTF8, causing
the compile to fail.
@dae
Copy link
Contributor Author

dae commented Oct 7, 2022

(rebased on main)

@UebelAndre UebelAndre merged commit 7ffe0a5 into bazelbuild:main Oct 8, 2022
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.

3 participants