hack/verify-govet.sh
6f45c69b
 #!/bin/bash
614bf6cc
 source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
6f45c69b
 
f23f2bf0
 os::golang::verify_go_version
 
6f45c69b
 mkdir -p _output/govet
 
772b5fa0
 os::build::setup_env
 
f23f2bf0
 govet_blacklist=(
 	"pkg/auth/ldaputil/client.go:[0-9]+: assignment copies lock value to c: crypto/tls.Config contains sync.Once contains sync.Mutex"
 	"pkg/.*/client/clientset_generated/internalclientset/fake/clientset_generated.go:[0-9]+: literal copies lock value from fakePtr: github.com/openshift/origin/vendor/k8s.io/kubernetes/pkg/client/testing/core.Fake"
 	"pkg/.*/client/clientset_generated/release_1_3/fake/clientset_generated.go:30: literal copies lock value from fakePtr: github.com/openshift/origin/vendor/k8s.io/kubernetes/pkg/client/testing/core.Fake"
 )
 
 function govet_blacklist_contains() {
 	local text=$1
 	for blacklist_entry in "${govet_blacklist[@]}"; do
 		if grep -Eqx "${blacklist_entry}" <<<"${text}"; then
 			# the text we got matches this blacklist entry
 			return 0
 		fi
 	done
 	return 1
 }
 
 test_dirs="$(find_files | cut -d '/' -f 1-2 | sort -u)"
 for test_dir in ${test_dirs}; do
 	if ! result="$(go tool vet -shadow=false "${test_dir}" 2>&1)"; then
 		while read -r line; do
 			if ! govet_blacklist_contains "${line}"; then
 				echo "${line}"
 				FAILURE=true
 			fi
 		done <<<"${result}"
 	fi
6f45c69b
 done
 
27df2696
 # For the sake of slowly white-listing `shadow` checks, we need to keep track of which
 # directories we're searching through. The following are all of the directories we care about:
 # all top-level directories except for 'pkg', and all second-level subdirectories of 'pkg'.
 ALL_DIRS=$(find_files | grep -Eo "\./([^/]+|pkg/[^/]+)" | sort -u)
 
e4e3a118
 DIR_BLACKLIST='./hack
27df2696
 ./pkg/api
 ./pkg/authorization
 ./pkg/build
 ./pkg/client
 ./pkg/cmd
 ./pkg/deploy
 ./pkg/diagnostics
 ./pkg/dockerregistry
 ./pkg/generate
 ./pkg/gitserver
 ./pkg/image
 ./pkg/oauth
 ./pkg/project
dfc40a76
 ./pkg/quota
27df2696
 ./pkg/router
f57c2e0b
 ./pkg/sdn
27df2696
 ./pkg/security
 ./pkg/serviceaccounts
 ./pkg/template
 ./pkg/user
 ./pkg/util
 ./test
84d5fc63
 ./third_party
27df2696
 ./tools'
 
 for test_dir in $ALL_DIRS
 do
84d5fc63
   # use `grep` failure to determine that a directory is not in the blacklist
27df2696
   if ! echo "${DIR_BLACKLIST}" | grep -q "${test_dir}"; then
     go tool vet -shadow -shadowstrict $test_dir
     if [ "$?" -ne "0" ]
     then
       FAILURE=true
     fi
   fi
 done
 
19ec3fd8
 # We don't want to exit on the first failure of go vet, so just keep track of
 # whether a failure occurred or not.
f23f2bf0
 if [[ -n "${FAILURE:-}" ]]; then
 	echo "FAILURE: go vet failed!"
 	exit 1
6f45c69b
 else
f23f2bf0
 	echo "SUCCESS: go vet succeded!"
 	exit 0
19ec3fd8
 fi