Skip to content

Commit

Permalink
Windows: Use absolute and shortened path for GOROOT environment varia…
Browse files Browse the repository at this point in the history
…ble (#1647)
  • Loading branch information
Xjs authored and jayconrod committed Aug 15, 2018
1 parent f6c1878 commit ebb0ab7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
5 changes: 4 additions & 1 deletion go/tools/builders/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)

Expand Down
2 changes: 1 addition & 1 deletion go/tools/builders/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions go/tools/builders/path.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build !windows

package main

func processPath(path string) (string, error) {
return path, nil
}
25 changes: 25 additions & 0 deletions go/tools/builders/path_windows.go
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions go/tools/builders/stdlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit ebb0ab7

Please sign in to comment.