Improve newline handling for ToolDef's writefile tool
The tool has the following signatures:
tool writefile(string path, string text, bool append = false)
tool writefile(string path, list string lines, bool append = false)
The problems are:
- The first variant writes a single string. It uses
FileAppStream
, which replaces all newlines by platform-specific newlines. This is not nice, because if I create a Linux shell script, I want to preserve the Linux line endings, even if I write the Linux shell script on a Windows computer. The string should be written as is, not manipulated in any way. I thus propose to invokesetConvertNewLines(false)
to keep the newlines intact, and write the raw string, as it is. - The second variant writes lines, and terminates each with a newline character. It uses
FileAppStream
, which uses platform-specific newlines. This is not nice, as ToolDef is supposed to be platform-independent. I thus propose to invokesetUnixNewLineBytes()
to always write the same newlines. This makes it platform-independent. All platforms, including all decent tools on Windows, support Unix-style newlines these days.
I think these are good improvements. While these are backwards-incompatible, I don't think it will lead to many problems.