Skip to content

Run compiler-issued commands with a real argv - #13044

Open
kLabz wants to merge 1 commit into
developmentfrom
fix-run-command-args-quoting
Open

kLabz wants to merge 1 commit into
developmentfrom
fix-run-command-args-quoting

Conversation

@kLabz

@kLabz kLabz commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

run_command_args folded the program and its arguments into one string and handed that to a shell, so generators had to quote arguments themselves. That quoting broke in server mode on Windows: the command string is passed to cmd.exe as a single argv entry, which OCaml escapes as \"…\", and the quotes end up literal in the child's arguments. haxelib run hashlink build then received "bin/c/hlout/main.c" and looked for "bin/c/hlout/hlc.json (regression from replacing the process C stubs, which handed the raw command line to CreateProcess). Unquoted arguments were no better: nekoc got a path with a space split into two arguments.

Give run_command_args its own implementation that never builds a command string: the child is spawned from an argv, going through the command interpreter on Windows only so .bat/.cmd shims keep resolving. Generators pass their arguments raw.

(fixes a regression from c49aa82)

`run_command_args` folded the program and its arguments into one string and
handed that to a shell, so generators had to quote arguments themselves. That
quoting broke in server mode on Windows: the command string is passed to
cmd.exe as a single argv entry, which OCaml escapes as `\"…\"`, and the quotes
end up literal in the child's arguments. `haxelib run hashlink build` then
received `"bin/c/hlout/main.c"` and looked for `"bin/c/hlout/hlc.json`
(regression from replacing the process C stubs, which handed the raw command
line to CreateProcess). Unquoted arguments were no better: `nekoc` got a path
with a space split into two arguments.

Give `run_command_args` its own implementation that never builds a command
string: the child is spawned from an argv, going through the command
interpreter on Windows only so .bat/.cmd shims keep resolving. Generators pass
their arguments raw.
Comment thread src/generators/gencpp.ml
common_ctx.class_paths#iter (fun path ->
let path = path#path in
cmd := !cmd @ [Printf.sprintf "-I\"%s\"" (escape_command path)]
cmd := !cmd @ [Printf.sprintf "-I%s" path]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be good to add a test to make sure spaces in these include paths still work with hxcpp (if we don't have one already).

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.

2 participants