Use cd and pwd in a subshell to define ${KUBE_REPO_ROOT}

The old method (using `readlink`) was convoluted and not portable. We
can achieve the same result using only bash builtins.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
This commit is contained in:
Filipe Brandenburger 2014-08-27 20:33:58 -07:00
parent 09dd081543
commit 391cd856c1

View File

@ -103,16 +103,15 @@ kube::setup_go_environment() {
# KUBE_TARGET - Path where output Go files are saved. # KUBE_TARGET - Path where output Go files are saved.
# KUBE_GO_PACKAGE - Full name of the Kubernetes Go package. # KUBE_GO_PACKAGE - Full name of the Kubernetes Go package.
KUBE_REPO_ROOT=$(dirname "${BASH_SOURCE:-$0}")/.. # Make ${KUBE_REPO_ROOT} an absolute path.
if [[ "${OSTYPE:-}" == *darwin* ]]; then KUBE_REPO_ROOT=$(
# Make the path absolute if it is not. set -eu
if [[ "${KUBE_REPO_ROOT}" != /* ]]; then unset CDPATH
KUBE_REPO_ROOT=${PWD}/${KUBE_REPO_ROOT} scripts_dir=$(dirname "${BASH_SOURCE[0]}")
fi cd "${scripts_dir}"
else cd ..
# Resolve symlinks. pwd
KUBE_REPO_ROOT=$(readlink -f "${KUBE_REPO_ROOT}") )
fi
export KUBE_REPO_ROOT export KUBE_REPO_ROOT
KUBE_TARGET="${KUBE_REPO_ROOT}/output/go" KUBE_TARGET="${KUBE_REPO_ROOT}/output/go"