Skip to content

Commit 14a4138

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
misc/cgo/testcshared: reapply CL 451816
I accidentally reverted its edits with a bad cherry-pick in CL 452457. This should re-fix the windows-.*-newcc builders that regressed at that change. Updates #47257. Updates #35006. Updates #53540. Change-Id: I5818416af7c4c8c1593c36aa0198331b42b6c7d7 Reviewed-on: https://go-review.googlesource.com/c/go/+/452675 Run-TryBot: Bryan Mills <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Auto-Submit: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 1521199 commit 14a4138

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
@@ -323,30 +323,46 @@ func createHeaders() error {
323323
if err != nil {
324324
return fmt.Errorf("unable to find dlltool path: %v\n%s\n", err, out)
325325
}
326-
args := []string{strings.TrimSpace(string(out)), "-D", args[6], "-l", libgoname, "-d", "libgo.def"}
327-
328-
// This is an unfortunate workaround for https://github.com/mstorsjo/llvm-mingw/issues/205 in which
329-
// we basically reimplement the contents of the dlltool.sh wrapper: https://git.io/JZFlU
330-
dlltoolContents, err := os.ReadFile(args[0])
331-
if err != nil {
332-
return fmt.Errorf("unable to read dlltool: %v\n", err)
326+
dlltoolpath := strings.TrimSpace(string(out))
327+
if filepath.Ext(dlltoolpath) == "" {
328+
// Some compilers report slash-separated paths without extensions
329+
// instead of ordinary Windows paths.
330+
// Try to find the canonical name for the path.
331+
if lp, err := exec.LookPath(dlltoolpath); err == nil {
332+
dlltoolpath = lp
333+
}
333334
}
334-
if bytes.HasPrefix(dlltoolContents, []byte("#!/bin/sh")) && bytes.Contains(dlltoolContents, []byte("llvm-dlltool")) {
335-
base, name := filepath.Split(args[0])
336-
args[0] = filepath.Join(base, "llvm-dlltool")
337-
var machine string
338-
switch prefix, _, _ := strings.Cut(name, "-"); prefix {
339-
case "i686":
340-
machine = "i386"
341-
case "x86_64":
342-
machine = "i386:x86-64"
343-
case "armv7":
344-
machine = "arm"
345-
case "aarch64":
346-
machine = "arm64"
335+
336+
args := []string{dlltoolpath, "-D", args[6], "-l", libgoname, "-d", "libgo.def"}
337+
338+
if filepath.Ext(dlltoolpath) == "" {
339+
// This is an unfortunate workaround for
340+
// https://github.com/mstorsjo/llvm-mingw/issues/205 in which
341+
// we basically reimplement the contents of the dlltool.sh
342+
// wrapper: https://git.io/JZFlU.
343+
// TODO(thanm): remove this workaround once we can upgrade
344+
// the compilers on the windows-arm64 builder.
345+
dlltoolContents, err := os.ReadFile(args[0])
346+
if err != nil {
347+
return fmt.Errorf("unable to read dlltool: %v\n", err)
347348
}
348-
if len(machine) > 0 {
349-
args = append(args, "-m", machine)
349+
if bytes.HasPrefix(dlltoolContents, []byte("#!/bin/sh")) && bytes.Contains(dlltoolContents, []byte("llvm-dlltool")) {
350+
base, name := filepath.Split(args[0])
351+
args[0] = filepath.Join(base, "llvm-dlltool")
352+
var machine string
353+
switch prefix, _, _ := strings.Cut(name, "-"); prefix {
354+
case "i686":
355+
machine = "i386"
356+
case "x86_64":
357+
machine = "i386:x86-64"
358+
case "armv7":
359+
machine = "arm"
360+
case "aarch64":
361+
machine = "arm64"
362+
}
363+
if len(machine) > 0 {
364+
args = append(args, "-m", machine)
365+
}
350366
}
351367
}
352368

0 commit comments

Comments
 (0)