diff --git a/Makefile b/Makefile index 8bf756d6e7..c95dc29b22 100644 --- a/Makefile +++ b/Makefile @@ -488,7 +488,7 @@ distro: all mrrobot: @rm -rf *.xml *.html *.log *.zip VCH-0-* -clean: +clean: cleandeps @echo removing binaries @rm -rf $(BIN)/* @echo removing Go object files @@ -520,3 +520,7 @@ clean: distclean: clean @echo removing binaries @rm -rf $(BIN) + +cleandeps: + @echo removing dependency cache + @rm -rf .godeps_cache diff --git a/README.md b/README.md index 9878c4fd9d..d761874801 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,22 @@ To run unit tests after a successful build, issue the following: make test ``` +Running "make" every time causes Go dependency regeneration for each component, so that "make" can rebuild only those components that are changed. However, such regeneration may take significant amount of time when it is not really needed. To fight that developers can use cached dependencies that can be enabled by defining the environment variable VIC_CACHE_DEPS. As soon as it is set, infra/scripts/go-deps.sh will read cached version of dependencies if those exist. + +```shell +export VIC_CACHE_DEPS=1 +``` + +This is important to note that as soon as you add a new package or an internal project dependency that didn't exist before, those dependencies +should be regenerated to reflect latest changes. It can be done just by running: + +```shell +make cleandeps +``` + +After that next "make" run will regenerate dependencies from scratch. + + ## Managing vendor/ directory To build the VIC Engine dependencies, ensure `GOPATH` is set, then issue the following. diff --git a/infra/scripts/go-deps.sh b/infra/scripts/go-deps.sh index fa06f799cf..0f48b97266 100755 --- a/infra/scripts/go-deps.sh +++ b/infra/scripts/go-deps.sh @@ -20,20 +20,36 @@ # # pkg This is github.com/vmware/vic/cmd/imagec for example # +# If VIC_CACHE_DEPS environment variable is defined, this script will attempt to read +# cached dependencies from disk if those exist. If they are not cached, dependencies will be +# regenerated and cached. + +cache_dir=.godeps_cache pkg=$1 flags=$2 +cachedname=`echo .$1.godeps_cache | sed 's/\//_/g'` if [ -d "$pkg" ]; then - if [[ "$flags" == *d* ]] - then + + if [[ "$flags" == *d* ]]; then # Only output if make is given the '-d' flag echo "Generating deps for $pkg" >&2 fi - go list -f '{{join .Deps "\n"}}' github.com/vmware/vic/"$pkg" 2>/dev/null | \ - xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' 2>/dev/null | \ - sed -e 's:github.com/vmware/vic/\(.*\)$:\1/*:' + if [ -n "$VIC_CACHE_DEPS" ]; then + mkdir -p $cache_dir + if [ ! -f $cache_dir/$cachedname ]; then + go list -f '{{join .Deps "\n"}}' github.com/vmware/vic/"$pkg" 2>/dev/null | \ + xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' 2>/dev/null | \ + sed -e 's:github.com/vmware/vic/\(.*\)$:\1/*:' > "$cache_dir/$cachedname" + fi + cat "$cache_dir/$cachedname" + else + go list -f '{{join .Deps "\n"}}' github.com/vmware/vic/"$pkg" 2>/dev/null | \ + xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' 2>/dev/null | \ + sed -e 's:github.com/vmware/vic/\(.*\)$:\1/*:' + fi else if [[ "$flags" == *d* ]] then