test, build: make build script source-able without doing a build

This commit is contained in:
Anthony Romano 2016-06-21 12:12:50 -07:00
parent 22bae02fe5
commit 6009e88077
2 changed files with 22 additions and 22 deletions

26
build
View File

@ -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="="
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
}
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${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

18
test
View File

@ -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