diff --git a/.travis.yml b/.travis.yml index 97e132661cd..4fd6dcd6715 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,6 +54,7 @@ script: GOARCH=386 PASSES="build unit" ./test ;; *) - GOARCH="${TARGET}" ./build + # test building out of gopath + GO_BUILD_FLAGS="-a -v" GOPATH=/bad-go-path GOARCH="${TARGET}" ./build ;; esac diff --git a/build b/build index c1a00ad6a9c..9143ca1024e 100755 --- a/build +++ b/build @@ -1,8 +1,5 @@ #!/bin/sh -e -CDIR=$(cd `dirname "$0"` && pwd) -cd "$CDIR" - # set some environment variables ORG_PATH="github.com/coreos" REPO_PATH="${ORG_PATH}/etcd" @@ -34,11 +31,13 @@ etcd_build() { if [ -n "${BINDIR}" ]; then out="${BINDIR}"; fi toggle_failpoints # Static compilation is useful when etcd is run in a container - CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "-s -X ${REPO_PATH}/cmd/vendor/${REPO_PATH}/version.GitSHA=${GIT_SHA}" -o ${out}/etcd ${REPO_PATH}/cmd/etcd - CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "-s" -o ${out}/etcdctl ${REPO_PATH}/cmd/etcdctl + CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "-s -X ${REPO_PATH}/cmd/vendor/${REPO_PATH}/version.GitSHA=${GIT_SHA}" -o ${out}/etcd ${REPO_PATH}/cmd/etcd || return + CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "-s" -o ${out}/etcdctl ${REPO_PATH}/cmd/etcdctl || return } etcd_setup_gopath() { + CDIR=$(cd `dirname "$0"` && pwd) + cd "$CDIR" etcdGOPATH=${CDIR}/gopath # preserve old gopath to support building with unvendored tooling deps (e.g., gofail) export GOPATH=${etcdGOPATH}:$GOPATH @@ -49,5 +48,9 @@ etcd_setup_gopath() { toggle_failpoints -# don't build when sourced -(echo "$0" | grep "/build$" > /dev/null) && etcd_build || true +# only build when called directly, not sourced +if echo "$0" | grep "build$" >/dev/null; then + # force new gopath so builds outside of gopath work + etcd_setup_gopath + etcd_build +fi