Skip to content

Commit 746ec36

Browse files
authored
Use absolute paths in GoPath builder (mainly for Windows compatibility) (bazel-contrib#2642)
Windows has a limit of 256 characters for relative characters when using the syscalls the Go standard library uses. In a Bazel project I encountered recently I couldn't run the GoPath builder because of an google.golang.org/grpc dependency that included the file bazel-out\x64_windows-fastbuild\bin\external\org_golang_google_grpc\reflection\grpc_reflection_v1alpha\grpc_reflection_v1alpha_go_proto_\google.golang.org\grpc\reflection\grpc_reflection_v1alpha\reflection.pb.go, which even with my very short bazel root of C:\tmp\bzl was too long to open, and resulted in the error message GoPath: open bazel-out\x64_windows-fastbuild\bin\external\org_golang_google_grpc\reflection\grpc_reflection_v1alpha\grpc_reflection_v1alpha_go_proto_\google.golang.org\grpc\reflection\grpc_reflection_v1alpha\reflection.pb.go: The system cannot find the path specified. (pasting verbatim so people googling it can find it) Using abs() and FromSlash() like in other builders fixes this issue.
1 parent 75644bd commit 746ec36

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

go/tools/builders/BUILD.bazel

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ go_source(
6969

7070
go_binary(
7171
name = "go_path",
72-
srcs = ["go_path.go"],
72+
srcs = [
73+
"env.go",
74+
"flags.go",
75+
"go_path.go",
76+
],
7377
visibility = ["//visibility:public"],
7478
)
7579

go/tools/builders/go_path.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func archivePath(out string, manifest []manifestEntry) (err error) {
125125
outZip := zip.NewWriter(outFile)
126126

127127
for _, entry := range manifest {
128-
srcFile, err := os.Open(entry.Src)
128+
srcFile, err := os.Open(abs(filepath.FromSlash(entry.Src)))
129129
if err != nil {
130130
return err
131131
}
@@ -158,7 +158,7 @@ func copyPath(out string, manifest []manifestEntry) error {
158158
if err := os.MkdirAll(filepath.Dir(dst), 0777); err != nil {
159159
return err
160160
}
161-
srcFile, err := os.Open(entry.Src)
161+
srcFile, err := os.Open(abs(filepath.FromSlash(entry.Src)))
162162
if err != nil {
163163
return err
164164
}

0 commit comments

Comments
 (0)