Skip to content

Commit

Permalink
Merge pull request #6198 from heyitsanthony/reenable-outside-gopath
Browse files Browse the repository at this point in the history
build: re-enable building outside gopath
  • Loading branch information
Anthony Romano authored Aug 18, 2016
2 parents a20d4a2 + 83dd121 commit cc4f4b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 10 additions & 7 deletions build
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit cc4f4b4

Please sign in to comment.