cd `mktemp -d`export GOPATH=$PWDmkdir hellocd hellocat <<EOD >hello.gopackage main // import "example.com/hello"import ("fmt")func main() {fmt.Println(vgo_example_compat.X, sub.Y)}EODecho >go.modvgo build./hello
2 2
vgo list -f '{{ join .Deps "\n"}}' ./... | xargs vgo list -f "{{if not .Standard}}{{.ImportPath}}{{end}}" .
vgo list -f '{{ join .Deps "\n"}}' ./... | xargs vgo list -f "{{if not .Standard}}{{.Dir}}{{end}}" . | xargs grep -r const
/tmp/tmp.8TlP9gd4Eq/src/v/github.com/myitcv/vgo_example_compat/v...@v2.0.0/sub/sub.go:const Y = 2/tmp/tmp.8TlP9gd4Eq/src/v/github.com/myitcv/vgo_example_compat/v...@v2.0.0/goodbye.go:const X = 2/tmp/tmp.8TlP9gd4Eq/src/v/github.com/myitcv/vgo_example_compat/v...@v2.0.0/sub/sub.go:const Y = 2
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
One minor issue, that `vgo list` results in a lot of bits of path appearing twice, for example:/home/pwaller/.local/src/v/github.com/lib/p...@v0.0.0-20180523175426-90697d60dd84/home/pwaller/.local/src/v/github.com/lib/p...@v0.0.0-20180523175426-90697d60dd84/oidWhich I guess means one should not do a recursive search on those paths, but only look in those exact directories. It will result in searching exactly the packages which are imported, which is a nice in many circumstances.
vgo list -f '{{ join .Deps "\n"}}' ./... | xargs vgo list -f "{{if not .Standard}}{{.Module.Path}}{{end}}" . | xargs vgo list -f "{{.Dir}}"
/tmp/tmp.etqFtpbatu/hello/tmp/tmp.etqFtpbatu/src/v/github.com/myitcv/vgo_example_compat/v...@v2.0.0
$ vgo list -json .{"Dir": "/tmp/tmp.etqFtpbatu/hello","ImportPath": "example.com/hello","Name": "main","Target": "/tmp/tmp.etqFtpbatu/bin/hello","Stale": true,"StaleReason": "target missing","GoFiles": ["hello.go"],"Imports": ["fmt",],"Deps": ["errors","fmt","internal/bytealg","internal/cpu","internal/poll","internal/race","internal/syscall/unix","internal/testlog","io","math","math/bits","os","reflect","runtime","runtime/internal/atomic","runtime/internal/sys","strconv","sync","sync/atomic","syscall","time","unicode","unicode/utf8","unsafe"],"Module": {"Top": true,"Path": "example.com/hello","Version": ""}}
go help list
To see the full output do something like:$ vgo list -json .
It's tricky this. If I start feeding the .Module.Path into vgo list, then I start finding lots of additional dependencies which are actually not used by my package, because then the vgo list appears to operate on all packages in the module, so again I end up with a list of paths which includes more modules than myapp actually uses.
find $(vgo list -f '{{ join .Deps "\n"}}' ./... | xargs vgo list -f "{{if not .Standard}}{{.Dir}}{{end}}" .) -maxdepth 1 -type f | xargs grep const
/tmp/tmp.1PdGhmegEy/src/v/github.com/myitcv/vgo_example_compat/v...@v2.0.0/goodbye.go:const X = 2/tmp/tmp.1PdGhmegEy/src/v/github.com/myitcv/vgo_example_compat/v...@v2.0.0/sub/sub.go:const Y = 2
Perhaps this does the trick?find $(vgo list -f '{{ join .Deps "\n"}}' ./... | xargs vgo list -f "{{if not .Standard}}{{.Dir}}{{end}}" .) -maxdepth 1 -type f | xargs grep constgives:/tmp/tmp.1PdGhmegEy/src/v/github.com/myitcv/vgo_example_compat/v...@v2.0.0/goodbye.go:const X = 2/tmp/tmp.1PdGhmegEy/src/v/github.com/myitcv/vgo_example_compat/v...@v2.0.0/sub/sub.go:const Y = 2
As I understand it, this won't grep v2/goodbye.go (or v2/README) if the myapp only imports .../v2/sub/ (and not .../v2), since that path won't appear as {{.Dir}}. (I tried to express this previously, but hopefully it's clearer written with respect to your example).
find $(vgo list -f '{{ join .Deps "\n"}}' ./... | xargs vgo list -f "{{if not .Standard}}{{.Dir}}{{end}}" .) -maxdepth 1 -type f | xargs grep const
vgo list -f '{{ join .Deps "\n"}}' ./... | xargs vgo list -f "{{if not .Standard}}{{.Module.Path}}{{end}}" . | xargs vgo list -f "{{.Dir}}" | xargs grep -r const
If you want something else, then apologies, I'm probably missing something!
On 31 May 2018 at 14:59, Paul Jolly <pa...@myitcv.io> wrote:If you want something else, then apologies, I'm probably missing something!It's subtle. The issue is that a module can depend on other modules which actually aren't compiled into myapp. Consider the following:myapp => pkga/foopkga/foo => pkgbpkga/bar => huge tree of dependencies.(that is, myapp imports pkga/foo but not pkga/bar).In the old world, since myapp only imports pkga/foo, only pkga and pkgb are vendored; I run grep in /vendor/, all is good. The huge tree of dependencies is ignored.Also neatly, vgo install avoids pkga/bar and its huge tree of dependencies since those are not imported by my program (AIUI). It doesn't bother fetching them, in particular.Using the suggested commands:vgo list -f '{{ join .Deps "\n"}}' myapp/...This would for example produce pkga/foo, because myapp depends on it.Then, when I feed `pkga/foo` along with others into .Module.Path:`vgo list -f '{{.Module.Path}}' pkga/foo etc`I get `pkga` (and the other modules).Now (after `sort --unique`) I feed pkga and friends into xargs vgo list -f '{{.Dir}}', it starts resolving (and downloading) dependencies for a large tree of packages which are unused by my program, but pulled in through pkga/bar.Also, if it completes that download, then consider that it runs something like this (protobuf taken as an example transitive dependency):vgo list -f "{{.Dir}}" pkga pkgb pkgc github.com/golang/protobufThat actually outputs nothing (not even the valid paths to pkga,pkgb,pkgc), it gives only an error instead:
vgo: import "github.com/golang/protobuf" [/home/pwaller/.local/src/v/github.com/golang/prot...@v1.1.0]: no Go source files