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

Dependencies are not sorted error on Windows #56

Open
dallenng opened this issue Nov 6, 2022 · 8 comments
Open

Dependencies are not sorted error on Windows #56

dallenng opened this issue Nov 6, 2022 · 8 comments

Comments

@dallenng
Copy link

dallenng commented Nov 6, 2022

I was trying to setup CI for one one my repo including cargo sort --check, but the check fail on Windows while it succeeds on Linux. I don't have a Windows machine so I cannot test this outside of the Github actions.

The repo is here. The logs of the failing job are here.

I don't know if you can see the logs, so here are the logs for ubuntu and windows.

I don't really know what more I can say, but if you need more input, I'll gladly answer.

@DevinR528
Copy link
Owner

Hmm, is there any chance it could be a line-ending thing? I also noticed one of the files does not end with \n; cargo-sort currently fails if there is no trailing newline. If it's not too much trouble you could try to run --print instead of --check to see what windows ci does.

@dallenng
Copy link
Author

I'm guessing you can see the logs so here is the windows job with --print which outputs the same thing as the linux job. I guess I could check formatting only on linux.

@dallenng
Copy link
Author

I think I know why it fails. When the repo is cloned on windows, the \n are converted to \r\n, so the original string contains \r\n. After parsing and sorting, the document is written to a string with the write macro, this macro uses \n on all platforms, so the sorted string contains \n. The comparison between the two then fail because line ending differ.

@DevinR528
Copy link
Owner

Wow, nice find! I'll look into finding a better cross-platform way to compare. I wonder if ignoring the difference would be ok, any thoughts?

@dallenng
Copy link
Author

Maybe you could compare the parsed Document of the input and the sorted input instead of comparing strings. I don't know the toml_edit library but this should ignore formatting differences.

@DevinR528
Copy link
Owner

That may work, I'd have to look into it after switching to the actual toml_edit crate. Thanks for the idea!

@lynn
Copy link

lynn commented Mar 27, 2023

I ran into probably the same issue. I have a Cargo.toml file like this:

[package]
name = "foo"
description = "bar"
version = { workspace = true }
publish = { workspace = true }
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
fs_extra = "1.3.0"
sysinfo = "0.28.2"

On Linux, cargo sort -w -g removes line 7, the empty line above the comment. On Windows, the line is not removed.

So cargo sort -w -g -c fails on Linux and succeeds on Windows.

I don't have autocrlf turned on in git. The file has LF line endings both on Windows and Linux. But maybe cargo sort expects the file to have CRLF line endings on Windows and gets confused?

EDIT: Yes, when I convert the file to CRLF and run cargo sort -w -g it removes line 7 on Windows.

@jacob-pro
Copy link

@lynn Yep I am seeing the same thing

When there are extra lines in the middle of the file, if it is in LF format, then the Windows version of cargo-sort will not remove them. Whereas the Linux version will.

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

No branches or pull requests

4 participants