Files
Vintner/internal/wrapper/clpost_test.go
T
Cheviiot 91471397fa Fix toolrelay.exe's mt.exe detection: it never matched a real path
IsMtExe() looked for the last '\\' in the target executable path to
find the bare filename, but vintner passes toolExePath straight from
Go's filepath.Join (forward slashes) all the way through to
CreateProcessW - so the path toolrelay.exe actually receives has no
backslash in it at all, and IsMtExe() compared the *entire path*
against "mt.exe", which of course never matched. The whole point of
this file - translating mt.exe's CMake-compatibility exit code
(0x41020001 -> 0xbb) before Wine's own exit-code truncation destroys
it - has silently never fired in real usage.

This had gone unnoticed because MSBuild's rawStdout path bypasses
toolrelay.exe entirely, and every real end-to-end test so far
(msbuild-driven builds, including the KMDF driver) went through that
path. Found while getting a CMake+Ninja-generated MSVC build of a
real project (Ogre3D) past its `cmake -E vs_link_exe` manifest step,
which depends on exactly this translation.

Now checks for both '\\' and '/' and uses whichever separator occurs
last in the path. Verified directly: `mt /manifest ... /notify_update`
through the wrapper now exits 187 (0xbb) instead of 1, and the Ogre
build gets past the manifest-embedding step it was failing at.
2026-07-25 11:55:05 +10:00

62 lines
1.7 KiB
Go

package wrapper
import (
"os"
"path/filepath"
"testing"
)
func TestClPostProcessRewritesLineDirectivesInPreprocessedOutput(t *testing.T) {
dir := t.TempDir()
fi := filepath.Join(dir, "out.i")
// A #line directive as cl.exe's /P emits it: z:-prefixed, backslash
// path, doubled ("escaped") backslashes, CRLF line ending.
input := "#line 1 \"z:\\\\home\\\\user\\\\src\\\\hello.c\"\r\n" +
"int main(void) { return 0; }\r\n"
if err := os.WriteFile(fi, []byte(input), 0o644); err != nil {
t.Fatal(err)
}
clPostProcess([]string{"/P", "/Fi" + fi, "hello.c"})
got, err := os.ReadFile(fi)
if err != nil {
t.Fatal(err)
}
want := "#line 1 \"/home/user/src/hello.c\"\n" +
"int main(void) { return 0; }\n"
if string(got) != want {
t.Errorf("clPostProcess output = %q, want %q", got, want)
}
}
func TestClPostProcessNoopWithoutP(t *testing.T) {
dir := t.TempDir()
fi := filepath.Join(dir, "out.i")
original := "#line 1 \"z:\\\\foo.c\"\r\n"
if err := os.WriteFile(fi, []byte(original), 0o644); err != nil {
t.Fatal(err)
}
// No "/P" flag - should leave the file untouched even though -Fi is present.
clPostProcess([]string{"/Fi" + fi, "foo.c"})
got, err := os.ReadFile(fi)
if err != nil {
t.Fatal(err)
}
if string(got) != original {
t.Errorf("file was modified without /P: got %q, want unchanged %q", got, original)
}
}
func TestClPostProcessNoopWithoutFi(t *testing.T) {
// Must not panic or error when -Fi wasn't passed - just silently skip.
clPostProcess([]string{"/P", "foo.c"})
}
func TestClPostProcessMissingFileIsSilent(t *testing.T) {
// The referenced -Fi file doesn't exist - clPostProcess must not panic.
clPostProcess([]string{"/P", "/Fi" + filepath.Join(t.TempDir(), "missing.i"), "foo.c"})
}