From 918721078fb19a060826318b4cec090f7bc646d3 Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Fri, 7 Jul 2017 18:39:11 +0200 Subject: [PATCH] godep-save.sh: add sanity checks --- hack/godep-save.sh | 47 +++++++++++++++++++++++----------------------- hack/lib/util.sh | 8 ++++++++ 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/hack/godep-save.sh b/hack/godep-save.sh index 5749eb9fac..8ce6026cc7 100755 --- a/hack/godep-save.sh +++ b/hack/godep-save.sh @@ -22,8 +22,14 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. source "${KUBE_ROOT}/hack/lib/init.sh" source "${KUBE_ROOT}/hack/lib/util.sh" +kube::util::ensure_single_dir_gopath kube::util::ensure_godep_version v79 +if [ -e "${KUBE_ROOT}/vendor" -o -e "${KUBE_ROOT}/Godeps" ]; then + echo "The directory vendor/ or Godeps/ exists. Remove them before running godep-save.sh" 1>&2 + exit 1 +fi + # Some things we want in godeps aren't code dependencies, so ./... # won't pick them up. REQUIRED_BINS=( @@ -34,34 +40,27 @@ REQUIRED_BINS=( ) pushd "${KUBE_ROOT}" > /dev/null + # sanity check that staging directories do not exist in GOPATH + error=0 + for repo in $(ls ${KUBE_ROOT}/staging/src/k8s.io); do + if [ -e "${GOPATH}/src/k8s.io/${repo}" ]; then + echo "k8s.io/${repo} exists in GOPATH. Remove before running godep-save.sh." 1>&2 + error=1 + fi + done + if [ "${error}" = "1" ]; then + exit 1 + fi + GOPATH=${GOPATH}:${KUBE_ROOT}/staging godep save "${REQUIRED_BINS[@]}" # create a symlink in vendor directory pointing to the staging client. This # let other packages use the staging client as if it were vendored. - if [ ! -e "vendor/k8s.io/api" ]; then - ln -s ../../staging/src/k8s.io/api vendor/k8s.io/api - fi - if [ ! -e "vendor/k8s.io/client-go" ]; then - ln -s ../../staging/src/k8s.io/client-go vendor/k8s.io/client-go - fi - if [ ! -e "vendor/k8s.io/apiserver" ]; then - ln -s ../../staging/src/k8s.io/apiserver vendor/k8s.io/apiserver - fi - if [ ! -e "vendor/k8s.io/apimachinery" ]; then - ln -s ../../staging/src/k8s.io/apimachinery vendor/k8s.io/apimachinery - fi - if [ ! -e "vendor/k8s.io/kube-aggregator" ]; then - ln -s ../../staging/src/k8s.io/kube-aggregator vendor/k8s.io/kube-aggregator - fi - if [ ! -e "vendor/k8s.io/apiextensions-apiserver" ]; then - ln -s ../../staging/src/k8s.io/apiextensions-apiserver vendor/k8s.io/apiextensions-apiserver - fi - if [ ! -e "vendor/k8s.io/sample-apiserver" ]; then - ln -s ../../staging/src/k8s.io/sample-apiserver vendor/k8s.io/sample-apiserver - fi - if [ ! -e "vendor/k8s.io/metrics" ]; then - ln -s ../../staging/src/k8s.io/metrics vendor/k8s.io/metrics - fi + for repo in $(ls ${KUBE_ROOT}/staging/src/k8s.io); do + if [ ! -e "vendor/k8s.io/${repo}" ]; then + ln -s "../../staging/src/k8s.io/${repo}" "vendor/k8s.io/${repo}" + fi + done popd > /dev/null echo "Don't forget to run hack/update-godep-licenses.sh if you added or removed a dependency!" diff --git a/hack/lib/util.sh b/hack/lib/util.sh index 2c23f14494..745a8982cf 100755 --- a/hack/lib/util.sh +++ b/hack/lib/util.sh @@ -513,6 +513,14 @@ kube::util::ensure_godep_version() { godep version } +# Checks that the GOPATH is simple, i.e. consists only of one directory, not multiple. +kube::util::ensure_single_dir_gopath() { + if [[ "${GOPATH}" == *:* ]]; then + echo "GOPATH must consist of a single directory." 1>&2 + exit 1 + fi +} + # Checks whether there are any files matching pattern $2 changed between the # current branch and upstream branch named by $1. # Returns 1 (false) if there are no changes, 0 (true) if there are changes