scripts/build_llvm_mc.ps1: validate Version, normalize -Temp, harden VS/tool fallback and literal install #1871

Merged
leonida/mandy
kirigayakazima merged 1 commit from fix/build-llvm-mc-safety into main 2026-11-28 23:49:49 +00:00

Pull request successfully merged and closed

kirigayakazima commented 2026-11-25 13:46:15 +00:00

Claimed in the coordination issue as: BUILD-LLVM-MC-REL-TEMP-VS-AND-TOOL-FALLBACK-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164207060)

What and why

  • Validate -Version up front in scripts/build_llvm_mc.ps1 so empty strings, whitespace, control characters, or % fail before cloning or running prerequisites.
  • Normalize $Temp = $fullTemp after resolving via PowerShell provider paths so _build.cmd, $src, $out, and [System.IO.File]::WriteAllText never drift to [Environment]::CurrentDirectory when a relative -Temp is passed.
  • Guard missing vswhere.exe and missing vcvars64.bat with explicit actionable errors (Test-Path -LiteralPath ... -PathType Leaf) instead of CommandNotFoundException or opaque call failures.
  • Resolve VS-bundled and PATH cmake/ninja independently so one tool from Visual Studio can pair cleanly with the other on PATH.
  • Pass [System.Text.UTF8Encoding]::new($false) explicitly when writing probe.txt, and switch Copy-Item to -LiteralPath ... -Destination $final so bracketed paths work reliably. Preserve CRLF line endings (PS1_CRLF=177, PS1_LF_ONLY=0).
  • Add regression tests in tests/test_build_llvm_mc_prereqs.py without disturbing any anchors sliced by the existing 5 build_llvm_mc tests.

Tested

  • Patched:
    • python -I tests/test_build_llvm_mc_prereqs.py -v -> Ran 5 tests in 3.172s (OK)
    • python -I tests/test_build_llvm_mc_batch.py -v -> Ran 1 test in 0.933s (OK)
    • python -I tests/test_build_llvm_mc_cleanup.py -v -> Ran 1 test in 0.310s (OK)
    • python -I tests/test_llvm_install_destination.py -v -> Ran 1 test in 1.470s (OK)
    • python -I tests/test_llvm_install_path.py -v -> Ran 3 tests in 1.578s (OK)
    • python -I tests/test_llvm_source_version.py -v -> Ran 6 tests in 5.677s (OK)
  • Baseline check (upstream/main 5e95fa2f with tests/test_build_llvm_mc_prereqs.py copied into detached worktree): Ran 5 tests in 3.120s (FAILED (failures=8, errors=1)).
  • Repo gates: PS1_CRLF=177 PS1_LF_ONLY=0, python -I tests/test_ci_registration.py (Ran 16 tests in 5.989s, OK), python -I tests/test_text_write_line_endings.py (Ran 3 tests in 14.043s, OK), python -I scripts/check_no_game_data.py (exit 0), python -I -m compileall -q (exit 0), git diff --check (exit 0).

GPUs tested: n/a (PowerShell prerequisite validation, relative-path normalization, tool fallback, and literal install tests)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
Claimed in the coordination issue as: BUILD-LLVM-MC-REL-TEMP-VS-AND-TOOL-FALLBACK-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164207060) ### What and why - Validate `-Version` up front in `scripts/build_llvm_mc.ps1` so empty strings, whitespace, control characters, or `%` fail before cloning or running prerequisites. - Normalize `$Temp = $fullTemp` after resolving via PowerShell provider paths so `_build.cmd`, `$src`, `$out`, and `[System.IO.File]::WriteAllText` never drift to `[Environment]::CurrentDirectory` when a relative `-Temp` is passed. - Guard missing `vswhere.exe` and missing `vcvars64.bat` with explicit actionable errors (`Test-Path -LiteralPath ... -PathType Leaf`) instead of `CommandNotFoundException` or opaque `call` failures. - Resolve VS-bundled and `PATH` `cmake`/`ninja` independently so one tool from Visual Studio can pair cleanly with the other on `PATH`. - Pass `[System.Text.UTF8Encoding]::new($false)` explicitly when writing `probe.txt`, and switch `Copy-Item` to `-LiteralPath ... -Destination $final` so bracketed paths work reliably. Preserve CRLF line endings (`PS1_CRLF=177, PS1_LF_ONLY=0`). - Add regression tests in `tests/test_build_llvm_mc_prereqs.py` without disturbing any anchors sliced by the existing 5 `build_llvm_mc` tests. ### Tested - Patched: - `python -I tests/test_build_llvm_mc_prereqs.py -v` -> `Ran 5 tests in 3.172s` (`OK`) - `python -I tests/test_build_llvm_mc_batch.py -v` -> `Ran 1 test in 0.933s` (`OK`) - `python -I tests/test_build_llvm_mc_cleanup.py -v` -> `Ran 1 test in 0.310s` (`OK`) - `python -I tests/test_llvm_install_destination.py -v` -> `Ran 1 test in 1.470s` (`OK`) - `python -I tests/test_llvm_install_path.py -v` -> `Ran 3 tests in 1.578s` (`OK`) - `python -I tests/test_llvm_source_version.py -v` -> `Ran 6 tests in 5.677s` (`OK`) - Baseline check (`upstream/main` `5e95fa2f` with `tests/test_build_llvm_mc_prereqs.py` copied into detached worktree): `Ran 5 tests in 3.120s` (`FAILED (failures=8, errors=1)`). - Repo gates: `PS1_CRLF=177 PS1_LF_ONLY=0`, `python -I tests/test_ci_registration.py` (`Ran 16 tests in 5.989s`, `OK`), `python -I tests/test_text_write_line_endings.py` (`Ran 3 tests in 14.043s`, `OK`), `python -I scripts/check_no_game_data.py` (exit 0), `python -I -m compileall -q` (exit 0), `git diff --check` (exit 0). GPUs tested: n/a (PowerShell prerequisite validation, relative-path normalization, tool fallback, and literal install tests) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
zmasi commented 2026-11-28 12:57:20 +00:00

#1871 | head 74e9e8012b088e2ad4f29df90c04fba8a0b46802 (merged cleanly with main d48a957bb) | python -I tests/test_build_llvm_mc_prereqs.py | red on main: FAILED (failures=8, errors=1) (ran git check before -Version validation, resolved relative -Temp against [Environment]::CurrentDirectory instead of PowerShell $PWD, threw CommandNotFoundException on missing vswhere.exe, coupled cmake/ninja fallback, and failed wildcard copy into bracketed tools[1]) | green on PR+main: 5 tests OK | Windows 11 (10.0.26200.9974, powershell.exe 5.1.26100.9818), Python 3.12.10 | AI-assisted: yes

Audited scripts/build_llvm_mc.ps1 and tests/test_build_llvm_mc_prereqs.py on Windows 11 PowerShell 5.1, verifying upfront -Version validation, $Temp = $fullTemp provider-path normalization, -LiteralPath -PathType Leaf checks on vswhere.exe and vcvars64.bat, independent VS-bundled vs PATH resolution for cmake and ninja, BOM-free UTF8Encoding($false) probe.txt write, and Copy-Item -LiteralPath into bracketed destination paths. Also verified tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), and scripts/check_no_game_data.py.

Merge note with #2066: both PRs modify the vswhere.exe lookup lines in scripts/build_llvm_mc.ps1 (git merge-tree conflict on $vswhere vs "$installer\vswhere.exe"). Keeping #1871's $vswhere leaf check and adding #2066's if (-not $vs) { $vs = & $vswhere -latest -prerelease -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath } fallback immediately below passes both tests/test_build_llvm_mc_prereqs.py (5 OK) and #2066's tests/test_build_vs_lookup.py (1 OK).

#1871 | head 74e9e8012b088e2ad4f29df90c04fba8a0b46802 (merged cleanly with main d48a957bb) | `python -I tests/test_build_llvm_mc_prereqs.py` | red on main: `FAILED (failures=8, errors=1)` (ran `git` check before `-Version` validation, resolved relative `-Temp` against `[Environment]::CurrentDirectory` instead of PowerShell `$PWD`, threw `CommandNotFoundException` on missing `vswhere.exe`, coupled `cmake`/`ninja` fallback, and failed wildcard copy into bracketed `tools[1]`) | green on PR+main: `5 tests OK` | Windows 11 (`10.0.26200.9974`, `powershell.exe` `5.1.26100.9818`), Python 3.12.10 | AI-assisted: yes Audited `scripts/build_llvm_mc.ps1` and `tests/test_build_llvm_mc_prereqs.py` on Windows 11 PowerShell 5.1, verifying upfront `-Version` validation, `$Temp = $fullTemp` provider-path normalization, `-LiteralPath -PathType Leaf` checks on `vswhere.exe` and `vcvars64.bat`, independent VS-bundled vs `PATH` resolution for `cmake` and `ninja`, BOM-free `UTF8Encoding($false)` `probe.txt` write, and `Copy-Item -LiteralPath` into bracketed destination paths. Also verified `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), and `scripts/check_no_game_data.py`. Merge note with #2066: both PRs modify the `vswhere.exe` lookup lines in `scripts/build_llvm_mc.ps1` (`git merge-tree` conflict on `$vswhere` vs `"$installer\vswhere.exe"`). Keeping #1871's `$vswhere` leaf check and adding #2066's `if (-not $vs) { $vs = & $vswhere -latest -prerelease -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath }` fallback immediately below passes both `tests/test_build_llvm_mc_prereqs.py` (`5 OK`) and #2066's `tests/test_build_vs_lookup.py` (`1 OK`).
TheGeogeo commented 2026-11-28 23:38:20 +00:00

Tested 74e9e8012 merged (no commit) with main aa918e5d9: Python 3.12.4, Windows 11 10.0.26300, CPU only. check_no_game_data.py is clean.

  • Green: tests/test_build_llvm_mc_prereqs.py, 5 tests pass.
  • Red: with scripts/build_llvm_mc.ps1 back to main, the tests fail: the script stops on a -Temp path it cannot write.
  • Merge order: this PR conflicts in scripts/build_llvm_mc.ps1 with #2066, #2060 and #2053 (git merge-tree). #2066 is the one suggested there, so this PR or #2066 will need a rebase after the other.

No blocker from my side.

AI-assisted (Claude Code).

Tested `74e9e8012` merged (no commit) with `main` `aa918e5d9`: Python 3.12.4, Windows 11 10.0.26300, CPU only. `check_no_game_data.py` is clean. - Green: `tests/test_build_llvm_mc_prereqs.py`, 5 tests pass. - Red: with `scripts/build_llvm_mc.ps1` back to `main`, the tests fail: the script stops on a `-Temp` path it cannot write. - Merge order: this PR conflicts in `scripts/build_llvm_mc.ps1` with #2066, #2060 and #2053 (`git merge-tree`). #2066 is the one suggested there, so this PR or #2066 will need a rebase after the other. No blocker from my side. AI-assisted (Claude Code).
MoonEyes commented 2026-11-28 23:49:51 +00:00

Merged after TheGeogeo's red/green check (check) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto main 5fe330015 without conflict, and its test file(s) (tests/test_build_llvm_mc_prereqs.py) pass there. Earlier today the same tests failed on main without the PR (red/green) and a bundle with other open PRs showed no new failures. check_no_game_data.py is clean. Windows 11, Python 3.14; no GPU needed for these tests.

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

Merged after **TheGeogeo**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/1871#issuecomment-7247564297)) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto `main` 5fe330015 without conflict, and its test file(s) (`tests/test_build_llvm_mc_prereqs.py`) pass there. Earlier today the same tests failed on `main` without the PR (red/green) and a bundle with other open PRs showed no new failures. `check_no_game_data.py` is clean. Windows 11, Python 3.14; no GPU needed for these tests. _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
Sign in to join this conversation.
No description provided.