Skip to content

Commit

Permalink
Move windows-specific path shortening to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
Xjs committed Aug 15, 2018
1 parent 0b665a3 commit 4cf72fa
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 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
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
}
16 changes: 3 additions & 13 deletions go/tools/builders/stdlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import (
"log"
"os"
"path/filepath"
"runtime"
"strings"
"syscall"
)

func run(args []string) error {
Expand Down Expand Up @@ -57,17 +55,9 @@ func run(args []string) error {
return err
}

if runtime.GOOS == "windows" {
var buf [258]uint16
up, err := syscall.UTF16PtrFromString(output)
if err != nil {
return err
}
_, err = syscall.GetShortPathName(up, &buf[0], 258)
if err != nil {
return err
}
output = syscall.UTF16ToString(buf[:])
output, err := processPath(output)
if err != nil {
return err
}

// Now switch to the newly created GOROOT
Expand Down

0 comments on commit 4cf72fa

Please sign in to comment.