Browse Source

Merge pull request #9356 from mkumatag/fix_gopath

test, build: Fix gopath creation
Gyuho Lee 7 years ago
parent
commit
d4aeb3b8cf
2 changed files with 46 additions and 1 deletions
  1. 41 0
      build
  2. 5 1
      test

+ 41 - 0
build

@@ -23,6 +23,26 @@ toggle_failpoints() {
 	fi
 }
 
+etcd_setup_gopath() {
+	echo "Setting GOPATH from vendor directory at 'gopath'"
+	d=$(dirname "$0")
+	CDIR=$(cd "$d" && pwd)
+	cd "$CDIR"
+	etcdGOPATH="${CDIR}/gopath"
+	# preserve old gopath to support building with unvendored tooling deps (e.g., gofail)
+	if [ -n "$GOPATH" ]; then
+		GOPATH="$GOPATH"
+	fi
+	rm -rf "${etcdGOPATH:?}/"
+	mkdir -p "${etcdGOPATH}/vendor" "${etcdGOPATH}/etcd_src/src/github.com/coreos"
+	export GOPATH=${etcdGOPATH}/vendor:${etcdGOPATH}/etcd_src:$GOPATH
+	ln -s "${CDIR}/vendor" "${etcdGOPATH}/vendor/src"
+	ln -s "${CDIR}" "${etcdGOPATH}/etcd_src/src/github.com/coreos/etcd"
+
+	#ln -s "${CDIR}/vendor" "${etcdGOPATH}/src"
+	#ln -s "${CDIR}" "${etcdGOPATH}/src/github.com/coreos"
+}
+
 toggle_failpoints_default() {
 	mode="disable"
 	if [ ! -z "$FAILPOINTS" ]; then mode="enable"; fi
@@ -41,6 +61,27 @@ etcd_build() {
 	CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "$GO_LDFLAGS" -o "${out}/etcdctl" ${REPO_PATH}/etcdctl || return
 }
 
+tools_build() {
+	out="bin"
+	if [ -n "${BINDIR}" ]; then out="${BINDIR}"; fi
+	# shellcheck disable=SC2039
+	tools=(
+		benchmark
+		etcd-dump-db
+		etcd-dump-logs
+		functional-tester/etcd-agent
+		functional-tester/etcd-tester
+		functional-tester/etcd-runner
+		local-tester/bridge
+	)
+	# shellcheck disable=SC2039
+	for tool in "${tools[@]}"
+	do
+		# shellcheck disable=SC2086
+		CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "$GO_LDFLAGS" -o "${out}/${tool}" "${REPO_PATH}/tools/${tool}" || return
+	done
+}
+
 toggle_failpoints_default
 
 # only build when called directly, not sourced

+ 5 - 1
test

@@ -16,6 +16,10 @@ set -e
 
 source ./build
 
+if [[ "${ETCD_SETUP_GOPATH}" == "1" ]]; then
+	etcd_setup_gopath
+fi
+
 # build before setting up test GOPATH
 if [[ "${PASSES}" == *"functional"* ]]; then
 	./tools/functional-tester/build
@@ -542,7 +546,7 @@ function build_cov_pass {
 
 function compile_pass {
 	echo "Checking build..."
-	go build -v ./tools/...
+	GO_BUILD_FLAGS="-a -v" tools_build
 }
 
 # fail fast on static tests