github.com/DaoCloud/dao@v0.0.0-20161212064103-c3dbfd13ee36/hack/.vendor-helpers.sh (about) 1 #!/usr/bin/env bash 2 3 PROJECT=github.com/docker/docker 4 5 # Downloads dependencies into vendor/ directory 6 mkdir -p vendor 7 8 if ! go list github.com/docker/docker/docker &> /dev/null; then 9 rm -rf .gopath 10 mkdir -p .gopath/src/github.com/docker 11 ln -sf ../../../.. .gopath/src/${PROJECT} 12 export GOPATH="${PWD}/.gopath:${PWD}/vendor" 13 fi 14 export GOPATH="$GOPATH:${PWD}/vendor" 15 16 find='find' 17 if [ "$(go env GOHOSTOS)" = 'windows' ]; then 18 find='/usr/bin/find' 19 fi 20 21 clone() { 22 local vcs="$1" 23 local pkg="$2" 24 local rev="$3" 25 local url="$4" 26 27 : ${url:=https://$pkg} 28 local target="vendor/src/$pkg" 29 30 echo -n "$pkg @ $rev: " 31 32 if [ -d "$target" ]; then 33 echo -n 'rm old, ' 34 rm -rf "$target" 35 fi 36 37 echo -n 'clone, ' 38 case "$vcs" in 39 git) 40 git clone --quiet --no-checkout "$url" "$target" 41 ( cd "$target" && git checkout --quiet "$rev" && git reset --quiet --hard "$rev" ) 42 ;; 43 hg) 44 hg clone --quiet --updaterev "$rev" "$url" "$target" 45 ;; 46 esac 47 48 echo -n 'rm VCS, ' 49 ( cd "$target" && rm -rf .{git,hg} ) 50 51 echo -n 'rm vendor, ' 52 ( cd "$target" && rm -rf vendor Godeps/_workspace ) 53 54 echo done 55 } 56 57 # get an ENV from the Dockerfile with support for multiline values 58 _dockerfile_env() { 59 local e="$1" 60 awk ' 61 $1 == "ENV" && $2 == "'"$e"'" { 62 sub(/^ENV +([^ ]+) +/, ""); 63 inEnv = 1; 64 } 65 inEnv { 66 if (sub(/\\$/, "")) { 67 printf "%s", $0; 68 next; 69 } 70 print; 71 exit; 72 } 73 ' ${DOCKER_FILE:="Dockerfile"} 74 } 75 76 clean() { 77 local packages=( 78 "${PROJECT}/cmd/dockerd" # daemon package main 79 "${PROJECT}/cmd/docker" # client package main 80 "${PROJECT}/integration-cli" # external tests 81 ) 82 local dockerPlatforms=( ${DOCKER_ENGINE_OSARCH:="linux/amd64"} $(_dockerfile_env DOCKER_CROSSPLATFORMS) ) 83 local dockerBuildTags="$(_dockerfile_env DOCKER_BUILDTAGS)" 84 local buildTagCombos=( 85 '' 86 'experimental' 87 'pkcs11' 88 "$dockerBuildTags" 89 "daemon $dockerBuildTags" 90 "daemon cgo $dockerBuildTags" 91 "experimental $dockerBuildTags" 92 "experimental daemon $dockerBuildTags" 93 "experimental daemon cgo $dockerBuildTags" 94 "pkcs11 $dockerBuildTags" 95 "pkcs11 daemon $dockerBuildTags" 96 "pkcs11 daemon cgo $dockerBuildTags" 97 ) 98 99 echo 100 101 echo -n 'collecting import graph, ' 102 local IFS=$'\n' 103 local imports=( $( 104 for platform in "${dockerPlatforms[@]}"; do 105 export GOOS="${platform%/*}"; 106 export GOARCH="${platform##*/}"; 107 for buildTags in "${buildTagCombos[@]}"; do 108 go list -e -tags "$buildTags" -f '{{join .Deps "\n"}}' "${packages[@]}" 109 go list -e -tags "$buildTags" -f '{{join .TestImports "\n"}}' "${packages[@]}" 110 done 111 done | grep -vE "^${PROJECT}/" | sort -u 112 ) ) 113 imports=( $(go list -e -f '{{if not .Standard}}{{.ImportPath}}{{end}}' "${imports[@]}") ) 114 unset IFS 115 116 echo -n 'pruning unused packages, ' 117 findArgs=( 118 # This directory contains only .c and .h files which are necessary 119 -path vendor/src/github.com/mattn/go-sqlite3/code 120 ) 121 122 # This package is required to build the Etcd client, 123 # but Etcd hard codes a local Godep full path. 124 # FIXME: fix_rewritten_imports fixes this problem in most platforms 125 # but it fails in very small corner cases where it makes the vendor 126 # script to remove this package. 127 # See: https://github.com/docker/docker/issues/19231 128 findArgs+=( -or -path vendor/src/github.com/ugorji/go/codec ) 129 for import in "${imports[@]}"; do 130 [ "${#findArgs[@]}" -eq 0 ] || findArgs+=( -or ) 131 findArgs+=( -path "vendor/src/$import" ) 132 done 133 134 # The docker proxy command is built from libnetwork 135 findArgs+=( -or -path vendor/src/github.com/docker/libnetwork/cmd/proxy ) 136 137 local IFS=$'\n' 138 local prune=( $($find vendor -depth -type d -not '(' "${findArgs[@]}" ')') ) 139 unset IFS 140 for dir in "${prune[@]}"; do 141 $find "$dir" -maxdepth 1 -not -type d -not -name 'LICENSE*' -not -name 'COPYING*' -exec rm -v -f '{}' ';' 142 rmdir "$dir" 2>/dev/null || true 143 done 144 145 echo -n 'pruning unused files, ' 146 $find vendor -type f -name '*_test.go' -exec rm -v '{}' ';' 147 $find vendor -type f -name 'Vagrantfile' -exec rm -v '{}' ';' 148 149 # These are the files that are left over after fix_rewritten_imports is run. 150 echo -n 'pruning .orig files, ' 151 $find vendor -type f -name '*.orig' -exec rm -v '{}' ';' 152 153 echo done 154 } 155 156 # Fix up hard-coded imports that refer to Godeps paths so they'll work with our vendoring 157 fix_rewritten_imports () { 158 local pkg="$1" 159 local remove="${pkg}/Godeps/_workspace/src/" 160 local target="vendor/src/$pkg" 161 162 echo "$pkg: fixing rewritten imports" 163 $find "$target" -name \*.go -exec sed -i'.orig' -e "s|\"${remove}|\"|g" {} \; 164 }