Clean up godep scripts to be self-contained

pull/6/head
Tim Hockin 2017-08-31 22:29:32 -07:00
parent 7732c8d892
commit a29c048e33
6 changed files with 73 additions and 39 deletions

View File

@ -22,8 +22,15 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"
source "${KUBE_ROOT}/hack/lib/util.sh"
kube::log::status "Restoring kubernetes godeps"
if kube::util::godep_restored >/dev/null 2>&1; then
kube::log::status "Dependencies appear to be current - skipping download"
exit 0
fi
kube::util::ensure_godep_version
kube::log::status "Starting to download all kubernetes godeps. This takes a while"
GOPATH=${GOPATH}:${KUBE_ROOT}/staging godep restore "$@"
kube::log::status "Download finished"
kube::log::status "Downloading dependencies - this might take a while"
GOPATH="${GOPATH}:${KUBE_ROOT}/staging" godep restore "$@"
kube::log::status "Done"

View File

@ -22,13 +22,35 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"
source "${KUBE_ROOT}/hack/lib/util.sh"
kube::log::status "Ensuring prereqs"
kube::util::ensure_single_dir_gopath
kube::util::ensure_godep_version
kube::util::ensure_no_staging_repos_in_gopath
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
kube::util::ensure_godep_version
BACKUP=_tmp/godep-save.$RANDOM
mkdir -p "${BACKUP}"
function kube::godep_save::cleanup() {
if [[ -d "${BACKUP}/vendor" ]]; then
kube::log::error "${BACKUP}/vendor exists, restoring it"
rm -rf vendor
mv "${BACKUP}/vendor" vendor
fi
if [[ -d "${BACKUP}/Godeps" ]]; then
kube::log::error "${BACKUP}/Godeps exists, restoring it"
rm -rf Godeps
mv "${BACKUP}/Godeps" Godeps
fi
}
kube::util::trap_add kube::godep_save::cleanup EXIT
# Clear old state, but save it in case of error
if [[ -d vendor ]]; then
mv vendor "${BACKUP}/vendor"
fi
if [[ -d Godeps ]]; then
mv Godeps "${BACKUP}/Godeps"
fi
# Some things we want in godeps aren't code dependencies, so ./...
@ -39,23 +61,29 @@ REQUIRED_BINS=(
"./..."
)
pushd "${KUBE_ROOT}" > /dev/null
echo "Running godep save. This will take around 15 minutes."
GOPATH=${GOPATH}:${KUBE_ROOT}/staging godep save "${REQUIRED_BINS[@]}"
kube::log::status "Running godep save - this might take a while"
# This uses $(pwd) rather than ${KUBE_ROOT} because KUBE_ROOT will be
# realpath'ed, and godep barfs ("... is not using a known version control
# system") on our staging dirs.
GOPATH="${GOPATH}:$(pwd)/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.
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
# create a symlink in vendor directory pointing to the staging client. This
# let other packages use the staging client as if it were vendored.
for repo in $(ls 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
# Workaround broken symlink in docker repo because godep copies the link, but not the target
rm -rf ${KUBE_ROOT}/vendor/github.com/docker/docker/project/
# Workaround broken symlink in docker repo because godep copies the link, but
# not the target
rm -rf vendor/github.com/docker/docker/project/
echo
echo "Don't forget to run:"
echo "- hack/update-bazel.sh to recreate the BUILD files"
echo "- hack/update-godep-licenses.sh if you added or removed a dependency!"
kube::log::status "Updating BUILD files"
hack/update-bazel.sh >/dev/null
kube::log::status "Updating LICENSES file"
hack/update-godep-licenses.sh >/dev/null
# Clean up
rm -rf "${BACKUP}"

View File

@ -85,7 +85,7 @@ kube::util::trap_add() {
if [[ -z "${existing_cmd}" ]]; then
new_cmd="${trap_add_cmd}"
else
new_cmd="${existing_cmd};${trap_add_cmd}"
new_cmd="${trap_add_cmd};${existing_cmd}"
fi
# Assign the test

View File

@ -53,12 +53,7 @@ if ! $ALL ; then
echo "Running in short-circuit mode; run with -a to force all scripts to run."
fi
kube::util::ensure_godep_version
if ! kube::util::godep_restored 2>&1 | sed 's/^/ /'; then
echo "Running godep restore"
"${KUBE_ROOT}/hack/godep-restore.sh" ${V}
fi
"${KUBE_ROOT}/hack/godep-restore.sh" ${V}
BASH_TARGETS="
update-generated-protobuf

View File

@ -25,10 +25,17 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
rm -f "${KUBE_ROOT}/pkg/generated/openapi/zz_generated.openapi.go"
# The git commit sha1s here should match the values in $KUBE_ROOT/WORKSPACE.
kube::util::go_install_from_commit github.com/kubernetes/repo-infra/kazel 4eaf9e671bbb549fb4ec292cf251f921d7ef80ac
kube::util::go_install_from_commit github.com/bazelbuild/rules_go/go/tools/gazelle/gazelle 82483596ec203eb9c1849937636f4cbed83733eb
kube::util::go_install_from_commit \
github.com/kubernetes/repo-infra/kazel \
4eaf9e671bbb549fb4ec292cf251f921d7ef80ac
kube::util::go_install_from_commit \
github.com/bazelbuild/rules_go/go/tools/gazelle/gazelle \
82483596ec203eb9c1849937636f4cbed83733eb
touch "${KUBE_ROOT}/vendor/BUILD"
gazelle fix -build_file_name=BUILD,BUILD.bazel -external=vendored -mode=fix -repo_root="$(kube::realpath ${KUBE_ROOT})"
kazel -root="$(kube::realpath ${KUBE_ROOT})"
gazelle fix \
-build_file_name=BUILD,BUILD.bazel \
-external=vendored \
-mode=fix
kazel

View File

@ -61,10 +61,7 @@ kube::util::ensure_godep_version
# Create a fake git repo the root of the repo to prevent godeps from complaining
kube::util::create-fake-git-tree "${KUBE_ROOT}"
kube::log::status "Checking whether godeps are restored"
if ! kube::util::godep_restored 2>&1 | sed 's/^/ /'; then
${KUBE_ROOT}/hack/godep-restore.sh
fi
"${KUBE_ROOT}/hack/godep-restore.sh"
kube::util::ensure-temp-dir
TMP_GOPATH="${KUBE_TEMP}/go"