Commit 76dcedc9 authored by Nodir Turakulov's avatar Nodir Turakulov Committed by Andrew Gerrand

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: 's avatarAndrew Gerrand <adg@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent d8c6bf91
......@@ -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)
......
......@@ -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...)
......
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