build_llvm_mc.ps1: a relative -Temp is checked as the full path it resolves to

Review by @QemmHD: a relative -Temp under a working directory with % skipped the check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lines9686-rgb
2026-11-24 08:52:50 +03:00
parent 5dbd92b92d
commit 2a4f650b7b
2 changed files with 14 additions and 4 deletions

View File

@ -20,8 +20,10 @@ param(
$ErrorActionPreference = "Stop"
# cmd.exe expands %...% on every line of _build.cmd (twice on a CALL line), so a -Temp with % in it breaks the build.
if ($Temp.Contains('%')) {
throw "-Temp '$Temp' contains '%', which cmd.exe expands in the generated _build.cmd. Choose a -Temp folder without % in its path."
# A relative -Temp is checked as the full path it resolves to (the working directory can hold the %).
$fullTemp = [IO.Path]::GetFullPath($ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Temp))
if ($fullTemp.Contains('%')) {
throw "-Temp '$fullTemp' contains '%', which cmd.exe expands in the generated _build.cmd. Choose a -Temp folder without % in its path."
}
if (-not $Keep) {

View File

@ -17,7 +17,7 @@ import unittest
SCRIPTS = Path(__file__).resolve().parents[1] / "scripts"
def run_ps(script, *args):
def run_ps(script, *args, cwd=None):
# Without the check the scripts would go on to a real build. Hide git, python and vswhere from them (PATH keeps
# only the system folders, ProgramFiles(x86) points nowhere), so they stop at "wasn't found" instead.
system = os.path.join(os.environ.get("SystemRoot", r"C:\Windows"), "System32")
@ -26,7 +26,7 @@ def run_ps(script, *args):
return subprocess.run(
[os.path.join(system, "WindowsPowerShell", "v1.0", "powershell.exe"), "-NoProfile", "-NonInteractive",
"-ExecutionPolicy", "Bypass", "-File", str(script), *args],
capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=60, env=env,
capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=60, env=env, cwd=cwd,
)
@ -54,6 +54,14 @@ class PercentPathTest(unittest.TestCase):
self.assertIn("contains '%'", r.stderr + r.stdout)
self.assertFalse(temp.exists())
def test_build_llvm_mc_refuses_a_relative_temp_under_a_percent_folder(self):
cwd = self.dir / "c%d"
cwd.mkdir()
r = run_ps(SCRIPTS / "build_llvm_mc.ps1", "-Temp", "tmp", "-Dest", str(self.dir / "dest"), "-NoEnv", cwd=cwd)
self.assertNotEqual(r.returncode, 0)
self.assertIn("contains '%'", r.stderr + r.stdout)
self.assertFalse((cwd / "tmp").exists())
if __name__ == "__main__":
unittest.main()