Skip to content

Commit 68b252c

Browse files
committed
Set build import path to the root of the target project
Fixes davecheney#13 Signed-off-by: Olivier <[email protected]>
1 parent 658e86e commit 68b252c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

main.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var (
3030
pkgmatch *regexp.Regexp
3131
)
3232

33-
func findImport(p string) {
33+
func findImport(p string, rootp string) {
3434
if !pkgmatch.MatchString(p) {
3535
// doesn't match the filter, skip it
3636
return
@@ -47,13 +47,13 @@ func findImport(p string) {
4747
p = path.Join("vendor", p)
4848
}
4949

50-
pkg, err := build.Import(p, "", 0)
50+
pkg, err := build.Import(p, rootp, 0)
5151
if err != nil {
5252
log.Fatal(err)
5353
}
5454
pkgs[p] = filter(pkg.Imports)
5555
for _, pkg := range pkgs[p] {
56-
findImport(pkg)
56+
findImport(pkg, rootp)
5757
}
5858
}
5959

@@ -102,8 +102,14 @@ func check(err error) {
102102
}
103103

104104
func main() {
105+
var rootPkg * build.Package
106+
var e error
105107
for _, pkg := range flag.Args() {
106-
findImport(pkg)
108+
rootPkg, e = build.Import(pkg, "", 0)
109+
if e != nil {
110+
log.Fatal(e)
111+
}
112+
findImport(pkg, rootPkg.Dir)
107113
}
108114
cmd := exec.Command("dot", "-Tsvg")
109115
in, err := cmd.StdinPipe()

0 commit comments

Comments
 (0)