Skip to content

Substitute an args file before wrapping a run in a shell - #2533

Merged
bfiete merged 1 commit into
beefytech:masterfrom
robknopf:pr/dorun-argsfile-shell
Nov 30, 2026
Merged

bfiete merged 1 commit into
beefytech:masterfrom
robknopf:pr/dorun-argsfile-shell

Conversation

@robknopf

Copy link
Copy Markdown
Contributor

DoRun builds the .ShellCommand invocation, setting the file name to cmd.exe and the arguments to /s /c "<exe> <args>":

else if (runFlags.HasFlag(.ShellCommand))
{
    ...
    startInfo.SetFileName("cmd.exe");
    startInfo.SetArguments(shellArgs);
}

and then the args file block below it overwrites those arguments:

if (useArgsFile != .None)
{
    ...
    arguments.Concat("@", tempFileName);
    startInfo.SetArguments(arguments);
}

cmd.exe is left with @tempfile and no /c, so it opens an interactive prompt and waits on it. The run never completes and the build hangs, since the execution is only considered finished once the process exits and its reader threads end.

The two have never been combinable. Nothing currently passes .ShellCommand, so nothing has hit it, but anything that did would hit it immediately for real workloads: cArgFileThreshold is 8191, and a link line long enough to matter is well past that.

This moves the substitution ahead of the wrapping, into effArgs, and has the shell and batch branches consume that — giving cmd /s /c "<exe> @tempfile". Without .ShellCommand or .BatchCommand the behaviour is unchanged: the same arguments are computed from the same inputs, just earlier.

The batch branch also now deletes the previous mTempFileName before replacing it, which the args file branch already did and which otherwise leaks when both apply.

Verified

On Linux, IDEHelper/Tests 143/143 and the IDE/Tests/Test1 IDE suite 41/41. That exercises it fairly hard, since every link, every PreBuildCmds exec and every test process goes through this path.

I found it while making the wasm link able to use an emsdk that ships emcc.bat rather than emcc.exe, which needs a shell to launch. That change is separate and I will put it up once this is settled, so the two cannot land in the wrong order.

@robknopf
robknopf force-pushed the pr/dorun-argsfile-shell branch from b3ff873 to f5aa2bf Compare November 29, 2026 03:16
DoRun builds the shell invocation for .ShellCommand, setting cmd.exe and
'/s /c "<exe> <args>"', and then the args file block below it overwrites the
arguments with '@tempfile'. cmd.exe is left with no '/c', so it opens an
interactive prompt and the build waits on it forever. The two have never been
combinable; nothing set .ShellCommand until now, so nothing hit it.

The substitution now happens first, into 'effArgs', and the shell and batch
wrappings consume that, giving 'cmd /s /c "<exe> @tempfile"'. Behaviour without
.ShellCommand or .BatchCommand is unchanged: the same arguments are set from
the same inputs, just earlier.

Also deletes the previous mTempFileName in the batch branch before replacing
it, which the args file branch already did and which leaked otherwise.
@robknopf
robknopf force-pushed the pr/dorun-argsfile-shell branch from f5aa2bf to 27c0423 Compare November 30, 2026 14:38
@bfiete
bfiete merged commit 27c0423 into beefytech:master Nov 30, 2026
5 checks passed
@robknopf
robknopf deleted the pr/dorun-argsfile-shell branch November 30, 2026 23:56
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