kbknapp / cargo-graph

A cargo subcommand for creating GraphViz DOT files and dependency graphs
BSD 3-Clause "New" or "Revised" License
216 stars 16 forks source link

cargo-graph generates incompatible dot files in powershell #41

Open Trolldemorted opened 6 years ago

Trolldemorted commented 6 years ago

When starting cargo graph in windows' cmd shell, the output file is ASCII text. When you start it in windows' powershell, the output file is Little-endian UTF-16 Unicode text, with CRLF, CR line terminators and a byte order mark.

dot fails to produce pngs from such a file:

PS C:\Users\Benni\repositories\parity> dot -Tpng > rainbow-graph.png cargo-count-ps.dot
Error: cargo-count-ps.dot: syntax error in line 1 near ' ■d'
remram44 commented 6 years ago

File is opened here:

https://github.com/kbknapp/cargo-graph/blob/d895af1b7840c7ae8eddaf4e990bfa594c22ba01/src/main.rs#L332-L334

And written to here:

https://github.com/kbknapp/cargo-graph/blob/d895af1b7840c7ae8eddaf4e990bfa594c22ba01/src/graph.rs#L222

I'm surprised this would happen. I don't see a reason for it?

Trolldemorted commented 6 years ago

The example and thus I are piping the content into a file, so cfg.dot_file is None, and stdout's encoding depends on the shell you use I presume?

Edit: Even if I write only a single letter this way, the BOM and encoding is that way, so I guess powershell uses utf16 (or something similar) and stdout adheres to that.

remram44 commented 6 years ago

I really assumed write!() always outputted UTF-8. I don't know where this translation could be happening.