go: Run builds in parallel

This commit is contained in:
William A. Kennington III 2015-07-29 18:16:56 -07:00
parent c6bb486641
commit a4707aed55

View File

@ -66,13 +66,16 @@ go.stdenv.mkDerivation (
runHook renameImports runHook renameImports
PIDS=()
if [ -n "$subPackages" ] ; then if [ -n "$subPackages" ] ; then
for p in $subPackages ; do for p in $subPackages ; do
go install $buildFlags "''${buildFlagsArray[@]}" -p $NIX_BUILD_CORES -v $goPackagePath/$p go install $buildFlags "''${buildFlagsArray[@]}" -p $NIX_BUILD_CORES -v $goPackagePath/$p &
PIDS+=("$!")
done done
else else
(cd go/src pushd go/src
find $goPackagePath -type f -name \*.go -exec dirname {} \; | sort | uniq | while read d; do while read d; do
{
echo "$d" | grep -q "/_" && continue echo "$d" | grep -q "/_" && continue
[ -n "$excludedPackages" ] && echo "$d" | grep -q "$excludedPackages" && continue [ -n "$excludedPackages" ] && echo "$d" | grep -q "$excludedPackages" && continue
local OUT local OUT
@ -85,26 +88,43 @@ go.stdenv.mkDerivation (
if [ -n "$OUT" ]; then if [ -n "$OUT" ]; then
echo "$OUT" >&2 echo "$OUT" >&2
fi fi
done) } &
PIDS+=("$!")
done < <(find $goPackagePath -type f -name \*.go -exec dirname {} \; | sort | uniq)
popd
fi fi
# Exit on error from the parallel process
for PID in "''${PIDS[@]}"; do
wait $PID || exit 1
done
runHook postBuild runHook postBuild
''; '';
checkPhase = args.checkPhase or '' checkPhase = args.checkPhase or ''
runHook preCheck runHook preCheck
PIDS=()
if [ -n "$subPackages" ] ; then if [ -n "$subPackages" ] ; then
for p in $subPackages ; do for p in $subPackages ; do
go test -p $NIX_BUILD_CORES -v $goPackagePath/$p go test -p $NIX_BUILD_CORES -v $goPackagePath/$p &
done done
PIDS+=("$!")
else else
(cd go/src pushd go/src
find $goPackagePath -type f -name \*_test.go -exec dirname {} \; | sort | uniq | while read d; do while read d; do
go test -p $NIX_BUILD_CORES -v $d go test -p $NIX_BUILD_CORES -v $d
done) done < <(find $goPackagePath -type f -name \*_test.go -exec dirname {} \; | sort | uniq)
popd
PIDS+=("$!")
fi fi
# Exit on error from the parallel process
for PID in "''${PIDS[@]}"; do
wait $PID || exit 1
done
runHook postCheck runHook postCheck
''; '';
@ -114,12 +134,13 @@ go.stdenv.mkDerivation (
mkdir -p $out mkdir -p $out
if [ -z "$dontInstallSrc" ]; then if [ -z "$dontInstallSrc" ]; then
(cd "$NIX_BUILD_TOP/go" pushd "$NIX_BUILD_TOP/go"
find . -type f | while read f; do while read f; do
echo "$f" | grep -q '^./\(src\|pkg/[^/]*\)/${goPackagePath}' || continue echo "$f" | grep -q '^./\(src\|pkg/[^/]*\)/${goPackagePath}' || continue
mkdir -p "$(dirname "$out/share/go/$f")" mkdir -p "$(dirname "$out/share/go/$f")"
cp $NIX_BUILD_TOP/go/$f $out/share/go/$f cp $NIX_BUILD_TOP/go/$f $out/share/go/$f
done) done < <(find . -type f)
popd
fi fi
dir="$NIX_BUILD_TOP/go/bin" dir="$NIX_BUILD_TOP/go/bin"