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>
This commit is contained in:
Tianon Gravi 2014-09-28 21:48:57 -06:00
Родитель d142b18aab
Коммит 8ffdf6022e
3 изменённых файлов: 28 добавлений и 28 удалений

Просмотреть файл

@ -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
# holding certain files ($1 parameter), and prints their paths on standard
# output, one per line.

26
hack/make/.go-compile-test-dir Executable file
Просмотреть файл

@ -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#.}"

Просмотреть файл

@ -29,7 +29,6 @@ bundle_test_unit() {
export HOME="$(mktemp -d)"
mkdir -p "$HOME/.parallel"
touch "$HOME/.parallel/ignored_vars"
export -f go_compile_test_dir
export LDFLAGS="$LDFLAGS $LDFLAGS_STATIC_DOCKER"
export TESTFLAGS
export HAVE_GO_TEST_COVER
@ -38,12 +37,12 @@ bundle_test_unit() {
export BUILDFLAGS_FILE="$HOME/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"
) else
# aww, no "parallel" available - fall back to boring
for test_dir in $TESTDIRS; do
go_compile_test_dir "$test_dir"
"$(dirname "$BASH_SOURCE")/.go-compile-test-dir" "$test_dir"
done
fi
echo "$TESTDIRS" | go_run_test_dir