]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: remove $GOROOT as a go get target
authorDave Cheney <dave@cheney.net>
Wed, 9 Jan 2013 22:57:01 +0000 (09:57 +1100)
committerDave Cheney <dave@cheney.net>
Wed, 9 Jan 2013 22:57:01 +0000 (09:57 +1100)
Fixes #4186.

Back in the day, before the Go 1.0 release, $GOROOT was mandatory for building from source. Fast forward to now and $GOPATH is mandatory and $GOROOT is optional, and mainly used by those who use the binary distribution in uncommon places.

For example, most novices at least know about `sudo` as they would have used it to install the binary tarball into /usr/local. It is logical they would use the `sudo` hammer to `go get` other Go packages when faced with a permission error talking about the path they just had to use `sudo` on last time.

Even if they had read the documentation and set $GOPATH, go get will not work as expected as `sudo` masks most environment variables.

llucky(~) % ~/go/bin/go env | grep GOPATH
GOPATH="/home/dfc"
lucky(~) % sudo ~/go/bin/go env | grep GOPATH
GOPATH=""

This CL therefore proposes to remove support for using `go get` to download source into $GOROOT.

This CL also proposes an error when GOPATH=$GOROOT, as this is another place where new Go users can get stuck.

Further discussion: https://groups.google.com/d/topic/golang-nuts/VIg3fjHiHRI/discussion

R=rsc, adg, minux.ma
CC=golang-dev
https://golang.org/cl/6941058

doc/go1.1.html
src/cmd/go/doc.go
src/cmd/go/get.go
src/cmd/go/help.go

index 4aa5fa55daa04dc7238b53ac8fcb49c732490dd1..49ee97b1c438a58aa925c9dc971f60e15c399417 100644 (file)
@@ -72,21 +72,38 @@ Functions written in assembly will need to be revised at least
 to adjust frame pointer offsets.
 </p>
 
-<h3 id="race">Data race detector</h3>
+<h3 id="gotool">Changes to the go tool</h3>
 
-<p>
-The implementation now includes a built-in <a href="/doc/articles/race_detector.html">data race detector</a>.
+<p>The <code>go</code> tool has acquired several improvements which are intended to improve the experience for new Go users.</p>
+
+<p>Firstly, when compiling, testing, or running Go code, the <code>go</code> tool will now give more detailed errors messages, including a list of paths searched, when a package cannot be located.
 </p>
 
-<h3 id="symtab">Symbol table</h3>
+<pre>
+$ go build foo/quxx
+can't load package: package foo/quxx: cannot find package "foo/quxx" in any of:
+        /home/User/go/src/pkg/foo/quxx (from $GOROOT)
+        /home/User/src/foo/quxx (from $GOPATH) 
+</pre>
 
 <p>
-In the gc toolchain, the symbol table format has been extended to allow
-little-endian encoding of symbol values, and the extension is used in
-binaries generated by the Go 1.1 version of the gc linker.
-To the Go 1.0 toolchain and libraries, these new symbol tables appear empty.
+Secondly, the <code>go get</code> command no longer allows <code>$GOROOT</code> as the default destination when downloading package source. To use <code>go get</code> command, a valid <code>$GOPATH</code> is now required.
+</p>
+
+<pre>
+$ GOPATH= go get code.google.com/p/foo/quxx
+package code.google.com/p/foo/quxx: cannot download, $GOPATH not set. For more details see: go help gopath 
+</pre>
+
+<p>Finally, as a result of the previous change, the <code>go get</code> command will also fail when <code>$GOPATH</code> and <code>$GOROOT</code> are set to the same value. 
 </p>
 
+<pre>
+$ GOPATH=$GOROOT go get code.google.com/p/foo/quxx
+warning: GOPATH set to GOROOT (/home/User/go) has no effect
+package code.google.com/p/foo/quxx: cannot download, $GOPATH must not be set to $GOROOT. For more details see: go help gopath
+</pre>
+
 <h2 id="library">Changes to the standard library</h2>
 
 <h3 id="debug/elf">debug/elf</h3>
index 18c5e8818cfc5d340dc369dfb87354a04bfc6ccf..09cf9a7f197efea9868017192b9e0db556f7172e 100644 (file)
@@ -453,7 +453,7 @@ On Unix, the value is a colon-separated string.
 On Windows, the value is a semicolon-separated string.
 On Plan 9, the value is a list.
 
-GOPATH must be set to build and install packages outside the
+GOPATH must be set to get, build and install packages outside the
 standard Go tree.
 
 Each directory listed in GOPATH must have a prescribed structure:
index 0abb2d5288f917f310c5adbdd96d87b713969f42..abcc2ba4346d52c04c17cc581e60567482731bee 100644 (file)
@@ -247,16 +247,17 @@ func downloadPackage(p *Package) error {
        }
 
        if p.build.SrcRoot == "" {
-               // Package not found.  Put in first directory of $GOPATH or else $GOROOT.
-               // Guard against people setting GOPATH=$GOROOT.  We have to use
-               // $GOROOT's directory hierarchy (src/pkg, not just src) in that case.
-               if list := filepath.SplitList(buildContext.GOPATH); len(list) > 0 && list[0] != goroot {
-                       p.build.SrcRoot = filepath.Join(list[0], "src")
-                       p.build.PkgRoot = filepath.Join(list[0], "pkg")
-               } else {
-                       p.build.SrcRoot = filepath.Join(goroot, "src", "pkg")
-                       p.build.PkgRoot = filepath.Join(goroot, "pkg")
+               // Package not found.  Put in first directory of $GOPATH.
+               list := filepath.SplitList(buildContext.GOPATH)
+               if len(list) == 0 {
+                       return fmt.Errorf("cannot download, $GOPATH not set. For more details see: go help gopath")
                }
+               // Guard against people setting GOPATH=$GOROOT.
+               if list[0] == goroot {
+                       return fmt.Errorf("cannot download, $GOPATH must not be set to $GOROOT. For more details see: go help gopath")
+               }
+               p.build.SrcRoot = filepath.Join(list[0], "src")
+               p.build.PkgRoot = filepath.Join(list[0], "pkg")
        }
        root := filepath.Join(p.build.SrcRoot, rootPath)
        // If we've considered this repository already, don't do it again.
index 7539753af0a39c32557e04b64c26a7e2329888eb..6d2bd7dbb9bd3a5c7e454eb2bedc27effa578f45 100644 (file)
@@ -186,7 +186,7 @@ On Unix, the value is a colon-separated string.
 On Windows, the value is a semicolon-separated string.
 On Plan 9, the value is a list.
 
-GOPATH must be set to build and install packages outside the
+GOPATH must be set to get, build and install packages outside the
 standard Go tree.
 
 Each directory listed in GOPATH must have a prescribed structure: