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

Kati fails to translate # in ninja mode #250

Open
jzhupo opened this issue Jun 10, 2022 · 1 comment
Open

Kati fails to translate # in ninja mode #250

jzhupo opened this issue Jun 10, 2022 · 1 comment

Comments

@jzhupo
Copy link

jzhupo commented Jun 10, 2022

[Test code]

bar:
	$(foreach var,foo,echo #define $(var);)

[Expected build.ninja]
rule rule0
description = build $out
command = /bin/sh -c "echo #define foo"
build bar: rule0

[Actual build.ninja]
rule rule0
description = build $out
command = /bin/sh -c "echo"
build bar: rule0

@danw
Copy link
Collaborator

danw commented Jun 10, 2022

At least in this particular example, the output(\n) is identical, and matches make, since the # is interpreted as a shell comment.

It's a bit more obvious why we're doing this when you add a second line to the rule:

bar:
	$(foreach var,foo,echo bar #define $(var);)
	$(foreach var,foo,echo bar #define $(var);)
rule rule0
 description = build $out
 command = /bin/sh -c "(echo bar ) && (echo bar )"
build bar: rule0

If we left the shell comments in we'd get syntax errors:

$ /bin/sh -c "(echo bar #define foo) && (echo bar #define foo)"
/bin/sh: -c: line 2: syntax error: unexpected end of file

Looking at the more detailed LK makefile, it looks like this ends up being an escaping issue:

bar:
	$(foreach var,foo,echo nothing #define $(var);)
	$(foreach var,foo,echo "quoted #define $(var)";)
	$(foreach var,foo,echo escape \#define $(var);)
	$(foreach var,foo,echo double escape \\\#define $(var);)

$ make bar
echo nothing #define foo;
nothing
echo "quoted #define foo";
quoted #define foo
echo escape \#define foo;
escape #define foo
echo double escape \\\#define foo;
double escape \#define foo
rule rule0
 description = build $out
 command = /bin/sh -c "(echo nothing ) && (echo \"quoted #define foo\" ) && (echo escape ) && (echo double escape \\\\#define foo )"
build bar: rule0
$ sh ...
nothing
quoted #define foo
escape
double escape \#define foo

So we're handling the quoted and double-escaped version fine, but not the single escape. And removing the foreach portion makes it work, so we're not preserving the single escape through the foreach in this context.

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

2 participants