From 593d8b0c1409d044472a2848de199eec498100b1 Mon Sep 17 00:00:00 2001 From: Dave Cheney Date: Thu, 10 Jan 2013 09:57:01 +1100 Subject: [PATCH] cmd/go: remove $GOROOT as a go get target 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 | 33 +++++++++++++++++++++++++-------- src/cmd/go/doc.go | 2 +- src/cmd/go/get.go | 19 ++++++++++--------- src/cmd/go/help.go | 2 +- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/doc/go1.1.html b/doc/go1.1.html index 4aa5fa55da..49ee97b1c4 100644 --- a/doc/go1.1.html +++ b/doc/go1.1.html @@ -72,21 +72,38 @@ Functions written in assembly will need to be revised at least to adjust frame pointer offsets.

-

Data race detector

+

Changes to the go tool

-

-The implementation now includes a built-in data race detector. +

The go tool has acquired several improvements which are intended to improve the experience for new Go users.

+ +

Firstly, when compiling, testing, or running Go code, the go tool will now give more detailed errors messages, including a list of paths searched, when a package cannot be located.

-

Symbol table

+
+$ 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) 
+

-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 go get command no longer allows $GOROOT as the default destination when downloading package source. To use go get command, a valid $GOPATH is now required. +

+ +
+$ 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 
+
+ +

Finally, as a result of the previous change, the go get command will also fail when $GOPATH and $GOROOT are set to the same value.

+
+$ 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
+
+

Changes to the standard library

debug/elf

diff --git a/src/cmd/go/doc.go b/src/cmd/go/doc.go index 18c5e8818c..09cf9a7f19 100644 --- a/src/cmd/go/doc.go +++ b/src/cmd/go/doc.go @@ -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: diff --git a/src/cmd/go/get.go b/src/cmd/go/get.go index 0abb2d5288..abcc2ba434 100644 --- a/src/cmd/go/get.go +++ b/src/cmd/go/get.go @@ -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. diff --git a/src/cmd/go/help.go b/src/cmd/go/help.go index 7539753af0..6d2bd7dbb9 100644 --- a/src/cmd/go/help.go +++ b/src/cmd/go/help.go @@ -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: -- 2.48.1