Skip to content

Commit 771a98d

Browse files
committed
misc/cgo/testcshared: handle unsuffixed dlltool path
Adapt the testcshared tests to handle the case where the path output by invoking gcc -print-prog-name=dlltool is a path lacking the final ".exe" suffix (this seems to be what clang is doing); tack it on before using if this is the case. Updates #35006. Updates #53540. Change-Id: I04fb7b9fc90677880b1ced4a4ad2a8867a3f5f86 Reviewed-on: https://go-review.googlesource.com/c/go/+/451816 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Than McIntosh <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent bda0235 commit 771a98d

File tree

1 file changed

+38
-22
lines changed

1 file changed

+38
-22
lines changed

misc/cgo/testcshared/cshared_test.go

+38-22
Original file line numberDiff line numberDiff line change
@@ -335,30 +335,46 @@ func createHeaders() error {
335335
if err != nil {
336336
return fmt.Errorf("unable to find dlltool path: %v\n%s\n", err, out)
337337
}
338-
args := []string{strings.TrimSpace(string(out)), "-D", args[6], "-l", libgoname, "-d", "libgo.def"}
339-
340-
// This is an unfortunate workaround for https://github.com/mstorsjo/llvm-mingw/issues/205 in which
341-
// we basically reimplement the contents of the dlltool.sh wrapper: https://git.io/JZFlU
342-
dlltoolContents, err := os.ReadFile(args[0])
343-
if err != nil {
344-
return fmt.Errorf("unable to read dlltool: %v\n", err)
338+
dlltoolpath := strings.TrimSpace(string(out))
339+
if filepath.Ext(dlltoolpath) == "" {
340+
// Some compilers report slash-separated paths without extensions
341+
// instead of ordinary Windows paths.
342+
// Try to find the canonical name for the path.
343+
if lp, err := exec.LookPath(dlltoolpath); err == nil {
344+
dlltoolpath = lp
345+
}
345346
}
346-
if bytes.HasPrefix(dlltoolContents, []byte("#!/bin/sh")) && bytes.Contains(dlltoolContents, []byte("llvm-dlltool")) {
347-
base, name := filepath.Split(args[0])
348-
args[0] = filepath.Join(base, "llvm-dlltool")
349-
var machine string
350-
switch prefix, _, _ := strings.Cut(name, "-"); prefix {
351-
case "i686":
352-
machine = "i386"
353-
case "x86_64":
354-
machine = "i386:x86-64"
355-
case "armv7":
356-
machine = "arm"
357-
case "aarch64":
358-
machine = "arm64"
347+
348+
args := []string{dlltoolpath, "-D", args[6], "-l", libgoname, "-d", "libgo.def"}
349+
350+
if filepath.Ext(dlltoolpath) == "" {
351+
// This is an unfortunate workaround for
352+
// https://github.com/mstorsjo/llvm-mingw/issues/205 in which
353+
// we basically reimplement the contents of the dlltool.sh
354+
// wrapper: https://git.io/JZFlU.
355+
// TODO(thanm): remove this workaround once we can upgrade
356+
// the compilers on the windows-arm64 builder.
357+
dlltoolContents, err := os.ReadFile(args[0])
358+
if err != nil {
359+
return fmt.Errorf("unable to read dlltool: %v\n", err)
359360
}
360-
if len(machine) > 0 {
361-
args = append(args, "-m", machine)
361+
if bytes.HasPrefix(dlltoolContents, []byte("#!/bin/sh")) && bytes.Contains(dlltoolContents, []byte("llvm-dlltool")) {
362+
base, name := filepath.Split(args[0])
363+
args[0] = filepath.Join(base, "llvm-dlltool")
364+
var machine string
365+
switch prefix, _, _ := strings.Cut(name, "-"); prefix {
366+
case "i686":
367+
machine = "i386"
368+
case "x86_64":
369+
machine = "i386:x86-64"
370+
case "armv7":
371+
machine = "arm"
372+
case "aarch64":
373+
machine = "arm64"
374+
}
375+
if len(machine) > 0 {
376+
args = append(args, "-m", machine)
377+
}
362378
}
363379
}
364380

0 commit comments

Comments
 (0)