github.com/vvnotw/moby@v1.13.1/hack/validate/pkg-imports (about) 1 #!/bin/bash 2 set -e 3 4 export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 5 source "${SCRIPTDIR}/.validate" 6 7 IFS=$'\n' 8 files=( $(validate_diff --diff-filter=ACMR --name-only -- 'pkg/*.go' || true) ) 9 unset IFS 10 11 badFiles=() 12 for f in "${files[@]}"; do 13 IFS=$'\n' 14 badImports=( $(go list -e -f '{{ join .Deps "\n" }}' "$f" | sort -u | grep -vE '^github.com/docker/docker/pkg/' | grep -vE '^github.com/docker/docker/vendor' | grep -E '^github.com/docker/docker' || true) ) 15 unset IFS 16 17 for import in "${badImports[@]}"; do 18 badFiles+=( "$f imports $import" ) 19 done 20 done 21 22 if [ ${#badFiles[@]} -eq 0 ]; then 23 echo 'Congratulations! "./pkg/..." is safely isolated from internal code.' 24 else 25 { 26 echo 'These files import internal code: (either directly or indirectly)' 27 for f in "${badFiles[@]}"; do 28 echo " - $f" 29 done 30 echo 31 } >&2 32 false 33 fi