goPackages: Use parallel instead of forking in bash

This commit is contained in:
William A. Kennington III 2015-08-29 11:51:15 -07:00
parent b9e999a595
commit 3afc3494bb
2 changed files with 38 additions and 55 deletions

View File

@ -1,4 +1,4 @@
{ go, govers, lib }: { go, govers, parallel, lib }:
{ name, buildInputs ? [], nativeBuildInputs ? [], passthru ? {}, preFixup ? "" { name, buildInputs ? [], nativeBuildInputs ? [], passthru ? {}, preFixup ? ""
@ -41,7 +41,7 @@ go.stdenv.mkDerivation (
(builtins.removeAttrs args [ "goPackageAliases" "disabled" ]) // { (builtins.removeAttrs args [ "goPackageAliases" "disabled" ]) // {
name = "go${go.meta.branch}-${name}"; name = "go${go.meta.branch}-${name}";
nativeBuildInputs = [ go ] nativeBuildInputs = [ go parallel ]
++ (lib.optional (!dontRenameImports) govers) ++ nativeBuildInputs; ++ (lib.optional (!dontRenameImports) govers) ++ nativeBuildInputs;
buildInputs = [ go ] ++ buildInputs; buildInputs = [ go ] ++ buildInputs;
@ -62,7 +62,7 @@ go.stdenv.mkDerivation (
rmdir extraSrc rmdir extraSrc
'') + '' '') + ''
GOPATH=$NIX_BUILD_TOP/go:$GOPATH export GOPATH=$NIX_BUILD_TOP/go:$GOPATH
runHook postConfigure runHook postConfigure
''; '';
@ -80,38 +80,39 @@ go.stdenv.mkDerivation (
runHook renameImports runHook renameImports
PIDS=() buildGoDir() {
if [ -n "$subPackages" ] ; then local d; local cmd;
for p in $subPackages ; do cmd="$1"
go install $buildFlags "''${buildFlagsArray[@]}" -p $NIX_BUILD_CORES -v $goPackagePath/$p & d="$2"
PIDS+=("$!") echo "$d" | grep -q "/_" && return 0
done [ -n "$excludedPackages" ] && echo "$d" | grep -q "$excludedPackages" && return 0
else local OUT
pushd go/src if ! OUT="$(go $cmd $buildFlags "''${buildFlagsArray[@]}" -v $d 2>&1)"; then
while read d; do if ! echo "$OUT" | grep -q 'no buildable Go source files'; then
{ echo "$OUT" >&2
echo "$d" | grep -q "/_" && continue return 1
[ -n "$excludedPackages" ] && echo "$d" | grep -q "$excludedPackages" && continue fi
local OUT fi
if ! OUT="$(go install $buildFlags "''${buildFlagsArray[@]}" -p $NIX_BUILD_CORES -v $d 2>&1)"; then if [ -n "$OUT" ]; then
if ! echo "$OUT" | grep -q 'no buildable Go source files'; then echo "$OUT" >&2
echo "$OUT" >&2 fi
exit 1 return 0
fi }
fi
if [ -n "$OUT" ]; then
echo "$OUT" >&2
fi
} &
PIDS+=("$!")
done < <(find $goPackagePath -type f -name \*.go -exec dirname {} \; | sort | uniq)
popd
fi
# Exit on error from the parallel process getGoDirs() {
for PID in "''${PIDS[@]}"; do local type;
wait $PID || exit 1 type="$1"
done if [ -n "$subPackages" ]; then
echo "$subPackages" | sed "s,\(^\| \),\1$goPackagePath/,g"
else
pushd go/src >/dev/null
find "$goPackagePath" -type f -name \*$type.go -exec dirname {} \; | sort | uniq
popd >/dev/null
fi
}
export -f buildGoDir # parallel needs to see the function
getGoDirs "" | parallel -j $NIX_BUILD_CORES buildGoDir install
runHook postBuild runHook postBuild
''; '';
@ -119,25 +120,7 @@ go.stdenv.mkDerivation (
checkPhase = args.checkPhase or '' checkPhase = args.checkPhase or ''
runHook preCheck runHook preCheck
PIDS=() getGoDirs test | parallel -j $NIX_BUILD_CORES buildGoDir test
if [ -n "$subPackages" ] ; then
for p in $subPackages ; do
go test -p $NIX_BUILD_CORES -v $goPackagePath/$p &
PIDS+=("$!")
done
else
pushd go/src
while read d; do
go test -p $NIX_BUILD_CORES -v $d &
PIDS+=("$!")
done < <(find $goPackagePath -type f -name \*_test.go -exec dirname {} \; | sort | uniq)
popd
fi
# Exit on error from the parallel process
for PID in "''${PIDS[@]}"; do
wait $PID || exit 1
done
runHook postCheck runHook postCheck
''; '';

View File

@ -8665,7 +8665,7 @@ let
buildGoPackage = import ../development/go-modules/generic { buildGoPackage = import ../development/go-modules/generic {
go = go_1_4; go = go_1_4;
govers = go14Packages.govers; govers = go14Packages.govers;
inherit lib; inherit parallel lib;
}; };
overrides = (config.goPackageOverrides or (p: {})) pkgs; overrides = (config.goPackageOverrides or (p: {})) pkgs;
}); });
@ -8675,7 +8675,7 @@ let
buildGoPackage = import ../development/go-modules/generic { buildGoPackage = import ../development/go-modules/generic {
go = go_1_5; go = go_1_5;
govers = go15Packages.govers; govers = go15Packages.govers;
inherit lib; inherit parallel lib;
}; };
overrides = (config.goPackageOverrides or (p: {})) pkgs; overrides = (config.goPackageOverrides or (p: {})) pkgs;
}); });