Skip to content

Commit

Permalink
Fix shell script quoting, clean up build scripts
Browse files Browse the repository at this point in the history
Fix quoting so that it works with arbitrary path names (e.g. containing
spaces.)  Make hack/config-go.sh non-executable since it is meant for
sourcing and not as a standalone.

Tested:
- Checked out the tree to a directory with spaces, called the
  build script from outside the tree, confirmed it worked as expected.
- Confirmed binaries work by running them with -version.
- Ran hack/build-go.sh cmd/kubecfg and confirmed only kubecfg was built.
- Ran hack/build-go.sh cmd/integration and confirmed it was built.
- Checked it out on a Mac and confirmed that the build script works.
- Confirmed that hack/test-go.sh and hack/test-cmd.sh work.

Signed-off-by: Filipe Brandenburger <[email protected]>
  • Loading branch information
filbranden committed Aug 1, 2014
1 parent d7396ac commit d00e08b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 36 deletions.
28 changes: 19 additions & 9 deletions hack/build-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,29 @@

# This script sets up a go workspace locally and builds all go components.

set -e
set -o errexit
set -o nounset
set -o pipefail

# Update the version.
$(dirname $0)/version-gen.sh
hackdir=$(dirname "$0")

source $(dirname $0)/config-go.sh
# Set the environment variables required by the build.
. "${hackdir}/config-go.sh"

cd "${KUBE_TARGET}"
# Go to the top of the tree.
cd "${KUBE_REPO_ROOT}"

BINARIES="cmd/proxy cmd/apiserver cmd/controller-manager cmd/kubelet cmd/kubecfg"
# Update the version.
"${hackdir}/version-gen.sh"

if [ $# -gt 0 ]; then
BINARIES="$@"
if [[ $# == 0 ]]; then
# Update $@ with the default list of targets to build.
set -- cmd/proxy cmd/apiserver cmd/controller-manager cmd/kubelet cmd/kubecfg
fi

go install $(for b in $BINARIES; do echo "${KUBE_GO_PACKAGE}"/${b}; done)
binaries=()
for arg; do
binaries+=("${KUBE_GO_PACKAGE}/${arg}")
done

go install "${binaries[@]}"
53 changes: 26 additions & 27 deletions hack/config-go.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,50 @@
# This script sets up a go workspace locally and builds all go components.
# You can 'source' this file if you want to set up GOPATH in your local shell.

if [[ "$(which go)" == "" ]]; then
echo "Can't find 'go' in PATH, please fix and retry."
echo "See http://golang.org/doc/install for installation instructions."
exit 1
if [[ -z "$(which go)" ]]; then
echo "Can't find 'go' in PATH, please fix and retry." >&2
echo "See http://golang.org/doc/install for installation instructions." >&2
exit 1
fi

# Travis continuous build uses a head go release that doesn't report
# a version number, so we skip this check on Travis. Its unnecessary
# there anyway.
if [ "${TRAVIS}" != "true" ]; then
if [[ "${TRAVIS:-}" != "true" ]]; then
GO_VERSION=($(go version))

if [[ ${GO_VERSION[2]} < "go1.2" ]]; then
echo "Detected go version: ${GO_VERSION}."
echo "Kubernetes requires go version 1.2 or greater."
echo "Please install Go version 1.2 or later"
if [[ "${GO_VERSION[2]}" < "go1.2" ]]; then
echo "Detected go version: ${GO_VERSION[*]}." >&2
echo "Kubernetes requires go version 1.2 or greater." >&2
echo "Please install Go version 1.2 or later" >&2
exit 1
fi
fi

if [[ "$OSTYPE" == *darwin* ]]; then
KUBE_REPO_ROOT="${PWD}/$(dirname ${BASH_SOURCE:-$0})/.."
KUBE_REPO_ROOT=$(dirname "${BASH_SOURCE:-$0}")/..
if [[ "${OSTYPE:-}" == *darwin* ]]; then
# Make the path absolute if it is not.
if [[ "${KUBE_REPO_ROOT}" != /* ]]; then
KUBE_REPO_ROOT=${PWD}/${KUBE_REPO_ROOT}
fi
else
KUBE_REPO_REL_ROOT="$(dirname ${BASH_SOURCE:-$0})/.."
KUBE_REPO_ROOT="$(readlink -f ${KUBE_REPO_REL_ROOT})"
# Resolve symlinks.
KUBE_REPO_ROOT=$(readlink -f "${KUBE_REPO_ROOT}")
fi

KUBE_TARGET="${KUBE_REPO_ROOT}/output/go"

mkdir -p "${KUBE_TARGET}"

KUBE_GO_PACKAGE=github.com/GoogleCloudPlatform/kubernetes
export GOPATH="${KUBE_TARGET}"
KUBE_GO_PACKAGE_DIR="${GOPATH}/src/${KUBE_GO_PACKAGE}"
KUBE_GO_PACKAGE_DIR="${KUBE_TARGET}/src/${KUBE_GO_PACKAGE}"

(
PACKAGE_BASE=$(dirname "${KUBE_GO_PACKAGE_DIR}")
if [ ! -d "${PACKAGE_BASE}" ]; then
mkdir -p "${PACKAGE_BASE}"
fi
KUBE_GO_PACKAGE_BASEDIR=$(dirname "${KUBE_GO_PACKAGE_DIR}")
mkdir -p "${KUBE_GO_PACKAGE_BASEDIR}"

# Create symlink under output/go/src.
ln -snf "${KUBE_REPO_ROOT}" "${KUBE_GO_PACKAGE_DIR}"

rm "${KUBE_GO_PACKAGE_DIR}" >/dev/null 2>&1 || true
ln -s "${KUBE_REPO_ROOT}" "${KUBE_GO_PACKAGE_DIR}"
)
GOPATH="${KUBE_TARGET}:${KUBE_REPO_ROOT}/third_party"
export GOPATH

# unset GOBIN in case it already exsit in the current session
# Unset GOBIN in case it already exsits in the current session.
unset GOBIN
export GOPATH="${KUBE_TARGET}:${KUBE_REPO_ROOT}/third_party"

0 comments on commit d00e08b

Please sign in to comment.