Commit eeb87c36 authored by Jan Ziak's avatar Jan Ziak Committed by Russ Cox

cmd/go: do not miss an error if import path contains "cmd/something"

Fixes #7638

LGTM=rsc
R=rsc, adg, robert.hencke, bradfitz
CC=golang-codereviews
https://golang.org/cl/89280043
parent 74ce581b
...@@ -140,6 +140,10 @@ var downloadRootCache = map[string]bool{} ...@@ -140,6 +140,10 @@ var downloadRootCache = map[string]bool{}
// for the package named by the argument. // for the package named by the argument.
func download(arg string, stk *importStack, getTestDeps bool) { func download(arg string, stk *importStack, getTestDeps bool) {
p := loadPackage(arg, stk) p := loadPackage(arg, stk)
if p.Error != nil && p.Error.hard {
errorf("%s", p.Error)
return
}
// There's nothing to do if this is a package in the standard library. // There's nothing to do if this is a package in the standard library.
if p.Standard { if p.Standard {
......
...@@ -139,6 +139,7 @@ type PackageError struct { ...@@ -139,6 +139,7 @@ type PackageError struct {
Pos string // position of error Pos string // position of error
Err string // the error itself Err string // the error itself
isImportCycle bool // the error is an import cycle isImportCycle bool // the error is an import cycle
hard bool // whether the error is soft or hard; soft errors are ignored in some places
} }
func (p *PackageError) Error() string { func (p *PackageError) Error() string {
...@@ -715,6 +716,7 @@ func loadPackage(arg string, stk *importStack) *Package { ...@@ -715,6 +716,7 @@ func loadPackage(arg string, stk *importStack) *Package {
Error: &PackageError{ Error: &PackageError{
ImportStack: stk.copy(), ImportStack: stk.copy(),
Err: fmt.Sprintf("invalid import path: cmd/... is reserved for Go commands"), Err: fmt.Sprintf("invalid import path: cmd/... is reserved for Go commands"),
hard: true,
}, },
} }
return p return p
......
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