mirror of
https://github.com/golang/go
synced 2024-11-20 04:44:40 -07:00
cmd/go: ignore empty path elements in GOPATH
go command refuses to use GOPATH with empty path elements (like %GOPATH%=C:\go;). But environment variable change dialog on Windows 10 produces strings ending with ; (see issue #21928 for a picture). Just accept GOPATH with empty path elements, and ignore all empty path elements. Fixes #21928 Change-Id: I1d3c3a19274ed69204d29ae06c3e8ff8c57c1ca0 Reviewed-on: https://go-review.googlesource.com/65151 Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
e6358c798b
commit
18b49db18e
@ -1689,6 +1689,27 @@ func TestRejectRelativePathsInGOPATHCommandLinePackage(t *testing.T) {
|
|||||||
tg.grepStderr("GOPATH entry is relative", "expected an error message rejecting relative GOPATH entries")
|
tg.grepStderr("GOPATH entry is relative", "expected an error message rejecting relative GOPATH entries")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue 21928.
|
||||||
|
func TestRejectBlankPathsInGOPATH(t *testing.T) {
|
||||||
|
tg := testgo(t)
|
||||||
|
defer tg.cleanup()
|
||||||
|
sep := string(filepath.ListSeparator)
|
||||||
|
tg.setenv("GOPATH", " "+sep+filepath.Join(tg.pwd(), "testdata"))
|
||||||
|
tg.runFail("build", "go-cmd-test")
|
||||||
|
tg.grepStderr("GOPATH entry is relative", "expected an error message rejecting relative GOPATH entries")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Issue 21928.
|
||||||
|
func TestIgnoreEmptyPathsInGOPATH(t *testing.T) {
|
||||||
|
tg := testgo(t)
|
||||||
|
defer tg.cleanup()
|
||||||
|
tg.creatingTemp("testdata/bin/go-cmd-test" + exeSuffix)
|
||||||
|
sep := string(filepath.ListSeparator)
|
||||||
|
tg.setenv("GOPATH", ""+sep+filepath.Join(tg.pwd(), "testdata"))
|
||||||
|
tg.run("install", "go-cmd-test")
|
||||||
|
tg.wantExecutable("testdata/bin/go-cmd-test"+exeSuffix, "go install go-cmd-test did not write to testdata/bin/go-cmd-test")
|
||||||
|
}
|
||||||
|
|
||||||
// Issue 4104.
|
// Issue 4104.
|
||||||
func TestGoTestWithPackageListedMultipleTimes(t *testing.T) {
|
func TestGoTestWithPackageListedMultipleTimes(t *testing.T) {
|
||||||
tg := testgo(t)
|
tg := testgo(t)
|
||||||
|
@ -89,6 +89,11 @@ func main() {
|
|||||||
fmt.Fprintf(os.Stderr, "warning: GOPATH set to GOROOT (%s) has no effect\n", gopath)
|
fmt.Fprintf(os.Stderr, "warning: GOPATH set to GOROOT (%s) has no effect\n", gopath)
|
||||||
} else {
|
} else {
|
||||||
for _, p := range filepath.SplitList(gopath) {
|
for _, p := range filepath.SplitList(gopath) {
|
||||||
|
// Some GOPATHs have empty directory elements - ignore them.
|
||||||
|
// See issue 21928 for details.
|
||||||
|
if p == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
// Note: using HasPrefix instead of Contains because a ~ can appear
|
// Note: using HasPrefix instead of Contains because a ~ can appear
|
||||||
// in the middle of directory elements, such as /tmp/git-1.8.2~rc3
|
// in the middle of directory elements, such as /tmp/git-1.8.2~rc3
|
||||||
// or C:\PROGRA~1. Only ~ as a path prefix has meaning to the shell.
|
// or C:\PROGRA~1. Only ~ as a path prefix has meaning to the shell.
|
||||||
|
Loading…
Reference in New Issue
Block a user