Skip to content

Fix Ninja support #24584

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

Merged
merged 1 commit into from
Jun 17, 2025
Merged

Fix Ninja support #24584

merged 1 commit into from
Jun 17, 2025

Conversation

RReverser
Copy link
Collaborator

Fixes #24393 by using subprocess.list2cmdline instead of shlex.join.

Unfortunately, subprocess.list2cmdline is undocumented but apparently has been available for well over a decade (eg see https://stackoverflow.com/questions/12130163/how-to-get-resulting-subprocess-command-string) and, judging by discussions like https://discuss.python.org/t/why-is-subprocess-list2cmdline-not-documented/25044 is unlikely to be ever removed since it's been long used in the wild.

It does exactly what we want - quote & join a command by Windows rules.

Fixes emscripten-core#24393 by using subprocess.list2cmdline instead of shlex.join.

Unfortunately, subprocess.list2cmdline is undocumented but apparently has been available for well over a decade (eg see https://stackoverflow.com/questions/12130163/how-to-get-resulting-subprocess-command-string) and, judging by discussions like https://discuss.python.org/t/why-is-subprocess-list2cmdline-not-documented/25044 is unlikely to be ever removed since it's been long used in the wild.

It does exactly what we want - quote & join a command by Windows rules.
@RReverser RReverser requested a review from sbc100 June 16, 2025 23:25
@@ -183,13 +184,15 @@ def create_ninja_file(input_files, filename, libname, cflags, asflags=None, cust
if asflags is None:
asflags = []

join_cmd = shlex.join if os.name == 'posix' else subprocess.list2cmdline
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we just use subprocess.list2cmdline in all cases?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh I see its a windows-specific function. I guess this will have to do

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should re-add shlex_join to utils.py and use that instead of shlex.join everywhere. Effectivly reverting #24111 but with a cleaner shlex_join impl?

Copy link
Collaborator Author

@RReverser RReverser Jun 17, 2025

Choose a reason for hiding this comment

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

Maybe, but not sure.

As I said in #24393 (comment), it does look like all other usages are for debug purposes only so syntax doesn't matter as much, and for command invocations we normally use subprocess module which does the right thing via native APIs automatically, so Ninja usecase - where we have to stringify a command with a valid OS-specific syntax - seems somewhat special in that regard.

If nothing else pops up, I wouldn't bother generalising it for now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK sgtm

@RReverser RReverser merged commit 542dc42 into emscripten-core:main Jun 17, 2025
30 checks passed
@RReverser RReverser deleted the fix-ninja branch June 17, 2025 01:12
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.

Ninja support for Windows is broken
2 participants