mirror of
https://github.com/golang/go
synced 2024-09-24 03:10:16 -06:00
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
This commit is contained in:
parent
5ca4f5e483
commit
593d8b0c14
@ -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>
|
||||
|
@ -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:
|
||||
|
@ -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.
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user