Commit ca2a6643 authored by Russ Cox's avatar Russ Cox

cmd/go: fix custom import path wildcards (go get rsc.io/pdf/...)

Fixes TestGoGetWorksWithVanityWildcards,
but that test uses the network and is not run
on the builders.

For #11806.

Change-Id: I35c6677deaf84e2fa9bdb98b62d80d388b5248ae
Reviewed-on: https://go-review.googlesource.com/12557Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent f0876a1a
...@@ -166,9 +166,9 @@ var downloadRootCache = map[string]bool{} ...@@ -166,9 +166,9 @@ var downloadRootCache = map[string]bool{}
func download(arg string, parent *Package, stk *importStack, getTestDeps bool) { func download(arg string, parent *Package, stk *importStack, getTestDeps bool) {
load := func(path string) *Package { load := func(path string) *Package {
if parent == nil { if parent == nil {
return loadPackage(arg, stk) return loadPackage(path, stk)
} }
return loadImport(arg, parent.Dir, nil, stk, nil) return loadImport(path, parent.Dir, nil, stk, nil)
} }
p := load(arg) p := load(arg)
...@@ -204,15 +204,17 @@ func download(arg string, parent *Package, stk *importStack, getTestDeps bool) { ...@@ -204,15 +204,17 @@ func download(arg string, parent *Package, stk *importStack, getTestDeps bool) {
wildcardOkay := len(*stk) == 0 wildcardOkay := len(*stk) == 0
isWildcard := false isWildcard := false
stk.push(arg) // Note: Do not stk.push(arg) and defer stk.pop() here.
defer stk.pop() // The push/pop below are using updated values of arg in some cases.
// Download if the package is missing, or update if we're using -u. // Download if the package is missing, or update if we're using -u.
if p.Dir == "" || *getU { if p.Dir == "" || *getU {
// The actual download. // The actual download.
stk.push(arg)
err := downloadPackage(p) err := downloadPackage(p)
if err != nil { if err != nil {
errorf("%s", &PackageError{ImportStack: stk.copy(), Err: err.Error()}) errorf("%s", &PackageError{ImportStack: stk.copy(), Err: err.Error()})
stk.pop()
return return
} }
...@@ -225,6 +227,7 @@ func download(arg string, parent *Package, stk *importStack, getTestDeps bool) { ...@@ -225,6 +227,7 @@ func download(arg string, parent *Package, stk *importStack, getTestDeps bool) {
fmt.Fprintf(os.Stderr, "warning: package %v\n", strings.Join(*stk, "\n\timports ")) fmt.Fprintf(os.Stderr, "warning: package %v\n", strings.Join(*stk, "\n\timports "))
} }
} }
stk.pop()
args := []string{arg} args := []string{arg}
// If the argument has a wildcard in it, re-evaluate the wildcard. // If the argument has a wildcard in it, re-evaluate the wildcard.
...@@ -251,7 +254,9 @@ func download(arg string, parent *Package, stk *importStack, getTestDeps bool) { ...@@ -251,7 +254,9 @@ func download(arg string, parent *Package, stk *importStack, getTestDeps bool) {
pkgs = pkgs[:0] pkgs = pkgs[:0]
for _, arg := range args { for _, arg := range args {
stk.push(arg)
p := load(arg) p := load(arg)
stk.pop()
if p.Error != nil { if p.Error != nil {
errorf("%s", p.Error) errorf("%s", p.Error)
continue continue
......
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