Commit 81dfcba3 authored by Edward Muller's avatar Edward Muller Committed by Rob Pike

go/build: add help info for unset $GOPATH

We relay this info in a few places, in a few different ways, but not
consistently everywhere.  This led one of our users to start googling
and not find https://golang.org/doc/code.html#Workspaces, of which `go
help gopath` is the most equivalent.

Change-Id: I28a94375739f3aa4f200e145293ca2a5f65101e1
Reviewed-on: https://go-review.googlesource.com/28690
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRob Pike <r@golang.org>
parent 1ff19201
...@@ -149,7 +149,7 @@ $ <b>export PATH=$PATH:$GOPATH/bin</b> ...@@ -149,7 +149,7 @@ $ <b>export PATH=$PATH:$GOPATH/bin</b>
<p> <p>
To learn more about setting up the <code>GOPATH</code> environment variable, To learn more about setting up the <code>GOPATH</code> environment variable,
please see please see
<a href="/cmd/go/#hdr-GOPATH_environment_variable"><code>go help gopath</code></a> <a href="/cmd/go/#hdr-GOPATH_environment_variable"><code>'go help gopath'</code></a>
</p> </p>
<h3 id="ImportPaths">Import paths</h3> <h3 id="ImportPaths">Import paths</h3>
......
...@@ -514,7 +514,7 @@ ...@@ -514,7 +514,7 @@
// //
// When checking out a new package, get creates the target directory // When checking out a new package, get creates the target directory
// GOPATH/src/<import-path>. If the GOPATH contains multiple entries, // GOPATH/src/<import-path>. If the GOPATH contains multiple entries,
// get uses the first one. See 'go help gopath'. // get uses the first one. For more details see: 'go help gopath'.
// //
// When checking out or updating a package, get looks for a branch or tag // When checking out or updating a package, get looks for a branch or tag
// that matches the locally installed version of Go. The most important // that matches the locally installed version of Go. The most important
...@@ -1074,7 +1074,7 @@ ...@@ -1074,7 +1074,7 @@
// The operating system for which to compile code. // The operating system for which to compile code.
// Examples are linux, darwin, windows, netbsd. // Examples are linux, darwin, windows, netbsd.
// GOPATH // GOPATH
// See 'go help gopath'. // For more details see: 'go help gopath'.
// GORACE // GORACE
// Options for the race detector. // Options for the race detector.
// See https://golang.org/doc/articles/race_detector.html. // See https://golang.org/doc/articles/race_detector.html.
...@@ -1125,10 +1125,10 @@ ...@@ -1125,10 +1125,10 @@
// //
// Import path syntax // Import path syntax
// //
// An import path (see 'go help packages') denotes a package // An import path (see 'go help packages') denotes a package stored in the local
// stored in the local file system. In general, an import path denotes // file system. In general, an import path denotes either a standard package (such
// either a standard package (such as "unicode/utf8") or a package // as "unicode/utf8") or a package found in one of the work spaces (For more
// found in one of the work spaces (see 'go help gopath'). // details see: 'go help gopath').
// //
// Relative import paths // Relative import paths
// //
...@@ -1260,8 +1260,8 @@ ...@@ -1260,8 +1260,8 @@
// same meta tag and then git clone https://code.org/r/p/exproj into // same meta tag and then git clone https://code.org/r/p/exproj into
// GOPATH/src/example.org. // GOPATH/src/example.org.
// //
// New downloaded packages are written to the first directory // New downloaded packages are written to the first directory listed in the GOPATH
// listed in the GOPATH environment variable (see 'go help gopath'). // environment variable (For more details see: 'go help gopath').
// //
// The go command attempts to download the version of the // The go command attempts to download the version of the
// package appropriate for the Go release being used. // package appropriate for the Go release being used.
...@@ -1305,7 +1305,7 @@ ...@@ -1305,7 +1305,7 @@
// //
// Otherwise, the import path P denotes the package found in // Otherwise, the import path P denotes the package found in
// the directory DIR/src/P for some DIR listed in the GOPATH // the directory DIR/src/P for some DIR listed in the GOPATH
// environment variable (see 'go help gopath'). // environment variable (For more details see: 'go help gopath').
// //
// If no import paths are given, the action applies to the // If no import paths are given, the action applies to the
// package in the current directory. // package in the current directory.
......
...@@ -605,7 +605,7 @@ func installPackages(args []string, forGet bool) { ...@@ -605,7 +605,7 @@ func installPackages(args []string, forGet bool) {
errorf("go install: no install location for %s: hidden by %s", p.Dir, p.ConflictDir) errorf("go install: no install location for %s: hidden by %s", p.Dir, p.ConflictDir)
default: default:
errorf("go install: no install location for directory %s outside GOPATH\n"+ errorf("go install: no install location for directory %s outside GOPATH\n"+
"\tFor more details see: go help gopath", p.Dir) "\tFor more details see: 'go help gopath'", p.Dir)
} }
} }
} }
......
...@@ -49,7 +49,7 @@ Get also accepts build flags to control the installation. See 'go help build'. ...@@ -49,7 +49,7 @@ Get also accepts build flags to control the installation. See 'go help build'.
When checking out a new package, get creates the target directory When checking out a new package, get creates the target directory
GOPATH/src/<import-path>. If the GOPATH contains multiple entries, GOPATH/src/<import-path>. If the GOPATH contains multiple entries,
get uses the first one. See 'go help gopath'. get uses the first one. For more details see: 'go help gopath'.
When checking out or updating a package, get looks for a branch or tag When checking out or updating a package, get looks for a branch or tag
that matches the locally installed version of Go. The most important that matches the locally installed version of Go. The most important
...@@ -393,11 +393,11 @@ func downloadPackage(p *Package) error { ...@@ -393,11 +393,11 @@ func downloadPackage(p *Package) error {
// Package not found. Put in first directory of $GOPATH. // Package not found. Put in first directory of $GOPATH.
list := filepath.SplitList(buildContext.GOPATH) list := filepath.SplitList(buildContext.GOPATH)
if len(list) == 0 { if len(list) == 0 {
return fmt.Errorf("cannot download, $GOPATH not set. For more details see: go help gopath") return fmt.Errorf("cannot download, $GOPATH not set. For more details see: 'go help gopath'")
} }
// Guard against people setting GOPATH=$GOROOT. // Guard against people setting GOPATH=$GOROOT.
if list[0] == goroot { if list[0] == goroot {
return fmt.Errorf("cannot download, $GOPATH must not be set to $GOROOT. For more details see: go help gopath") 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.SrcRoot = filepath.Join(list[0], "src")
p.build.PkgRoot = filepath.Join(list[0], "pkg") p.build.PkgRoot = filepath.Join(list[0], "pkg")
......
...@@ -1622,8 +1622,8 @@ func TestMissingGOPATHIsReported(t *testing.T) { ...@@ -1622,8 +1622,8 @@ func TestMissingGOPATHIsReported(t *testing.T) {
defer tg.cleanup() defer tg.cleanup()
tg.setenv("GOPATH", "") tg.setenv("GOPATH", "")
tg.runFail("install", "foo/quxx") tg.runFail("install", "foo/quxx")
if tg.grepCountBoth(`\(\$GOPATH not set\)$`) != 1 { if tg.grepCountBoth(`\(\$GOPATH not set\. For more details see: 'go help gopath'\)$`) != 1 {
t.Error(`go install foo/quxx expected error: ($GOPATH not set)`) t.Error(`go install foo/quxx expected error: ($GOPATH not set. For more details see: 'go help gopath')`)
} }
} }
......
...@@ -42,7 +42,7 @@ denotes the package in that directory. ...@@ -42,7 +42,7 @@ denotes the package in that directory.
Otherwise, the import path P denotes the package found in Otherwise, the import path P denotes the package found in
the directory DIR/src/P for some DIR listed in the GOPATH the directory DIR/src/P for some DIR listed in the GOPATH
environment variable (see 'go help gopath'). environment variable (For more details see: 'go help gopath').
If no import paths are given, the action applies to the If no import paths are given, the action applies to the
package in the current directory. package in the current directory.
...@@ -102,10 +102,10 @@ var helpImportPath = &Command{ ...@@ -102,10 +102,10 @@ var helpImportPath = &Command{
Short: "import path syntax", Short: "import path syntax",
Long: ` Long: `
An import path (see 'go help packages') denotes a package An import path (see 'go help packages') denotes a package stored in the local
stored in the local file system. In general, an import path denotes file system. In general, an import path denotes either a standard package (such
either a standard package (such as "unicode/utf8") or a package as "unicode/utf8") or a package found in one of the work spaces (For more
found in one of the work spaces (see 'go help gopath'). details see: 'go help gopath').
Relative import paths Relative import paths
...@@ -237,8 +237,8 @@ the go tool will verify that https://example.org/?go-get=1 contains the ...@@ -237,8 +237,8 @@ the go tool will verify that https://example.org/?go-get=1 contains the
same meta tag and then git clone https://code.org/r/p/exproj into same meta tag and then git clone https://code.org/r/p/exproj into
GOPATH/src/example.org. GOPATH/src/example.org.
New downloaded packages are written to the first directory New downloaded packages are written to the first directory listed in the GOPATH
listed in the GOPATH environment variable (see 'go help gopath'). environment variable (For more details see: 'go help gopath').
The go command attempts to download the version of the The go command attempts to download the version of the
package appropriate for the Go release being used. package appropriate for the Go release being used.
...@@ -439,7 +439,7 @@ General-purpose environment variables: ...@@ -439,7 +439,7 @@ General-purpose environment variables:
The operating system for which to compile code. The operating system for which to compile code.
Examples are linux, darwin, windows, netbsd. Examples are linux, darwin, windows, netbsd.
GOPATH GOPATH
See 'go help gopath'. For more details see: 'go help gopath'.
GORACE GORACE
Options for the race detector. Options for the race detector.
See https://golang.org/doc/articles/race_detector.html. See https://golang.org/doc/articles/race_detector.html.
......
...@@ -147,7 +147,7 @@ func main() { ...@@ -147,7 +147,7 @@ func main() {
os.Exit(2) os.Exit(2)
} }
if !filepath.IsAbs(p) { if !filepath.IsAbs(p) {
fmt.Fprintf(os.Stderr, "go: GOPATH entry is relative; must be absolute path: %q.\nRun 'go help gopath' for usage.\n", p) fmt.Fprintf(os.Stderr, "go: GOPATH entry is relative; must be absolute path: %q.\nFor more details see: 'go help gopath'\n", p)
os.Exit(2) os.Exit(2)
} }
} }
......
...@@ -636,7 +636,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa ...@@ -636,7 +636,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa
format = "\t%s" format = "\t%s"
} }
if len(tried.gopath) == 0 { if len(tried.gopath) == 0 {
paths = append(paths, "\t($GOPATH not set)") paths = append(paths, "\t($GOPATH not set. For more details see: 'go help gopath')")
} }
return p, fmt.Errorf("cannot find package %q in any of:\n%s", path, strings.Join(paths, "\n")) return p, fmt.Errorf("cannot find package %q in any of:\n%s", path, strings.Join(paths, "\n"))
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment