Skip to content

scripts: start _build.cmd with cmd /s /c ""path"" so & and ^ survive - #3554

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
ezbyDev:scripts/batch-launch-quotes
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
ezbyDev:scripts/batch-launch-quotes

Conversation

@ezbyDev

@ezbyDev ezbyDev commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claim: #3381 (comment)

What changed and why

scripts/build_runtime.ps1 and scripts/build_llvm_mc.ps1 started the generated batch with Start-Process cmd.exe -ArgumentList "/c", "\"$bat\"". cmd.exe drops those quotes when the path holds a special character such as & or ^, then runs only the part before it. So a checkout (build_runtime.ps1) or a -Temp/%TEMP% (build_llvm_mc.ps1) in a folder like C:\src\a & b failed straight away with "C:\src\a" is not recognized. Both now use "/s", "/c", "\"\"$bat\"\"": with /s cmd.exe strips only the outer pair of quotes, so the path stays quoted. One line in each script; the batch body is unchanged, and its paths are already quoted inside the .cmd.

New tests/test_build_batch_launch.py takes each script's $p = Start-Process cmd.exe -ArgumentList ... line as written and runs it on a stub _build.cmd in folders named plain, a & b, a&b, x^y, sp (x) and 東京 & co. The stub must run, and its exit code (0 and 7) must come back. A second case checks that the old form fails in the &/^ folders, so the check can't pass by accident.

Touches the same scripts as #3250, #3363, #3029, #2975, #2717, #2648, #2515, #2497, #1797, #802 and #157. None of them changes this line except #1797, which rewrites it but keeps /c "path".

Tests (Windows 11, Windows PowerShell 5.1, Python 3.12.10, CPU only, no GPU used)

  • python -I tests/test_build_batch_launch.py: 2 tests OK.
  • With both scripts as on main f847748c, it fails for both scripts: all 8 &/^ cases of the 12 break, and the 4 plain and sp (x) cases pass.
  • A probe with the same two forms over 8 folder names (adding 100% and it's), each with exit 0 and 7: old 8/16, new 16/16.
  • python -I tests/test_ci_registration.py, tests/test_text_write_line_endings.py: OK. tests/test_build_runtime_fallback.py and tests/test_build_llvm_mc_batch.py: OK with NoDefaultCurrentDirectoryInExePath unset; with it set they fail on main too (fixed separately in tests: start _build.cmd as .\_build.cmd in the two batch-writer tests #3380).
  • The scripts keep their BOM and CRLF working-tree line endings.
  • Not run: a full build_runtime.ps1 / build_llvm_mc.ps1 build from such a folder (needs MSVC plus the full toolchain); only the launch line was exercised, with a stub batch.

AI-assisted (Claude Code).

build_runtime.ps1 and build_llvm_mc.ps1 started the generated batch with
`cmd.exe /c "path"`. cmd.exe drops those quotes when the path holds a
special character such as & or ^, then runs only the part before it, so a
checkout (build_runtime) or -Temp/%TEMP% (build_llvm_mc) in a folder like
`a & b` failed at once with "C:\...\a is not recognized". With /s and a
second pair of quotes, cmd.exe strips only the outer pair.

tests/test_build_batch_launch.py takes each script's launch line as written
and runs it on a stub batch in folders named plain, `a & b`, `a&b`, `x^y`,
`sp (x)` and `東京 & co`: the stub must run and its exit code (0 and 7) must
come back. It also checks that the old form fails there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dcastell1

Copy link
Copy Markdown
Contributor

Code read (no test run: this machine is in a no-background-work window). This is the canonical form: cmd /s /c ""path"" makes cmd strip only the outer pair, so the inner quotes survive around the path and &/^ inside a folder name stay literal. Without /s, cmd strips the first and last quote it sees and the argument stops being quoted.

The comment you added is the part that keeps it from being "fixed" back later; worth keeping it in both places, as you did.

@slint6614-dev slint6614-dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Independent Windows validation of fc3bda5c (PowerShell 5.1.26100.9818, Python 3.12.10): python -I tests/test_build_batch_launch.py passed 2/2. It exercises both scripts with paths containing spaces, &, ^, parentheses and Unicode, and verifies child exit codes 0 and 7. The negative control also confirms the old /c "path" form fails for & and ^. I did not run the full compiler/toolchain builds. No blocking issue in this focused change.

@clutchwtn

Copy link
Copy Markdown

Tested fc3bda5c on Windows 11 Enterprise 10.0.26300, Windows PowerShell 5.1.26100, Python 3.13.17, CPU only: pass.

  • python -I tests/test_build_batch_launch.py: 2 tests OK.
  • With scripts/ from main (f847748c) and the new test kept, test_each_script_starts_its_batch_in_any_folder fails for both scripts in the &/^ folders (a & b/0->1, …), so the check catches the old form.
  • tests/test_ci_registration.py, tests/test_text_write_line_endings.py: OK.
  • tests/test_build_runtime_fallback.py, tests/test_build_llvm_mc_batch.py: error with NoDefaultCurrentDirectoryInExePath=1 ('_build.cmd' is not recognized), the same on main; OK on this PR with it unset, as the description says (tests: start _build.cmd as .\_build.cmd in the two batch-writer tests #3380).
  • Not run: a full build_runtime.ps1 / build_llvm_mc.ps1 build.

@VeTkN VeTkN left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested fc3bda5 on Windows 11 Pro (26200), MSVC 19.51 (VS 2026 Build Tools): a full scripts/build_runtime.ps1 build from a git worktree of this PR at C:\LT\amp&caret^dir, the run the description lists as not done.

  • With this PR's scripts the launch works: CMake configures and Ninja starts. Step 13 of 431, linking gta6rt_xtaskqueue.lib, then fails, and Ninja stops at step 18. Ninja runs lib.exe through cmd.exe /C with the object paths unquoted, and those paths contain the folder name, because the xtaskqueue sources sit outside runtime/ (CMakeFiles\gta6rt_xtaskqueue.dir\C_\LT\amp&caret^dir\third_party\xtaskqueue\...). cmd splits at the &: fatal error LNK1181 on CMakeFiles\gta6rt_xtaskqueue.dir\C_\LT\amp.
  • With main's two scripts in the same folder: exit 1 at once, with no build output. So the launch fix itself works.
  • Control, this PR in a plain folder (C:\LT\plain): exit 0, 248 s, all 431 steps, gta6rt.exe built.

So the launcher part is fixed, but a full runtime build from a folder with & still fails in the generated build, outside this PR's scope. Maybe worth a Known problems row or a follow-up item. I only tried a name with both & and ^ (the cut is at the &), and didn't run build_llvm_mc.ps1.

AI-assisted (Claude).

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.

6 participants