ondrajz / go-callvis

Visualize call graph of a Go program using Graphviz
https://ofabry.github.io/go-callvis
MIT License
5.91k stars 408 forks source link

Cross-platform build tool support? #16

Closed emcniece closed 6 years ago

emcniece commented 6 years ago

I'm trying to run this against a project that has platform-specific build files, and it's failing. Not sure if it's because I'm not ignoring stuff properly or if it's because of cross-platform builds.

Command:

go-callvis -focus github.com/rancher/os/cmd/control/install \
-limit github.com/rancher/os/cmd/control/install \
-ignore github.com/rancher/os/netconf,github.com/rancher/os/util,github.com/rancher/os/netconf/bridge \
github.com/rancher/os/cmd/control/install | dot -Tpng -o install.png

Result:

~/go/src/github.com/rancher/os/netconf/bridge.go:41:39: cannot use bridge (variable of type *github.com/rancher/os/vendor/github.com/vishvananda/netlink.Bridge) as *github.com/rancher/os/vendor/github.com/vishvananda/netlink.Link value in argument to netlink.LinkSetMaster
~/go/src/github.com/rancher/os/cmd/control/install/install.go:43:30: Mount not declared by package util
~/go/src/github.com/rancher/os/cmd/control/install/install.go:50:16: Blkid not declared by package util
~/go/src/github.com/rancher/os/cmd/control/install/install.go:58:14: ResolveDevice not declared by package util
~/go/src/github.com/rancher/os/cmd/control/install/install.go:62:18: Blkid not declared by package util
go-callvis: couldn't load packages due to errors: github.com/rancher/os/netconf, github.com/rancher/os/cmd/control/install

I suspect that this is at least partially due to the util package having platform-specific builds. For example, most of the errors above (Mount, Blkid, ResolveDevice) reside in util_linux.go instead of the main util.go:

github.com/rancher/os/util/util_linux.go

// +build linux

package util

Can anyone confirm that I am not ignoring or focussing this target properly?

ondrajz commented 6 years ago

And you are trying to compile it on something else than linux I presume?

Also, ignoring packages doesn't lose dependency on it, it just omits that packages from the output graph result. The analysis is done for the entire program.

emcniece commented 6 years ago

Yes, this compilation is happening on OSX... good call. I'll try this on Linux and see what happens. Thank you for the clarification on -ignore!

emcniece commented 6 years ago

Excellent, verified that the build target was the problem.

root@wtfdidijustdo:~/go# go-callvis github.com/rancher/os/cmd | dot -Tpng -o install.png
go-callvis: cannot find package "main" in any of:
    /usr/local/go/src/main (from $GOROOT)
    /root/go/src/main (from $GOPATH)
root@emc2-wp1:~/go#

There's some other issues, unrelated to this topic. Thanks again!