Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Vendor only the used packages in a dependency repository #625

Closed
ahmetb opened this issue May 23, 2017 · 10 comments
Closed

Vendor only the used packages in a dependency repository #625

ahmetb opened this issue May 23, 2017 · 10 comments

Comments

@ahmetb
Copy link
Contributor

ahmetb commented May 23, 2017

I am trying to figure out how can I make sure I only vendor a particular package from a huge repository my project depends on.

For example consider this simple program with main.go and nothing else:

package main

import "google.golang.org/api/cloudbuild/v1"

func main() {
    _ = v1.CloudPlatformScope
}

I then run dep init on this directory to initialize Gopkg files. This simple dependency yields in 2,129,065 lines of code to be vendored. Is this by design?

If I use govendor/godep this is not the case as those tools can figure out what packages are used in the build and vendor only those. Am I doing something wrong?

@ahmetb
Copy link
Contributor Author

ahmetb commented May 23, 2017

I just discovered the dep prune command which seems to be doing what I want. This made me wonder why is this not the default behavior?

@sdboyer
Copy link
Member

sdboyer commented May 23, 2017

I've recently sorta relented on this and have accepted as a TODO making pruning the default. But this whole area gets sticky and complicated if we want to make it safe (which is our primary goal), and is the topic of #120 😄

(Closing as dup)

@sdboyer sdboyer closed this as completed May 23, 2017
@kron4eg
Copy link

kron4eg commented May 23, 2017

@ahmetb I have small make target dep, which makes sure most trash is cleaned :)

.PHONY: dep
dep: $(GOPATH)/bin/dep
	dep ensure && dep prune && find ./vendor -name '*_test.go' -delete

$(GOPATH)/bin/dep:
	go get -u github.com/golang/dep/cmd/dep

@VojtechVitek
Copy link

VojtechVitek commented Jun 5, 2017

I'm using .gitignore to avoid unnecessary files in vendor/ directory:

# Ignore everything in vendor/, except for *.go files,
# LICENSE and COPYING. Ignore Go tests.
vendor/**
!vendor/**/*.go
!vendor/**/LICENSE
!vendor/**/COPYING
vendor/**/*_test.go

@leonid-shevtsov
Copy link

The gitignore snippet from @VojtechVitek wouldn't work in my case - and probably most cases - because the first line will ignore all directories under vendor, and per Git documentation

It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined.

(Spent some time figuring out why wouldn't Git see anything inside my vendor directory.)

@sdboyer
Copy link
Member

sdboyer commented Feb 7, 2018

the gitignore approach is long since outdated, thanks to pruning.

@leonid-shevtsov
Copy link

Pruning doesn’t remove non-Go files and test files. Which I think is correct, but I prefer removing them.

For reference, this is the “conversion” of the .gitignore above into a shell script.

find vendor -type f -not -name "*.go" -not -name "LICENSE" -not -name "COPYING" -or -name "*_test.go" | xargs rm -f

@jmank88
Copy link
Collaborator

jmank88 commented Feb 7, 2018

Pruning doesn’t remove non-Go files and test files.

'non-go' and 'go-tests' are two of the three types of pruning supported by dep: https://golang.github.io/dep/docs/Gopkg.toml.html#prune

@sdboyer
Copy link
Member

sdboyer commented Feb 8, 2018 via email

@leonid-shevtsov
Copy link

@jmank88 @sdboyer indeed I was! Thanks for the clarification - very happy to see this feature.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants