diff --git a/go/tools/builders/BUILD.bazel b/go/tools/builders/BUILD.bazel index e581bed9cd..391f7535c9 100644 --- a/go/tools/builders/BUILD.bazel +++ b/go/tools/builders/BUILD.bazel @@ -142,7 +142,10 @@ go_tool_binary( "flags.go", "replicate.go", "stdlib.go", - ], + ] + select({ + "@bazel_tools//src/conditions:windows": ["path_windows.go"], + "//conditions:default": ["path.go"], + }), visibility = ["//visibility:public"], ) diff --git a/go/tools/builders/link.go b/go/tools/builders/link.go index 12cd5a88b0..965fe0f3e3 100644 --- a/go/tools/builders/link.go +++ b/go/tools/builders/link.go @@ -155,7 +155,7 @@ func buildImportcfgFile(archives []archive, packageList, installSuffix, dir stri if line == "" { continue } - fmt.Fprintf(buf, "packagefile %s=%s/%s.a\n", line, prefix, filepath.FromSlash(line)) + fmt.Fprintf(buf, "packagefile %s=%s.a\n", line, filepath.Join(prefix, filepath.FromSlash(line))) } if err := scanner.Err(); err != nil { return "", err diff --git a/go/tools/builders/path.go b/go/tools/builders/path.go new file mode 100644 index 0000000000..f60e4deb36 --- /dev/null +++ b/go/tools/builders/path.go @@ -0,0 +1,7 @@ +// +build !windows + +package main + +func processPath(path string) (string, error) { + return path, nil +} diff --git a/go/tools/builders/path_windows.go b/go/tools/builders/path_windows.go new file mode 100644 index 0000000000..23b1b65b50 --- /dev/null +++ b/go/tools/builders/path_windows.go @@ -0,0 +1,25 @@ +// +build windows + +package main + +import ( + "runtime" + "syscall" +) + +func processPath(path string) (string, error) { + if runtime.GOOS != "windows" { + return path, nil + } + + var buf [258]uint16 + up, err := syscall.UTF16PtrFromString(path) + if err != nil { + return path, err + } + _, err = syscall.GetShortPathName(up, &buf[0], 258) + if err != nil { + return path, err + } + return syscall.UTF16ToString(buf[:]), nil +} diff --git a/go/tools/builders/stdlib.go b/go/tools/builders/stdlib.go index 2152ae4378..82944b7296 100644 --- a/go/tools/builders/stdlib.go +++ b/go/tools/builders/stdlib.go @@ -55,6 +55,11 @@ func run(args []string) error { return err } + output, err = processPath(output) + if err != nil { + return err + } + // Now switch to the newly created GOROOT os.Setenv("GOROOT", output)