Skip to content

Commit

Permalink
test, build: make build script source-able without doing a build
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Romano committed Jun 21, 2016
1 parent 22bae02 commit 6009e88
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
26 changes: 13 additions & 13 deletions build
Original file line number Diff line number Diff line change
@@ -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
18 changes: 9 additions & 9 deletions test
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,15 @@
# 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$')

# 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)"
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 6009e88

Please sign in to comment.