github.com/nf/docker@v1.8.1/hack/.vendor-helpers.sh (about) 1 #!/usr/bin/env bash 2 3 # Downloads dependencies into vendor/ directory 4 mkdir -p vendor 5 6 rm -rf .gopath 7 mkdir -p .gopath/src/github.com/docker 8 ln -sf ../../../.. .gopath/src/github.com/docker/docker 9 export GOPATH="${PWD}/.gopath:${PWD}/vendor" 10 11 clone() { 12 local vcs="$1" 13 local pkg="$2" 14 local rev="$3" 15 local url="$4" 16 17 : ${url:=https://$pkg} 18 local target="vendor/src/$pkg" 19 20 echo -n "$pkg @ $rev: " 21 22 if [ -d "$target" ]; then 23 echo -n 'rm old, ' 24 rm -rf "$target" 25 fi 26 27 echo -n 'clone, ' 28 case "$vcs" in 29 git) 30 git clone --quiet --no-checkout "$url" "$target" 31 ( cd "$target" && git reset --quiet --hard "$rev" ) 32 ;; 33 hg) 34 hg clone --quiet --updaterev "$rev" "$url" "$target" 35 ;; 36 esac 37 38 echo -n 'rm VCS, ' 39 ( cd "$target" && rm -rf .{git,hg} ) 40 41 echo -n 'rm vendor, ' 42 ( cd "$target" && rm -rf vendor Godeps/_workspace ) 43 44 echo done 45 } 46 47 # get an ENV from the Dockerfile with support for multiline values 48 _dockerfile_env() { 49 local e="$1" 50 awk ' 51 $1 == "ENV" && $2 == "'"$e"'" { 52 sub(/^ENV +([^ ]+) +/, ""); 53 inEnv = 1; 54 } 55 inEnv { 56 if (sub(/\\$/, "")) { 57 printf "%s", $0; 58 next; 59 } 60 print; 61 exit; 62 } 63 ' Dockerfile 64 } 65 66 clean() { 67 local packages=( 68 github.com/docker/docker/docker # package main 69 github.com/docker/docker/dockerinit # package main 70 github.com/docker/docker/integration-cli # external tests 71 ) 72 73 local dockerPlatforms=( linux/amd64 windows/amd64 $(_dockerfile_env DOCKER_CROSSPLATFORMS) ) 74 local dockerBuildTags="$(_dockerfile_env DOCKER_BUILDTAGS)" 75 local buildTagCombos=( 76 '' 77 'experimental' 78 "$dockerBuildTags" 79 "daemon $dockerBuildTags" 80 "daemon cgo $dockerBuildTags" 81 "experimental $dockerBuildTags" 82 "experimental daemon $dockerBuildTags" 83 "experimental daemon cgo $dockerBuildTags" 84 ) 85 86 echo 87 88 echo -n 'collecting import graph, ' 89 local IFS=$'\n' 90 local imports=( $( 91 for platform in "${dockerPlatforms[@]}"; do 92 export GOOS="${platform%/*}"; 93 export GOARCH="${platform##*/}"; 94 for buildTags in "${buildTagCombos[@]}"; do 95 go list -e -tags "$buildTags" -f '{{join .Deps "\n"}}' "${packages[@]}" 96 done 97 done | grep -vE '^github.com/docker/docker' | sort -u 98 ) ) 99 imports=( $(go list -e -f '{{if not .Standard}}{{.ImportPath}}{{end}}' "${imports[@]}") ) 100 unset IFS 101 102 echo -n 'pruning unused packages, ' 103 findArgs=( 104 # This directory contains only .c and .h files which are necessary 105 -path vendor/src/github.com/mattn/go-sqlite3/code 106 ) 107 for import in "${imports[@]}"; do 108 [ "${#findArgs[@]}" -eq 0 ] || findArgs+=( -or ) 109 findArgs+=( -path "vendor/src/$import" ) 110 done 111 local IFS=$'\n' 112 local prune=( $(find vendor -depth -type d -not '(' "${findArgs[@]}" ')') ) 113 unset IFS 114 for dir in "${prune[@]}"; do 115 find "$dir" -maxdepth 1 -not -type d -not -name 'LICENSE*' -not -name 'COPYING*' -exec rm -v -f '{}' + 116 rmdir "$dir" 2>/dev/null || true 117 done 118 119 echo -n 'pruning unused files, ' 120 find vendor -type f -name '*_test.go' -exec rm -v '{}' + 121 122 echo done 123 }