]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: reject relative values for GOPATH
authorFrancisco Souza <franciscossouza@gmail.com>
Mon, 17 Sep 2012 20:44:55 +0000 (13:44 -0700)
committerRob Pike <r@golang.org>
Mon, 17 Sep 2012 20:44:55 +0000 (13:44 -0700)
Fixes #4062.

R=rsc, dave, r
CC=golang-dev, nicksaika
https://golang.org/cl/6488129

src/cmd/go/main.go
src/cmd/go/test.bash

index 20585d1beaab63bd1a4c020e48065a31a51aab70..840d584cd02254147bc5962d9a92020c92e06ebf 100644 (file)
@@ -127,6 +127,13 @@ func main() {
        // which is not what most people want when they do it.
        if gopath := os.Getenv("GOPATH"); gopath == runtime.GOROOT() {
                fmt.Fprintf(os.Stderr, "warning: GOPATH set to GOROOT (%s) has no effect\n", gopath)
+       } else {
+               for _, p := range strings.Split(gopath, ":") {
+                       if build.IsLocalImport(p) {
+                               fmt.Fprintf(os.Stderr, "go: GOPATH entry is relative; must be absolute path: %q.\nRun 'go help gopath' for usage.\n", p)
+                               os.Exit(2)
+                       }
+               }
        }
 
        for _, cmd := range commands {
index 587bcfc1f96f7d0207b7abd4c3f8eb01b2b03279..82cbd389cfcaf39f020ca88e0ae83a6f31202f9a 100755 (executable)
@@ -125,6 +125,17 @@ elif ! test -x testdata/bin1/helloworld; then
        ok=false
 fi
 
+# Reject relative paths in GOPATH.
+if GOPATH=. ./testgo build testdata/src/go-cmd-test/helloworld.go; then
+    echo 'GOPATH="." go build should have failed, did not'
+    ok=false
+fi
+
+if GOPATH=:$(pwd)/testdata:. ./testgo build go-cmd-test; then
+    echo 'GOPATH=":$(pwd)/testdata:." go build should have failed, did not'
+    ok=false
+fi
+
 if $ok; then
        echo PASS
 else