]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: ignore empty path elements in GOPATH
authorAlex Brainman <alex.brainman@gmail.com>
Thu, 21 Sep 2017 02:33:11 +0000 (12:33 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Sun, 24 Sep 2017 01:41:21 +0000 (01:41 +0000)
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>
src/cmd/go/go_test.go
src/cmd/go/main.go

index 1a47b720835956a8506e7319ee8bde1e9a9b5d11..2145ffb2751237bf69a13aae83a05849067ee704 100644 (file)
@@ -1689,6 +1689,27 @@ func TestRejectRelativePathsInGOPATHCommandLinePackage(t *testing.T) {
        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.
 func TestGoTestWithPackageListedMultipleTimes(t *testing.T) {
        tg := testgo(t)
index 75a46db98f2921dc9ff0cb3d591485086e495dbc..f5b64869ea15bb947177a43d6b8a929b6491b58f 100644 (file)
@@ -89,6 +89,11 @@ func main() {
                fmt.Fprintf(os.Stderr, "warning: GOPATH set to GOROOT (%s) has no effect\n", gopath)
        } else {
                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
                        // 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.