1
0
mirror of https://github.com/golang/go synced 2024-09-30 12:28:35 -06:00

cmd/go: dedup packages in packagesAndErrors

packagesAndErrors function doesn't dedup packages.
As a result, `go list io ./io` prints io package twice.
Same applies to `go build` and `go test`.

* dedup packages.
* add a test for go list

Change-Id: I54d4063979b1c9359e5416e12327cb85c4823a0f
Reviewed-on: https://go-review.googlesource.com/16136
Run-TryBot: Andrew Gerrand <adg@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Nodir Turakulov 2015-10-20 21:33:18 -07:00 committed by Andrew Gerrand
parent d8c6bf916e
commit 76dcedc920
2 changed files with 27 additions and 6 deletions

View File

@ -1372,6 +1372,18 @@ func TestGoListCmdOnlyShowsCommands(t *testing.T) {
}
}
func TestGoListDedupsPackages(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.run("list", "xtestonly", "./testdata/src/xtestonly/...")
got := strings.TrimSpace(tg.getStdout())
const want = "xtestonly"
if got != want {
t.Errorf("got %q; want %q", got, want)
}
}
// Issue 4096. Validate the output of unsuccessful go install foo/quxx.
func TestUnsuccessfulGoInstallShouldMentionMissingPackage(t *testing.T) {
tg := testgo(t)

View File

@ -1604,15 +1604,24 @@ func packagesAndErrors(args []string) []*Package {
}
args = importPaths(args)
var pkgs []*Package
var stk importStack
var set = make(map[string]bool)
var (
pkgs []*Package
stk importStack
seenArg = make(map[string]bool)
seenPkg = make(map[*Package]bool)
)
for _, arg := range args {
if !set[arg] {
pkgs = append(pkgs, loadPackage(arg, &stk))
set[arg] = true
if seenArg[arg] {
continue
}
seenArg[arg] = true
pkg := loadPackage(arg, &stk)
if seenPkg[pkg] {
continue
}
seenPkg[pkg] = true
pkgs = append(pkgs, pkg)
}
computeStale(pkgs...)