@@ -22,13 +22,35 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
22
22
source " ${KUBE_ROOT} /hack/lib/init.sh"
23
23
source " ${KUBE_ROOT} /hack/lib/util.sh"
24
24
25
+ kube::log::status " Ensuring prereqs"
25
26
kube::util::ensure_single_dir_gopath
26
- kube::util::ensure_godep_version
27
27
kube::util::ensure_no_staging_repos_in_gopath
28
28
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"
32
54
fi
33
55
34
56
# Some things we want in godeps aren't code dependencies, so ./...
@@ -39,23 +61,29 @@ REQUIRED_BINS=(
39
61
" ./..."
40
62
)
41
63
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} "
0 commit comments