From 6009e88077f3e55cce714f65cc284dc8b252f85b Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Tue, 21 Jun 2016 12:12:50 -0700 Subject: [PATCH] test, build: make build script source-able without doing a build --- build | 26 +++++++++++++------------- test | 18 +++++++++--------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/build b/build index 407645415a5..61efec54e50 100755 --- a/build +++ b/build @@ -1,22 +1,22 @@ #!/bin/sh -e +# set some environment variables ORG_PATH="github.com/coreos" REPO_PATH="${ORG_PATH}/etcd" - export GO15VENDOREXPERIMENT="1" - eval $(go env) - GIT_SHA=`git rev-parse --short HEAD || echo "GitNotFound"` -LINK_OPERATOR="=" - -if [ -z "${GOARCH}" ] || [ "${GOARCH}" = "$(go env GOHOSTARCH)" ]; then - out="bin" -else - out="bin/${GOARCH}" -fi +etcd_build() { + if [ -z "${GOARCH}" ] || [ "${GOARCH}" = "$(go env GOHOSTARCH)" ]; then + out="bin" + else + out="bin/${GOARCH}" + fi + # 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 + CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "-s" -o ${out}/etcdctl ${REPO_PATH}/cmd/etcdctl +} -# 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${LINK_OPERATOR}${GIT_SHA}" -o ${out}/etcd ${REPO_PATH}/cmd -CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "-s" -o ${out}/etcdctl ${REPO_PATH}/cmd/etcdctl +# don't build when sourced +(echo "$0" | grep "/build$") && etcd_build || true diff --git a/test b/test index d3504ac9838..0e8090a4c2a 100755 --- a/test +++ b/test @@ -10,6 +10,8 @@ # PKG=snap ./test set -e +source ./build + # TODO: 'client' pkg fails with gosimple from generated files # TODO: 'rafttest' is failing with unused GOSIMPLE_UNUSED_PATHS=$(go list ./... | sed -e 's/github.com\/coreos\/etcd\///g' | grep -vE 'cmd|vendor|rafttest|github.com/coreos/etcd$|client$') @@ -17,15 +19,6 @@ GOSIMPLE_UNUSED_PATHS=$(go list ./... | sed -e 's/github.com\/coreos\/etcd\///g' # Invoke ./cover for HTML output COVER=${COVER:-"-cover"} -GO_BUILD_FLAGS="-a -v" -source ./build - -# Set up gopath so tests use vendored dependencies -export GOPATH=${PWD}/gopath -rm -rf $GOPATH/src -mkdir -p $GOPATH -ln -s ${PWD}/cmd/vendor $GOPATH/src - # Hack: gofmt ./ will recursively check the .git directory. So use *.go for gofmt. IGNORE_PKGS="(cmd|vendor|etcdserverpb|rafttest)" INTEGRATION_PKGS="(integration|e2e|contrib|functional-tester)" @@ -168,7 +161,14 @@ function dep_tests { fi } +# Set up gopath so tests use vendored dependencies +export GOPATH=${PWD}/gopath +rm -rf $GOPATH/src +mkdir -p $GOPATH +ln -s ${PWD}/cmd/vendor $GOPATH/src + # fail fast on static tests +GO_BUILD_FLAGS="-a -v" etcd_build fmt_tests dep_tests