1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
9 // Dependencies returns all dependencies of the specified packages.
11 // Dependent packages appear in topological order: if package P imports
12 // package Q, Q appears earlier than P in the result.
13 // The algorithm follows import statements in the order they
14 // appear in the source code, so the result is a total order.
16 func Dependencies(pkgs ...*types.Package) []*types.Package {
17 var result []*types.Package
18 seen := make(map[*types.Package]bool)
19 var visit func(pkgs []*types.Package)
20 visit = func(pkgs []*types.Package) {
21 for _, p := range pkgs {
25 result = append(result, p)