Skip to content

Commit

Permalink
Merge pull request kubernetes#11860 from ingvagabund/delimiter-for-X-…
Browse files Browse the repository at this point in the history
…option-eparis

Use the correct delimiter for -X option of --ldflags (more readable solution)
  • Loading branch information
mikedanese committed Jul 29, 2015
2 parents ff18190 + 3a90386 commit 9f16fd9
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions hack/lib/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,39 @@ kube::version::load_version_vars() {
source "${version_file}"
}

# golang 1.5 wants `-X key=val`, but golang 1.4- REQUIRES `-X key val`
kube::version::ldflag() {
local key=${1}
local val=${2}

GO_VERSION=($(go version))

if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.5') ]]; then
echo "-X ${KUBE_GO_PACKAGE}/pkg/version.${key} ${val}"
else
echo "-X ${KUBE_GO_PACKAGE}/pkg/version.${key}=${val}"
fi
}

# Prints the value that needs to be passed to the -ldflags parameter of go build
# in order to set the Kubernetes based on the git tree status.
kube::version::ldflags() {
kube::version::get_version_vars

local -a ldflags=()
if [[ -n ${KUBE_GIT_COMMIT-} ]]; then
ldflags+=(-X "${KUBE_GO_PACKAGE}/pkg/version.gitCommit" "${KUBE_GIT_COMMIT}")
ldflags+=(-X "${KUBE_GO_PACKAGE}/pkg/version.gitTreeState" "${KUBE_GIT_TREE_STATE}")
ldflags+=($(kube::version::ldflag "gitCommit" "${KUBE_GIT_COMMIT}"))
ldflags+=($(kube::version::ldflag "gitTreeState" "${KUBE_GIT_TREE_STATE}"))
fi

if [[ -n ${KUBE_GIT_VERSION-} ]]; then
ldflags+=(-X "${KUBE_GO_PACKAGE}/pkg/version.gitVersion" "${KUBE_GIT_VERSION}")
ldflags+=($(kube::version::ldflag "gitVersion" "${KUBE_GIT_VERSION}"))
fi

if [[ -n ${KUBE_GIT_MAJOR-} && -n ${KUBE_GIT_MINOR-} ]]; then
ldflags+=(
-X "${KUBE_GO_PACKAGE}/pkg/version.gitMajor" "${KUBE_GIT_MAJOR}"
-X "${KUBE_GO_PACKAGE}/pkg/version.gitMinor" "${KUBE_GIT_MINOR}"
$(kube::version::ldflag "gitMajor" "${KUBE_GIT_MAJOR}")
$(kube::version::ldflag "gitMinor" "${KUBE_GIT_MINOR}")
)
fi

Expand Down

0 comments on commit 9f16fd9

Please sign in to comment.