Переглянути джерело

Move the body of go_compile_test_dir into a file since GNU Parallel breaks on sourcing exported Bash functions thanks to the shellshock fixes

Signed-off-by: Andrew Page <admwiggin@gmail.com>
Tianon Gravi 10 роки тому
батько
коміт
8ffdf6022e
3 змінених файлів з 28 додано та 28 видалено
  1. 0 25
      hack/make.sh
  2. 26 0
      hack/make/.go-compile-test-dir
  3. 2 3
      hack/make/test-unit

+ 0 - 25
hack/make.sh

@@ -169,31 +169,6 @@ go_test_dir() {
 	)
 	)
 }
 }
 
 
-# Compile phase run by parallel in test-unit. No support for coverpkg
-go_compile_test_dir() {
-	dir=$1
-	out_file="$DEST/precompiled/$dir.test"
-	testcover=()
-	if [ "$HAVE_GO_TEST_COVER" ]; then
-		# if our current go install has -cover, we want to use it :)
-		mkdir -p "$DEST/coverprofiles"
-		coverprofile="docker${dir#.}"
-		coverprofile="$DEST/coverprofiles/${coverprofile//\//-}"
-		testcover=( -cover -coverprofile "$coverprofile" ) # missing $coverpkg
-	fi
-	if [ "$BUILDFLAGS_FILE" ]; then
-		readarray -t BUILDFLAGS < "$BUILDFLAGS_FILE"
-	fi
-	(
-		cd "$dir"
-		go test "${testcover[@]}" -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $TESTFLAGS -c
-	)
-	[ $? -ne 0 ] && return 1
-	mkdir -p "$(dirname "$out_file")"
-	mv "$dir/$(basename "$dir").test" "$out_file"
-	echo "Precompiled: ${DOCKER_PKG}${dir#.}"
-}
-
 # This helper function walks the current directory looking for directories
 # This helper function walks the current directory looking for directories
 # holding certain files ($1 parameter), and prints their paths on standard
 # holding certain files ($1 parameter), and prints their paths on standard
 # output, one per line.
 # output, one per line.

+ 26 - 0
hack/make/.go-compile-test-dir

@@ -0,0 +1,26 @@
+#!/bin/bash
+set -e
+
+# Compile phase run by parallel in test-unit. No support for coverpkg
+
+dir=$1
+out_file="$DEST/precompiled/$dir.test"
+testcover=()
+if [ "$HAVE_GO_TEST_COVER" ]; then
+	# if our current go install has -cover, we want to use it :)
+	mkdir -p "$DEST/coverprofiles"
+	coverprofile="docker${dir#.}"
+	coverprofile="$DEST/coverprofiles/${coverprofile//\//-}"
+	testcover=( -cover -coverprofile "$coverprofile" ) # missing $coverpkg
+fi
+if [ "$BUILDFLAGS_FILE" ]; then
+	readarray -t BUILDFLAGS < "$BUILDFLAGS_FILE"
+fi
+(
+	cd "$dir"
+	go test "${testcover[@]}" -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $TESTFLAGS -c
+)
+[ $? -ne 0 ] && return 1
+mkdir -p "$(dirname "$out_file")"
+mv "$dir/$(basename "$dir").test" "$out_file"
+echo "Precompiled: ${DOCKER_PKG}${dir#.}"

+ 2 - 3
hack/make/test-unit

@@ -29,7 +29,6 @@ bundle_test_unit() {
 			export HOME="$(mktemp -d)"
 			export HOME="$(mktemp -d)"
 			mkdir -p "$HOME/.parallel"
 			mkdir -p "$HOME/.parallel"
 			touch "$HOME/.parallel/ignored_vars"
 			touch "$HOME/.parallel/ignored_vars"
-			export -f go_compile_test_dir
 			export LDFLAGS="$LDFLAGS $LDFLAGS_STATIC_DOCKER"
 			export LDFLAGS="$LDFLAGS $LDFLAGS_STATIC_DOCKER"
 			export TESTFLAGS
 			export TESTFLAGS
 			export HAVE_GO_TEST_COVER
 			export HAVE_GO_TEST_COVER
@@ -38,12 +37,12 @@ bundle_test_unit() {
 			export BUILDFLAGS_FILE="$HOME/buildflags_file"
 			export BUILDFLAGS_FILE="$HOME/buildflags_file"
 			( IFS=$'\n'; echo "${BUILDFLAGS[*]}" ) > "$BUILDFLAGS_FILE"
 			( IFS=$'\n'; echo "${BUILDFLAGS[*]}" ) > "$BUILDFLAGS_FILE"
 
 
-			echo "$TESTDIRS" | parallel --jobs "$PARALLEL_JOBS" --halt 2 --env _ go_compile_test_dir
+			echo "$TESTDIRS" | parallel --jobs "$PARALLEL_JOBS" --halt 2 --env _ "$(dirname "$BASH_SOURCE")/.go-compile-test-dir"
 			rm -rf "$HOME"
 			rm -rf "$HOME"
 		) else
 		) else
 			# aww, no "parallel" available - fall back to boring
 			# aww, no "parallel" available - fall back to boring
 			for test_dir in $TESTDIRS; do
 			for test_dir in $TESTDIRS; do
-				go_compile_test_dir "$test_dir"
+				"$(dirname "$BASH_SOURCE")/.go-compile-test-dir" "$test_dir"
 			done
 			done
 		fi
 		fi
 		echo "$TESTDIRS" | go_run_test_dir
 		echo "$TESTDIRS" | go_run_test_dir