]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: dedup packages in packagesAndErrors
authorNodir Turakulov <nodir@google.com>
Wed, 21 Oct 2015 04:33:18 +0000 (21:33 -0700)
committerAndrew Gerrand <adg@golang.org>
Wed, 21 Oct 2015 06:31:52 +0000 (06:31 +0000)
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>

src/cmd/go/go_test.go
src/cmd/go/pkg.go

index a4c91c960af2a4476fa2f77c72adc0997695e48a..9f4828b3415eb5b7bc45354dc4163cc45d947f44 100644 (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)
index 539e8b92e1f10932c8e3a90665b631009de07ee0..f7b18743de4fe9fd8e63df49027fc0d71f8adf9b 100644 (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...)