Skip to content

Commit aa0c01f

Browse files
thanmcagedmantis
authored andcommitted
[release-branch.go1.18] 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 #57704. Fixes #57705. 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]> (cherry picked from commit 771a98d) Reviewed-on: https://go-review.googlesource.com/c/go/+/461176 Reviewed-by: Heschi Kreinick <[email protected]> Reviewed-by: Carlos Amedee <[email protected]>
1 parent 87105e5 commit aa0c01f

File tree

1 file changed

+38
-22
lines changed

1 file changed

+38
-22
lines changed

misc/cgo/testcshared/cshared_test.go

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -317,30 +317,46 @@ func createHeaders() error {
317317
if err != nil {
318318
return fmt.Errorf("unable to find dlltool path: %v\n%s\n", err, out)
319319
}
320-
args := []string{strings.TrimSpace(string(out)), "-D", args[6], "-l", libgoname, "-d", "libgo.def"}
321-
322-
// This is an unfortunate workaround for https://github.com/mstorsjo/llvm-mingw/issues/205 in which
323-
// we basically reimplement the contents of the dlltool.sh wrapper: https://git.io/JZFlU
324-
dlltoolContents, err := os.ReadFile(args[0])
325-
if err != nil {
326-
return fmt.Errorf("unable to read dlltool: %v\n", err)
320+
dlltoolpath := strings.TrimSpace(string(out))
321+
if filepath.Ext(dlltoolpath) == "" {
322+
// Some compilers report slash-separated paths without extensions
323+
// instead of ordinary Windows paths.
324+
// Try to find the canonical name for the path.
325+
if lp, err := exec.LookPath(dlltoolpath); err == nil {
326+
dlltoolpath = lp
327+
}
327328
}
328-
if bytes.HasPrefix(dlltoolContents, []byte("#!/bin/sh")) && bytes.Contains(dlltoolContents, []byte("llvm-dlltool")) {
329-
base, name := filepath.Split(args[0])
330-
args[0] = filepath.Join(base, "llvm-dlltool")
331-
var machine string
332-
switch prefix, _, _ := strings.Cut(name, "-"); prefix {
333-
case "i686":
334-
machine = "i386"
335-
case "x86_64":
336-
machine = "i386:x86-64"
337-
case "armv7":
338-
machine = "arm"
339-
case "aarch64":
340-
machine = "arm64"
329+
330+
args := []string{dlltoolpath, "-D", args[6], "-l", libgoname, "-d", "libgo.def"}
331+
332+
if filepath.Ext(dlltoolpath) == "" {
333+
// This is an unfortunate workaround for
334+
// https://github.com/mstorsjo/llvm-mingw/issues/205 in which
335+
// we basically reimplement the contents of the dlltool.sh
336+
// wrapper: https://git.io/JZFlU.
337+
// TODO(thanm): remove this workaround once we can upgrade
338+
// the compilers on the windows-arm64 builder.
339+
dlltoolContents, err := os.ReadFile(args[0])
340+
if err != nil {
341+
return fmt.Errorf("unable to read dlltool: %v\n", err)
341342
}
342-
if len(machine) > 0 {
343-
args = append(args, "-m", machine)
343+
if bytes.HasPrefix(dlltoolContents, []byte("#!/bin/sh")) && bytes.Contains(dlltoolContents, []byte("llvm-dlltool")) {
344+
base, name := filepath.Split(args[0])
345+
args[0] = filepath.Join(base, "llvm-dlltool")
346+
var machine string
347+
switch prefix, _, _ := strings.Cut(name, "-"); prefix {
348+
case "i686":
349+
machine = "i386"
350+
case "x86_64":
351+
machine = "i386:x86-64"
352+
case "armv7":
353+
machine = "arm"
354+
case "aarch64":
355+
machine = "arm64"
356+
}
357+
if len(machine) > 0 {
358+
args = append(args, "-m", machine)
359+
}
344360
}
345361
}
346362

0 commit comments

Comments
 (0)