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:
Cheviiot
2026-07-25 11:55:05 +10:00
parent 94a19e6b43
commit 91471397fa
8 changed files with 696 additions and 2 deletions
+59
View File
@@ -0,0 +1,59 @@
package download
import (
"os"
"path/filepath"
"testing"
"time"
)
func TestRetryBackoff(t *testing.T) {
for _, tc := range []struct {
attempt int
want time.Duration
}{
{1, 1 * time.Second},
{2, 2 * time.Second},
{3, 4 * time.Second},
{4, 8 * time.Second},
{5, 10 * time.Second}, // capped
{10, 10 * time.Second},
} {
if got := retryBackoff(tc.attempt); got != tc.want {
t.Errorf("retryBackoff(%d) = %v, want %v", tc.attempt, got, tc.want)
}
}
}
func TestSHA256File(t *testing.T) {
path := filepath.Join(t.TempDir(), "f")
if err := os.WriteFile(path, []byte("hello"), 0o644); err != nil {
t.Fatal(err)
}
got, err := sha256File(path)
if err != nil {
t.Fatal(err)
}
// echo -n hello | sha256sum
want := "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
if got != want {
t.Errorf("sha256File(hello) = %q, want %q", got, want)
}
}
func TestEqualFoldHex(t *testing.T) {
for _, tc := range []struct {
a, b string
want bool
}{
{"ABCDEF", "abcdef", true},
{"abc123", "ABC123", true},
{"abc123", "abc124", false},
{"abc", "abcd", false},
{"", "", true},
} {
if got := equalFoldHex(tc.a, tc.b); got != tc.want {
t.Errorf("equalFoldHex(%q, %q) = %v, want %v", tc.a, tc.b, got, tc.want)
}
}
}