-
Notifications
You must be signed in to change notification settings - Fork 9.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vendor: only vendor on emitted binaries #4950
Conversation
Do we have script or command to vendor this way? |
@gyuho what do you mean? it's still godep... |
@heyitsanthony |
@gyuho yeah, to vendor it's |
add a Readme.md for app dir? |
we need to update the build script too? this approach looks good to me. |
bdfe312
to
ed36404
Compare
all fixed ptal /cc @xiang90 |
LGTM. |
Not LGTM. This does not fix #4913. See https://github.com/zellyn/wtf2. Please, please join the Gophers slack, channel #vendor to discuss the problem before trying another solution. Unfortunately the vendoring situation in Go at the moment is pretty fucked (term of art) and a lot of things that look reasonable on their face are subtly broken. There's a lot of experience in the channel that can save you a lot of work and mistakes :) |
It looks like this moves the vendor folder from What this will achieve is that when building, your client packages (libs) will see a version from $GOPATH while your cmds will simultaneously also include the version from the vendor folder. @heyitsanthony I would strongly encourage you to run |
@peterbourgon if https://github.com/zellyn/wtf2/cmd is vendoring the context package, why isn't it also vendoring the lib package as well? |
@kardianos I don't see any problems with the output. What should I be looking for? I've been using I reran the builds again to be certain. vendoring turns up no duplicates with unvendored packages, but uses 157 vendored packages: GO_BUILD_FLAGS="-a -v" ./build >vendor-build.txt 2>&1
# this works too if you only interested in one binary: go build -a -v -o out ./app/etcdmain >vendor-build.txt 2>&1
`sort vendor-build.txt | uniq | sed 's|github.com/coreos/etcd/app/vendor/||g' | sort | uniq -c | grep -v ' 1 '` I tried it with unvendored go build -a -v -o out ./etcdctl >novendor.txt 2>&1
grep vendor novendor.txt I then tried an external repo that uses the etcd client3 library and the context package without vendoring. I ran github.com/coreos/etcd/storage/storagepb
github.com/coreos/etcd/pkg/tlsutil
github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes
github.com/coreos/etcd/etcdserver/etcdserverpb
github.com/coreos/etcd/clientv3
github.com/coreos/etcd/clientv3/concurrency What's missing? |
@heyitsanthony
Please note that two different context packages will be included in the end binary. Same is true for all the other packages in the /app/vendor folder. At the very least, I don't think that's what you were intending. |
@kardianos can this be confirmed with an end binary? I built an unvendored binary and ran strings over it. There was nothing that looked vendored: go build -a -v -o test ./etcdctl 2>&1 | grep context
strings out | grep context | sort | uniq -c | sort -n I got back what looks like good evidence for no duplicates:
|
What does |
|
@heyitsanthony Oh! Yes, now I see what you did. Wow. Yeah, I had considered that approach, but did seriously consider using symbolic links to link to your own repo roo in the vendor folder. The key that I was missing before was the use of symlinks both in the app dir (rename to "cmd"?) and that app/vendor/github.com/coreos/etcd -> $repo_root . A description of the approach used might be a good addition in the commit message, namely what symlinks you are creating and why. That would have saved me a bunch of time :). @peterbourgon While I'm not sure this approach is a good idea with the use of symlinks, it does actually solve the stated issue. I'll back out of this issue conversation. Interesting approach. |
I don't see what @heyitsanthony did. Can you explain? If these commits add symlinks to the repo, I can't figure out how to get GitHub to show them. Regardless, it's a bad idea to have symlinks anywhere in your $GOPATH, as the go tool goes out of its way to ignore them. |
@peterbourgon ... You are correct, symlinks are discouraged. Yes, go build ./... would build the same package twice. |
6976df4
to
d45b094
Compare
reworked the windows builds, @gyuho confirmed it works. merging on greenlight |
Moves the vendor/ directory to cmd/vendor. Vendored binaries are built from cmd/, which is backed by symlinks pointing back to repo root.
@peterbourgon @heyitsanthony @kardianos Sorry for the late reply. I think the current solution works for external projects that uses etcd subpkgs as dependencies. Correct me if I am wrong. As there is probably no prefect solution right now. The tradeoff we want is to keep other people happy and potentially do more work at etcd developer side. The symlinks only exists inside cmd dir and might causes issues for people who tries to build etcd, but it works. We really do not want to split bin and libs into different repos and vendor the libs again for the moment. |
This does not help automatic scripts to discover directories with vendored/bundled dependencies. It is always better to assume the vendor directory is in your root directory. Once the directory can be located everywhere, how can you distinguish between |
@ingvagabund Putting There's only one vendor directory in the entire repo, what's left to distinguish? |
I see. Thanks for the #4913 link. Need to read through the discussion to get better picture. |
Fixes #4913