mirror of
https://github.com/Cheviiot/Vintner.git
synced 2026-08-03 15:57:24 +00:00
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.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
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"})
|
||||
}
|
||||
Reference in New Issue
Block a user