mirror of
https://github.com/golang/go
synced 2024-11-25 06:57:58 -07:00
goinstall: report lack of $GOPATH on errors
Fixes #2175. R=alex.brainman, rsc, gustavo, adg CC=golang-dev https://golang.org/cl/4929047
This commit is contained in:
parent
cb51fdc007
commit
0462f77e24
@ -71,6 +71,13 @@ func errorf(format string, args ...interface{}) {
|
|||||||
logf(format, args...)
|
logf(format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func terrorf(tree *build.Tree, format string, args ...interface{}) {
|
||||||
|
if tree != nil && tree.Goroot && os.Getenv("GOPATH") == "" {
|
||||||
|
format = strings.TrimRight(format, "\n") + " ($GOPATH not set)\n"
|
||||||
|
}
|
||||||
|
errorf(format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Usage = usage
|
flag.Usage = usage
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@ -156,7 +163,7 @@ func logPackage(pkg string, tree *build.Tree) (logged bool) {
|
|||||||
name := filepath.Join(tree.Path, logfile)
|
name := filepath.Join(tree.Path, logfile)
|
||||||
fout, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
|
fout, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logf("%s\n", err)
|
terrorf(tree, "package log: %s\n", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
fmt.Fprintf(fout, "%s\n", pkg)
|
fmt.Fprintf(fout, "%s\n", pkg)
|
||||||
@ -215,7 +222,7 @@ func install(pkg, parent string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorf("%s: %v\n", pkg, err)
|
terrorf(tree, "%s: %v\n", pkg, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dir := filepath.Join(tree.SrcDir(), pkg)
|
dir := filepath.Join(tree.SrcDir(), pkg)
|
||||||
@ -223,11 +230,11 @@ func install(pkg, parent string) {
|
|||||||
// Install prerequisites.
|
// Install prerequisites.
|
||||||
dirInfo, err := build.ScanDir(dir, parent == "")
|
dirInfo, err := build.ScanDir(dir, parent == "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorf("%s: %v\n", pkg, err)
|
terrorf(tree, "%s: %v\n", pkg, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(dirInfo.GoFiles)+len(dirInfo.CgoFiles) == 0 {
|
if len(dirInfo.GoFiles)+len(dirInfo.CgoFiles) == 0 {
|
||||||
errorf("%s: package has no files\n", pkg)
|
terrorf(tree, "%s: package has no files\n", pkg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, p := range dirInfo.Imports {
|
for _, p := range dirInfo.Imports {
|
||||||
@ -243,13 +250,13 @@ func install(pkg, parent string) {
|
|||||||
if *useMake {
|
if *useMake {
|
||||||
err := domake(dir, pkg, tree, dirInfo.IsCommand())
|
err := domake(dir, pkg, tree, dirInfo.IsCommand())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorf("%s: install: %v\n", pkg, err)
|
terrorf(tree, "%s: install: %v\n", pkg, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
script, err := build.Build(tree, pkg, dirInfo)
|
script, err := build.Build(tree, pkg, dirInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorf("%s: install: %v\n", pkg, err)
|
terrorf(tree, "%s: install: %v\n", pkg, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if *nuke {
|
if *nuke {
|
||||||
@ -263,7 +270,7 @@ func install(pkg, parent string) {
|
|||||||
if script.Stale() {
|
if script.Stale() {
|
||||||
printf("%s: install\n", pkg)
|
printf("%s: install\n", pkg)
|
||||||
if err := script.Run(); err != nil {
|
if err := script.Run(); err != nil {
|
||||||
errorf("%s: install: %v\n", pkg, err)
|
terrorf(tree, "%s: install: %v\n", pkg, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user