diff options
author | Jay Conrod <jayconrod@google.com> | 2019-04-25 14:11:42 -0400 |
---|---|---|
committer | Jay Conrod <jayconrod@google.com> | 2019-04-25 21:41:24 +0000 |
commit | 2d660fb8a000e1c288dc2f2150401b364922ebe9 (patch) | |
tree | d175f3bc6cae3caa592cd7c4688705db7f306835 /imports | |
parent | e54115a0622c5325aff9076ff6116307d9e5cbbc (diff) | |
download | golang-x-tools-2d660fb8a000e1c288dc2f2150401b364922ebe9.tar.gz |
go/packages/packagestest: fix GOPROXY file URLs for Windows
Amends prematurely submitted CL 173918. We now use file:/// URLs for
go1.13 and later and file:// URLs for go1.12 and earlier.
Fixes golang/go#31675
Change-Id: I009c63a900bdfd091bf46def5cea5a0843639b47
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173919
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Diffstat (limited to 'imports')
-rw-r--r-- | imports/mod_test.go | 2 | ||||
-rw-r--r-- | imports/proxy_112_test.go | 20 | ||||
-rw-r--r-- | imports/proxy_113_test.go | 24 |
3 files changed, 45 insertions, 1 deletions
diff --git a/imports/mod_test.go b/imports/mod_test.go index a6bf8d6df..f2fb76e21 100644 --- a/imports/mod_test.go +++ b/imports/mod_test.go @@ -519,7 +519,7 @@ func setup(t *testing.T, main, wd string) *modTest { GOROOT: build.Default.GOROOT, GOPATH: filepath.Join(dir, "gopath"), GO111MODULE: "on", - GOPROXY: "file://" + filepath.ToSlash(proxyDir), + GOPROXY: proxyDirToURL(proxyDir), WorkingDir: filepath.Join(mainDir, wd), } diff --git a/imports/proxy_112_test.go b/imports/proxy_112_test.go new file mode 100644 index 000000000..732879a15 --- /dev/null +++ b/imports/proxy_112_test.go @@ -0,0 +1,20 @@ +// +build !go1.13 + +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package imports + +import "path/filepath" + +// TODO: use proxy functionality in golang.org/x/tools/go/packages/packagestest +// instead of copying it here. + +func proxyDirToURL(dir string) string { + // Prior to go1.13, the Go command on Windows only accepted GOPROXY file URLs + // of the form file://C:/path/to/proxy. This was incorrect: when parsed, "C:" + // is interpreted as the host. See golang.org/issue/6027. This has been + // fixed in go1.13, but we emit the old format for old releases. + return "file://" + filepath.ToSlash(dir) +} diff --git a/imports/proxy_113_test.go b/imports/proxy_113_test.go new file mode 100644 index 000000000..f6f6be580 --- /dev/null +++ b/imports/proxy_113_test.go @@ -0,0 +1,24 @@ +// +build go1.13 + +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package imports + +import ( + "path/filepath" + "strings" +) + +// TODO: use proxy functionality in golang.org/x/tools/go/packages/packagestest +// instead of copying it here. + +func proxyDirToURL(dir string) string { + // file URLs on Windows must start with file:///. See golang.org/issue/6027. + path := filepath.ToSlash(dir) + if !strings.HasPrefix(path, "/") { + path = "/" + path + } + return "file://" + path +} |