diff --git a/hack/.vendor-helpers.sh b/hack/.vendor-helpers.sh new file mode 100755 index 0000000..3a403e2 --- /dev/null +++ b/hack/.vendor-helpers.sh @@ -0,0 +1,109 @@ +#!/usr/bin/env bash + +PROJECT=github.com/docker/containerd + +# Downloads dependencies into vendor/ directory +mkdir -p vendor + +export GOPATH="$GOPATH:${PWD}/vendor" + +find='find' +if [ "$(go env GOHOSTOS)" = 'windows' ]; then + find='/usr/bin/find' +fi + +clone() { + local vcs="$1" + local pkg="$2" + local rev="$3" + local url="$4" + + : ${url:=https://$pkg} + local target="vendor/src/$pkg" + + echo -n "$pkg @ $rev: " + + if [ -d "$target" ]; then + echo -n 'rm old, ' + rm -rf "$target" + fi + + echo -n 'clone, ' + case "$vcs" in + git) + git clone --quiet --no-checkout "$url" "$target" + ( cd "$target" && git checkout --quiet "$rev" && git reset --quiet --hard "$rev" ) + ;; + hg) + hg clone --quiet --updaterev "$rev" "$url" "$target" + ;; + esac + + echo -n 'rm VCS, ' + ( cd "$target" && rm -rf .{git,hg} ) + + echo -n 'rm vendor, ' + ( cd "$target" && rm -rf vendor Godeps/_workspace ) + + echo done +} + +clean() { + local packages=( + "${PROJECT}/containerd" # package main + "${PROJECT}/ctr" # package main + ) + local platforms=( linux/amd64 linux/386 windows/amd64 windows/386 darwin/amd64 ) + local buildTagCombos=( + 'libcontainer runc seccomp' + ) + + echo + + echo -n 'collecting import graph, ' + local IFS=$'\n' + local imports=( $( + for platform in "${platforms[@]}"; do + export GOOS="${platform%/*}"; + export GOARCH="${platform##*/}"; + for buildTags in "${buildTagCombos[@]}"; do + go list -e -tags "$buildTags" -f '{{join .Deps "\n"}}' "${packages[@]}" + go list -e -tags "$buildTags" -f '{{join .TestImports "\n"}}' "${packages[@]}" + done + done | grep -vE "^${PROJECT}" | sort -u + ) ) + imports=( $(go list -e -f '{{if not .Standard}}{{.ImportPath}}{{end}}' "${imports[@]}") ) + unset IFS + + echo -n 'pruning unused packages, ' + findArgs=( + # This directory contains only .c and .h files which are necessary + -path vendor/src/github.com/mattn/go-sqlite3/code + ) + for import in "${imports[@]}"; do + [ "${#findArgs[@]}" -eq 0 ] || findArgs+=( -or ) + findArgs+=( -path "vendor/src/$import" ) + done + local IFS=$'\n' + local prune=( $($find vendor -depth -type d -not '(' "${findArgs[@]}" ')') ) + unset IFS + for dir in "${prune[@]}"; do + $find "$dir" -maxdepth 1 -not -type d -not -name 'LICENSE*' -not -name 'COPYING*' -exec rm -v -f '{}' ';' + rmdir "$dir" 2>/dev/null || true + done + + echo -n 'pruning unused files, ' + $find vendor -type f -name '*_test.go' -exec rm -v '{}' ';' + + echo done +} + +# Fix up hard-coded imports that refer to Godeps paths so they'll work with our vendoring +fix_rewritten_imports () { + local pkg="$1" + local remove="${pkg}/Godeps/_workspace/src/" + local target="vendor/src/$pkg" + + echo "$pkg: fixing rewritten imports" + $find "$target" -name \*.go -exec sed -i -e "s|\"${remove}|\"|g" {} \; +} diff --git a/hack/vendor.sh b/hack/vendor.sh new file mode 100755 index 0000000..6aa3ab2 --- /dev/null +++ b/hack/vendor.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -e + +rm -rf vendor/ +source 'hack/.vendor-helpers.sh' + +clone git github.com/Sirupsen/logrus master +clone git github.com/cloudfoundry/gosigar master +clone git github.com/codegangsta/cli master +clone git github.com/coreos/go-systemd master +clone git github.com/cyberdelia/go-metrics-graphite master +clone git github.com/docker/docker master +clone git github.com/docker/go-units master +clone git github.com/godbus/dbus master +clone git github.com/golang/glog master +clone git github.com/golang/protobuf master +clone git github.com/opencontainers/runc master +clone git github.com/opencontainers/specs master +clone git github.com/rcrowley/go-metrics master +clone git github.com/satori/go.uuid master +clone git github.com/syndtr/gocapability master +clone git github.com/vishvananda/netlink master +clone git github.com/Azure/go-ansiterm master +clone git golang.org/x/net master https://github.com/golang/net.git +clone git google.golang.org/grpc master https://github.com/grpc/grpc-go.git +clone git github.com/seccomp/libseccomp-golang master + +clean