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

Open
opened 2026-11-26 21:19:17 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1871
Author: @kirigayakazima
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/build-llvm-mc-safety


📝 Commits (1)

  • 74e9e80 Harden build_llvm_mc.ps1 Version/Temp resolution, VS/tool fallback, and literal copy

📊 Changes

2 files changed (+191 additions, -7 deletions)

View changed files

📝 scripts/build_llvm_mc.ps1 (+19 -7)
➕ tests/test_build_llvm_mc_prereqs.py (+172 -0)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1871 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/build-llvm-mc-safety` --- ### 📝 Commits (1) - [`74e9e80`](https://github.com/ubiquitarianism/leonida/commit/74e9e8012b088e2ad4f29df90c04fba8a0b46802) Harden build_llvm_mc.ps1 Version/Temp resolution, VS/tool fallback, and literal copy ### 📊 Changes **2 files changed** (+191 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `scripts/build_llvm_mc.ps1` (+19 -7) ➕ `tests/test_build_llvm_mc_prereqs.py` (+172 -0) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1883
No description provided.