2015-06-05 21:47:27 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2015-09-11 02:10:20 +00:00
|
|
|
PROJECT=github.com/docker/docker
|
|
|
|
|
2015-06-05 21:47:27 +00:00
|
|
|
# Downloads dependencies into vendor/ directory
|
|
|
|
mkdir -p vendor
|
|
|
|
|
|
|
|
rm -rf .gopath
|
|
|
|
mkdir -p .gopath/src/github.com/docker
|
2015-09-11 02:10:20 +00:00
|
|
|
ln -sf ../../../.. .gopath/src/${PROJECT}
|
2015-06-05 21:47:27 +00:00
|
|
|
export GOPATH="${PWD}/.gopath:${PWD}/vendor"
|
|
|
|
|
|
|
|
clone() {
|
|
|
|
local vcs="$1"
|
|
|
|
local pkg="$2"
|
|
|
|
local rev="$3"
|
2015-06-16 14:08:18 +00:00
|
|
|
local url="$4"
|
2015-06-05 21:47:27 +00:00
|
|
|
|
2015-06-16 14:08:18 +00:00
|
|
|
: ${url:=https://$pkg}
|
2015-06-05 21:47:27 +00:00
|
|
|
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"
|
2015-08-19 22:56:04 +00:00
|
|
|
( cd "$target" && git checkout --quiet "$rev" && git reset --quiet --hard "$rev" )
|
2015-06-05 21:47:27 +00:00
|
|
|
;;
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
# get an ENV from the Dockerfile with support for multiline values
|
|
|
|
_dockerfile_env() {
|
|
|
|
local e="$1"
|
|
|
|
awk '
|
|
|
|
$1 == "ENV" && $2 == "'"$e"'" {
|
|
|
|
sub(/^ENV +([^ ]+) +/, "");
|
|
|
|
inEnv = 1;
|
|
|
|
}
|
|
|
|
inEnv {
|
|
|
|
if (sub(/\\$/, "")) {
|
|
|
|
printf "%s", $0;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
print;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
' Dockerfile
|
|
|
|
}
|
|
|
|
|
|
|
|
clean() {
|
|
|
|
local packages=(
|
2015-09-11 02:10:20 +00:00
|
|
|
"${PROJECT}/docker" # package main
|
|
|
|
"${PROJECT}/dockerinit" # package main
|
|
|
|
"${PROJECT}/integration-cli" # external tests
|
2015-06-05 21:47:27 +00:00
|
|
|
)
|
2015-07-28 17:13:33 +00:00
|
|
|
local dockerPlatforms=( linux/amd64 $(_dockerfile_env DOCKER_CROSSPLATFORMS) )
|
2015-06-05 21:47:27 +00:00
|
|
|
local dockerBuildTags="$(_dockerfile_env DOCKER_BUILDTAGS)"
|
|
|
|
local buildTagCombos=(
|
|
|
|
''
|
|
|
|
'experimental'
|
|
|
|
"$dockerBuildTags"
|
|
|
|
"daemon $dockerBuildTags"
|
2015-05-30 23:05:12 +00:00
|
|
|
"daemon cgo $dockerBuildTags"
|
2015-06-05 21:47:27 +00:00
|
|
|
"experimental $dockerBuildTags"
|
|
|
|
"experimental daemon $dockerBuildTags"
|
2015-05-30 23:05:12 +00:00
|
|
|
"experimental daemon cgo $dockerBuildTags"
|
2015-06-05 21:47:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
echo
|
|
|
|
|
|
|
|
echo -n 'collecting import graph, '
|
|
|
|
local IFS=$'\n'
|
|
|
|
local imports=( $(
|
|
|
|
for platform in "${dockerPlatforms[@]}"; do
|
|
|
|
export GOOS="${platform%/*}";
|
|
|
|
export GOARCH="${platform##*/}";
|
|
|
|
for buildTags in "${buildTagCombos[@]}"; do
|
2015-09-14 18:59:38 +00:00
|
|
|
pkgs=( $(go list -e -tags "$buildTags" -f '{{join .Deps "\n"}}' "${packages[@]}" | grep -E "^${PROJECT}" | grep -vE "^${PROJECT}/vendor" | sort -u) )
|
|
|
|
pkgs+=( ${packages[@]} )
|
|
|
|
testImports=( $(go list -e -tags "$buildTags" -f '{{join .TestImports "\n"}}' "${pkgs[@]}" | sort -u) )
|
|
|
|
printf '%s\n' "${testImports[@]}"
|
|
|
|
go list -e -tags "$buildTags" -f '{{join .Deps "\n"}}' "${packages[@]} ${testImports[@]}"
|
2015-06-05 21:47:27 +00:00
|
|
|
done
|
2015-09-14 18:59:38 +00:00
|
|
|
done | grep -vE "^${PROJECT}" | sort -u
|
2015-06-05 21:47:27 +00:00
|
|
|
) )
|
|
|
|
imports=( $(go list -e -f '{{if not .Standard}}{{.ImportPath}}{{end}}' "${imports[@]}") )
|
|
|
|
unset IFS
|
|
|
|
|
|
|
|
echo -n 'pruning unused packages, '
|
2015-05-30 23:05:12 +00:00
|
|
|
findArgs=(
|
|
|
|
# This directory contains only .c and .h files which are necessary
|
|
|
|
-path vendor/src/github.com/mattn/go-sqlite3/code
|
2015-09-10 23:12:00 +00:00
|
|
|
# This directory is needed for compiling the unit tests
|
|
|
|
-o -path vendor/src/github.com/stretchr/objx
|
2015-05-30 23:05:12 +00:00
|
|
|
)
|
2015-06-05 21:47:27 +00:00
|
|
|
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
|
2015-07-23 23:12:21 +00:00
|
|
|
find "$dir" -maxdepth 1 -not -type d -not -name 'LICENSE*' -not -name 'COPYING*' -exec rm -v -f '{}' +
|
2015-06-05 21:47:27 +00:00
|
|
|
rmdir "$dir" 2>/dev/null || true
|
|
|
|
done
|
|
|
|
|
|
|
|
echo -n 'pruning unused files, '
|
2015-05-30 23:05:12 +00:00
|
|
|
find vendor -type f -name '*_test.go' -exec rm -v '{}' +
|
2015-06-05 21:47:27 +00:00
|
|
|
|
|
|
|
echo done
|
|
|
|
}
|