When using 'go mod vendor' why are there lots of files missing?

6,208 views
Skip to first unread message

kalekold

unread,
Sep 17, 2018, 2:59:34 PM9/17/18
to golang-nuts
When using 'go mod vendor' why are there lots of files missing? I'm converting packages from using Dep to using the new modules and there are mismatches in the vendor folder structure.

Does this command only vendor the actual files used for compilation? Because a lot of tests and examples are missing from the vendor directory of each package.

Frits van Bommel

unread,
Sep 17, 2018, 4:58:01 PM9/17/18
to golang-nuts
 According to the help text that's the intended behavior:

usage: go mod vendor [-v]

Vendor resets the main module's vendor directory to include all packages
needed to build and test all the main module's packages.
It does not include test code for vendored packages.

The -v flag causes vendor to print the names of vendored
modules and packages to standard error.

Justin Israel

unread,
Sep 24, 2018, 2:43:24 AM9/24/18
to golang-nuts
This just bit me, because it isn't copying required cc source files from a parent directory of the package, leading to the cgo library not being able to build:

library
    cpp/
        source1.cpp
    go/
        lib.go
        inc.cpp

For better or worse, inc.cpp has had '#include "../cpp/source1.cpp"' in it, and it has been working under glide as the whole project gets vendored. But now under "go mod vendor" it throws away the non-go files leading to missing cpp files. Is this intended behaviour, expecting that the Go source should have everything it needs as siblings or children in the directory structure?

gary.wi...@victoriaplumb.com

unread,
Sep 24, 2018, 4:00:42 AM9/24/18
to golang-nuts
I think it's worth raising an issue for this. Vendoring should copy the whole repo.

Paul Jolly

unread,
Sep 24, 2018, 4:12:34 AM9/24/18
to gary.wi...@victoriaplumb.com, golan...@googlegroups.com
> I think it's worth raising an issue for this. Vendoring should copy the whole repo.

This has been raised before (https://github.com/golang/go/issues/26366
amongst others). Vendoring is not defined to copy the whole repo:

$ go help mod vendor
usage: go mod vendor [-v]

Vendor resets the main module's vendor directory to include all packages
needed to build and test all the main module's packages.
It does not include test code for vendored packages.

An alternative is to "vendor" the modules themselves:

https://github.com/myitcv/go-modules-by-example/blob/master/012_modvendor/README.md
Reply all
Reply to author
Forward
0 new messages