Browse Source

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

Anthony Romano 9 years ago
parent
commit
6009e88077
2 changed files with 22 additions and 22 deletions
  1. 13 13
      build
  2. 9 9
      test

+ 13 - 13
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

+ 9 - 9
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