Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Use absolute and shortened path for GOROOT environment variable #1647

Merged
merged 3 commits into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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