Skip to content

Commit a29c048

Browse files
committed
Clean up godep scripts to be self-contained
1 parent 7732c8d commit a29c048

6 files changed

+76
-42
lines changed

hack/godep-restore.sh

+10-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,15 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
2222
source "${KUBE_ROOT}/hack/lib/init.sh"
2323
source "${KUBE_ROOT}/hack/lib/util.sh"
2424

25+
kube::log::status "Restoring kubernetes godeps"
26+
27+
if kube::util::godep_restored >/dev/null 2>&1; then
28+
kube::log::status "Dependencies appear to be current - skipping download"
29+
exit 0
30+
fi
31+
2532
kube::util::ensure_godep_version
2633

27-
kube::log::status "Starting to download all kubernetes godeps. This takes a while"
28-
GOPATH=${GOPATH}:${KUBE_ROOT}/staging godep restore "$@"
29-
kube::log::status "Download finished"
34+
kube::log::status "Downloading dependencies - this might take a while"
35+
GOPATH="${GOPATH}:${KUBE_ROOT}/staging" godep restore "$@"
36+
kube::log::status "Done"

hack/godep-save.sh

+52-24
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,35 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
2222
source "${KUBE_ROOT}/hack/lib/init.sh"
2323
source "${KUBE_ROOT}/hack/lib/util.sh"
2424

25+
kube::log::status "Ensuring prereqs"
2526
kube::util::ensure_single_dir_gopath
26-
kube::util::ensure_godep_version
2727
kube::util::ensure_no_staging_repos_in_gopath
2828

29-
if [ -e "${KUBE_ROOT}/vendor" -o -e "${KUBE_ROOT}/Godeps" ]; then
30-
echo "The directory vendor/ or Godeps/ exists. Remove them before running godep-save.sh" 1>&2
31-
exit 1
29+
kube::util::ensure_godep_version
30+
31+
BACKUP=_tmp/godep-save.$RANDOM
32+
mkdir -p "${BACKUP}"
33+
34+
function kube::godep_save::cleanup() {
35+
if [[ -d "${BACKUP}/vendor" ]]; then
36+
kube::log::error "${BACKUP}/vendor exists, restoring it"
37+
rm -rf vendor
38+
mv "${BACKUP}/vendor" vendor
39+
fi
40+
if [[ -d "${BACKUP}/Godeps" ]]; then
41+
kube::log::error "${BACKUP}/Godeps exists, restoring it"
42+
rm -rf Godeps
43+
mv "${BACKUP}/Godeps" Godeps
44+
fi
45+
}
46+
kube::util::trap_add kube::godep_save::cleanup EXIT
47+
48+
# Clear old state, but save it in case of error
49+
if [[ -d vendor ]]; then
50+
mv vendor "${BACKUP}/vendor"
51+
fi
52+
if [[ -d Godeps ]]; then
53+
mv Godeps "${BACKUP}/Godeps"
3254
fi
3355

3456
# Some things we want in godeps aren't code dependencies, so ./...
@@ -39,23 +61,29 @@ REQUIRED_BINS=(
3961
"./..."
4062
)
4163

42-
pushd "${KUBE_ROOT}" > /dev/null
43-
echo "Running godep save. This will take around 15 minutes."
44-
GOPATH=${GOPATH}:${KUBE_ROOT}/staging godep save "${REQUIRED_BINS[@]}"
45-
46-
# create a symlink in vendor directory pointing to the staging client. This
47-
# let other packages use the staging client as if it were vendored.
48-
for repo in $(ls ${KUBE_ROOT}/staging/src/k8s.io); do
49-
if [ ! -e "vendor/k8s.io/${repo}" ]; then
50-
ln -s "../../staging/src/k8s.io/${repo}" "vendor/k8s.io/${repo}"
51-
fi
52-
done
53-
popd > /dev/null
54-
55-
# Workaround broken symlink in docker repo because godep copies the link, but not the target
56-
rm -rf ${KUBE_ROOT}/vendor/github.com/docker/docker/project/
57-
58-
echo
59-
echo "Don't forget to run:"
60-
echo "- hack/update-bazel.sh to recreate the BUILD files"
61-
echo "- hack/update-godep-licenses.sh if you added or removed a dependency!"
64+
kube::log::status "Running godep save - this might take a while"
65+
# This uses $(pwd) rather than ${KUBE_ROOT} because KUBE_ROOT will be
66+
# realpath'ed, and godep barfs ("... is not using a known version control
67+
# system") on our staging dirs.
68+
GOPATH="${GOPATH}:$(pwd)/staging" godep save "${REQUIRED_BINS[@]}"
69+
70+
# create a symlink in vendor directory pointing to the staging client. This
71+
# let other packages use the staging client as if it were vendored.
72+
for repo in $(ls staging/src/k8s.io); do
73+
if [ ! -e "vendor/k8s.io/${repo}" ]; then
74+
ln -s "../../staging/src/k8s.io/${repo}" "vendor/k8s.io/${repo}"
75+
fi
76+
done
77+
78+
# Workaround broken symlink in docker repo because godep copies the link, but
79+
# not the target
80+
rm -rf vendor/github.com/docker/docker/project/
81+
82+
kube::log::status "Updating BUILD files"
83+
hack/update-bazel.sh >/dev/null
84+
85+
kube::log::status "Updating LICENSES file"
86+
hack/update-godep-licenses.sh >/dev/null
87+
88+
# Clean up
89+
rm -rf "${BACKUP}"

hack/lib/util.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ kube::util::trap_add() {
8585
if [[ -z "${existing_cmd}" ]]; then
8686
new_cmd="${trap_add_cmd}"
8787
else
88-
new_cmd="${existing_cmd};${trap_add_cmd}"
88+
new_cmd="${trap_add_cmd};${existing_cmd}"
8989
fi
9090

9191
# Assign the test

hack/update-all.sh

+1-6
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,7 @@ if ! $ALL ; then
5353
echo "Running in short-circuit mode; run with -a to force all scripts to run."
5454
fi
5555

56-
kube::util::ensure_godep_version
57-
58-
if ! kube::util::godep_restored 2>&1 | sed 's/^/ /'; then
59-
echo "Running godep restore"
60-
"${KUBE_ROOT}/hack/godep-restore.sh" ${V}
61-
fi
56+
"${KUBE_ROOT}/hack/godep-restore.sh" ${V}
6257

6358
BASH_TARGETS="
6459
update-generated-protobuf

hack/update-bazel.sh

+11-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,17 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
2525
rm -f "${KUBE_ROOT}/pkg/generated/openapi/zz_generated.openapi.go"
2626

2727
# The git commit sha1s here should match the values in $KUBE_ROOT/WORKSPACE.
28-
kube::util::go_install_from_commit github.com/kubernetes/repo-infra/kazel 4eaf9e671bbb549fb4ec292cf251f921d7ef80ac
29-
kube::util::go_install_from_commit github.com/bazelbuild/rules_go/go/tools/gazelle/gazelle 82483596ec203eb9c1849937636f4cbed83733eb
28+
kube::util::go_install_from_commit \
29+
github.com/kubernetes/repo-infra/kazel \
30+
4eaf9e671bbb549fb4ec292cf251f921d7ef80ac
31+
kube::util::go_install_from_commit \
32+
github.com/bazelbuild/rules_go/go/tools/gazelle/gazelle \
33+
82483596ec203eb9c1849937636f4cbed83733eb
3034

3135
touch "${KUBE_ROOT}/vendor/BUILD"
3236

33-
gazelle fix -build_file_name=BUILD,BUILD.bazel -external=vendored -mode=fix -repo_root="$(kube::realpath ${KUBE_ROOT})"
34-
kazel -root="$(kube::realpath ${KUBE_ROOT})"
37+
gazelle fix \
38+
-build_file_name=BUILD,BUILD.bazel \
39+
-external=vendored \
40+
-mode=fix
41+
kazel

hack/update-staging-godeps-dockerized.sh

+1-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ kube::util::ensure_godep_version
6161
# Create a fake git repo the root of the repo to prevent godeps from complaining
6262
kube::util::create-fake-git-tree "${KUBE_ROOT}"
6363

64-
kube::log::status "Checking whether godeps are restored"
65-
if ! kube::util::godep_restored 2>&1 | sed 's/^/ /'; then
66-
${KUBE_ROOT}/hack/godep-restore.sh
67-
fi
64+
"${KUBE_ROOT}/hack/godep-restore.sh"
6865

6966
kube::util::ensure-temp-dir
7067
TMP_GOPATH="${KUBE_TEMP}/go"

0 commit comments

Comments
 (0)