Skip to content

Conversation

ildus
Copy link

@ildus ildus commented Jun 6, 2025

Replace '$^' with the actual newlines.

Straight to use case:

rule one
    command = cmd /C file.bat
    rspfile = file.bat
    rspfile_content = echo "1" > $out $^echo "2"

build one.txt : one

This is required when the build system generates scripts, but trying to make one liners from every script is too bug prone. For example 'set ' in Windows cmd.exe requires delayed expansion when the variable (which is just set) was used in the same line. But writer of the building script could not know such details.

Another case is platforms where scripts can not be converted to oneliners in any way (I have a such use case for OpenVMS dcl).

'$^' currently gives an error (bad escape), so this change should not break the current usage of ninja in any way.

`$:` :: a colon. (This is only necessary in `build` lines, where a colon
would otherwise terminate the list of outputs.)

`$^` :: a newline. Inserts '\n' into the resulting string.
Copy link

Choose a reason for hiding this comment

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

Why it named not a $n, similar to the $:?

Copy link
Author

Choose a reason for hiding this comment

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

Not so visible when surrounded with an another text, and ^ usually means the beginning like in regular expressions.

@jhasse
Copy link
Collaborator

jhasse commented Jun 13, 2025

Thanks! For this not to cause a lot of confusion in the future I think we should print a warning (or error?) if some uses it without ninja_minimum_version = 1.13 in the first line. Because then the error message for someone with older ninja will be more helpful. Not sure if that is easily doable with the current parser.

@digit-google
Copy link
Contributor

Following the regression described in #2616, should these newlines be \r\n on Windows instead?

@ildus
Copy link
Author

ildus commented Jun 29, 2025

@digit-google That's a good question. I think it depends on the use case. For the scripts like in example cmd works just fine with both line endings, but I remember bash from cygwin could fail on windows endings. Although I could not reproduce it today, on my cygwin today it worked ok with '\r\n', maybe they fixed that.

@ildus
Copy link
Author

ildus commented Sep 26, 2025

Changed behavior on Windows for consistency, will add '\r\n' instead just '\n'.

@digit-google
Copy link
Contributor

Thank you very much, apart from the latest two nits, this looks good to me. @jhasse , wdyt?

@ildus
Copy link
Author

ildus commented Sep 26, 2025

@digit-google Thanks for review!

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.

4 participants