Skip to content

Commit

Permalink
go/packages/packagestest: fix GOPROXY file URLs for Windows
Browse files Browse the repository at this point in the history
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 <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Ian Cottrell <[email protected]>
  • Loading branch information
Jay Conrod committed Apr 25, 2019
1 parent e54115a commit 2d660fb
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 10 deletions.
10 changes: 1 addition & 9 deletions go/packages/packagestest/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"path"
"path/filepath"
"regexp"
"strings"

"golang.org/x/tools/go/packages"
)
Expand Down Expand Up @@ -102,13 +101,6 @@ func (modules) Finalize(exported *Exported) error {
return fmt.Errorf("creating module proxy dir for %v: %v", module, err)
}
}
proxyURL := filepath.ToSlash(proxyDir)
if !strings.HasPrefix(proxyURL, "/") {
// Windows paths will look like C:/foo/bar. In the URL, the C: will be
// interpreted as the host, so add a leading /. See golang.org/issue/6027.
proxyURL = "/" + proxyURL
}
proxyURL = "file://" + proxyURL

// Discard the original mod cache dir, which contained the files written
// for us by Export.
Expand All @@ -118,7 +110,7 @@ func (modules) Finalize(exported *Exported) error {
exported.Config.Env = append(exported.Config.Env,
"GO111MODULE=on",
"GOPATH="+filepath.Join(exported.temp, "modcache"),
"GOPROXY=file://"+filepath.ToSlash(proxyDir))
"GOPROXY="+proxyDirToURL(proxyDir))

// Run go mod download to recreate the mod cache dir with all the extra
// stuff in cache. All the files created by Export should be recreated.
Expand Down
17 changes: 17 additions & 0 deletions go/packages/packagestest/modules_112.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// +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 packagestest

import "path/filepath"

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)
}
21 changes: 21 additions & 0 deletions go/packages/packagestest/modules_113.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// +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 packagestest

import (
"path/filepath"
"strings"
)

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
}
2 changes: 1 addition & 1 deletion imports/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down
20 changes: 20 additions & 0 deletions imports/proxy_112_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
24 changes: 24 additions & 0 deletions imports/proxy_113_test.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 2d660fb

Please sign in to comment.