Skip to content

Commit

Permalink
Clean up godep scripts to be self-contained
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Sep 29, 2017
1 parent 7732c8d commit a29c048
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 42 deletions.
13 changes: 10 additions & 3 deletions hack/godep-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
76 changes: 52 additions & 24 deletions hack/godep-save.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand All @@ -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[@]}"

# 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

# 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/

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 "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 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 vendor/github.com/docker/docker/project/

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}"
2 changes: 1 addition & 1 deletion hack/lib/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions hack/update-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions hack/update-bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions hack/update-staging-godeps-dockerized.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a29c048

Please sign in to comment.