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