builder: Reformat with nixpkgs-fmt

After porting builder changes from nixpkgs the structure has changed somewhat.
This commit is contained in:
adisbladis 2022-06-14 19:13:11 +08:00
parent 2028c2f3ff
commit 5a8afd711e

View file

@ -182,7 +182,7 @@ let
, passthru ? { } , passthru ? { }
, tags ? [ ] , tags ? [ ]
# needed for buildFlags{,Array} warning # needed for buildFlags{,Array} warning
, buildFlags ? "" , buildFlags ? ""
, buildFlagsArray ? "" , buildFlagsArray ? ""
@ -224,148 +224,149 @@ let
package = package =
lib.warnIf (buildFlags != "" || buildFlagsArray != "") lib.warnIf (buildFlags != "" || buildFlagsArray != "")
"Use the `ldflags` and/or `tags` attributes instead of `buildFlags`/`buildFlagsArray`" "Use the `ldflags` and/or `tags` attributes instead of `buildFlags`/`buildFlagsArray`"
stdenv.mkDerivation (lib.optionalAttrs (defaultPackage != "") stdenv.mkDerivation
{ (lib.optionalAttrs (defaultPackage != "")
pname = attrs.pname or baseNameOf defaultPackage; {
version = stripVersion (modulesStruct.mod.${defaultPackage}).version; pname = attrs.pname or baseNameOf defaultPackage;
src = vendorEnv.passthru.sources.${defaultPackage}; version = stripVersion (modulesStruct.mod.${defaultPackage}).version;
} // lib.optionalAttrs (lib.hasAttr "subPackages" modulesStruct) { src = vendorEnv.passthru.sources.${defaultPackage};
subPackages = modulesStruct.subPackages; } // lib.optionalAttrs (lib.hasAttr "subPackages" modulesStruct) {
} // attrs // { subPackages = modulesStruct.subPackages;
nativeBuildInputs = [ removeReferencesTo go ] ++ nativeBuildInputs; } // attrs // {
nativeBuildInputs = [ removeReferencesTo go ] ++ nativeBuildInputs;
inherit (go) GOOS GOARCH; inherit (go) GOOS GOARCH;
GO_NO_VENDOR_CHECKS = "1"; GO_NO_VENDOR_CHECKS = "1";
GO111MODULE = "on"; GO111MODULE = "on";
GOFLAGS = "-mod=vendor"; GOFLAGS = "-mod=vendor";
configurePhase = attrs.configurePhase or '' configurePhase = attrs.configurePhase or ''
runHook preConfigure runHook preConfigure
export GOCACHE=$TMPDIR/go-cache export GOCACHE=$TMPDIR/go-cache
export GOPATH="$TMPDIR/go" export GOPATH="$TMPDIR/go"
export GOSUMDB=off export GOSUMDB=off
export GOPROXY=off export GOPROXY=off
cd "$modRoot" cd "$modRoot"
if [ -n "${vendorEnv}" ]; then if [ -n "${vendorEnv}" ]; then
rm -rf vendor rm -rf vendor
ln -s ${vendorEnv} vendor ln -s ${vendorEnv} vendor
fi
runHook postConfigure
'';
buildPhase = attrs.buildPhase or ''
runHook preBuild
exclude='\(/_\|examples\|Godeps\|testdata'
if [[ -n "$excludedPackages" ]]; then
IFS=' ' read -r -a excludedArr <<<$excludedPackages
printf -v excludedAlternates '%s\\|' "''${excludedArr[@]}"
excludedAlternates=''${excludedAlternates%\\|} # drop final \| added by printf
exclude+='\|'"$excludedAlternates"
fi
exclude+='\)'
buildGoDir() {
local d; local cmd;
cmd="$1"
d="$2"
. $TMPDIR/buildFlagsArray
local OUT
if ! OUT="$(go $cmd $buildFlags "''${buildFlagsArray[@]}" ''${tags:+-tags=${lib.concatStringsSep "," tags}} ''${ldflags:+-ldflags="$ldflags"} -v -p $NIX_BUILD_CORES $d 2>&1)"; then
if echo "$OUT" | grep -qE 'imports .*?: no Go files in'; then
echo "$OUT" >&2
return 1
fi fi
if ! echo "$OUT" | grep -qE '(no( buildable| non-test)?|build constraints exclude all) Go (source )?files'; then
echo "$OUT" >&2 runHook postConfigure
return 1 '';
buildPhase = attrs.buildPhase or ''
runHook preBuild
exclude='\(/_\|examples\|Godeps\|testdata'
if [[ -n "$excludedPackages" ]]; then
IFS=' ' read -r -a excludedArr <<<$excludedPackages
printf -v excludedAlternates '%s\\|' "''${excludedArr[@]}"
excludedAlternates=''${excludedAlternates%\\|} # drop final \| added by printf
exclude+='\|'"$excludedAlternates"
fi fi
fi exclude+='\)'
if [ -n "$OUT" ]; then
echo "$OUT" >&2
fi
return 0
}
getGoDirs() { buildGoDir() {
local type; local d; local cmd;
type="$1" cmd="$1"
if [ -n "$subPackages" ]; then d="$2"
echo "$subPackages" | sed "s,\(^\| \),\1./,g" . $TMPDIR/buildFlagsArray
else local OUT
find . -type f -name \*$type.go -exec dirname {} \; | grep -v "/vendor/" | sort --unique | grep -v "$exclude" if ! OUT="$(go $cmd $buildFlags "''${buildFlagsArray[@]}" ''${tags:+-tags=${lib.concatStringsSep "," tags}} ''${ldflags:+-ldflags="$ldflags"} -v -p $NIX_BUILD_CORES $d 2>&1)"; then
fi if echo "$OUT" | grep -qE 'imports .*?: no Go files in'; then
} echo "$OUT" >&2
return 1
fi
if ! echo "$OUT" | grep -qE '(no( buildable| non-test)?|build constraints exclude all) Go (source )?files'; then
echo "$OUT" >&2
return 1
fi
fi
if [ -n "$OUT" ]; then
echo "$OUT" >&2
fi
return 0
}
if (( "''${NIX_DEBUG:-0}" >= 1 )); then getGoDirs() {
buildFlagsArray+=(-x) local type;
fi type="$1"
if [ -n "$subPackages" ]; then
echo "$subPackages" | sed "s,\(^\| \),\1./,g"
else
find . -type f -name \*$type.go -exec dirname {} \; | grep -v "/vendor/" | sort --unique | grep -v "$exclude"
fi
}
if [ ''${#buildFlagsArray[@]} -ne 0 ]; then if (( "''${NIX_DEBUG:-0}" >= 1 )); then
declare -p buildFlagsArray > $TMPDIR/buildFlagsArray buildFlagsArray+=(-x)
else fi
touch $TMPDIR/buildFlagsArray
fi
if [ -z "$enableParallelBuilding" ]; then
export NIX_BUILD_CORES=1
fi
for pkg in $(getGoDirs ""); do
echo "Building subPackage $pkg"
buildGoDir install "$pkg"
done
'' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
# normalize cross-compiled builds w.r.t. native builds
(
dir=$GOPATH/bin/${go.GOOS}_${go.GOARCH}
if [[ -n "$(shopt -s nullglob; echo $dir/*)" ]]; then
mv $dir/* $dir/..
fi
if [[ -d $dir ]]; then
rmdir $dir
fi
)
'' + ''
runHook postBuild
'';
doCheck = attrs.doCheck or true; if [ ''${#buildFlagsArray[@]} -ne 0 ]; then
checkPhase = attrs.checkPhase or '' declare -p buildFlagsArray > $TMPDIR/buildFlagsArray
runHook preCheck else
touch $TMPDIR/buildFlagsArray
fi
if [ -z "$enableParallelBuilding" ]; then
export NIX_BUILD_CORES=1
fi
for pkg in $(getGoDirs ""); do
echo "Building subPackage $pkg"
buildGoDir install "$pkg"
done
'' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
# normalize cross-compiled builds w.r.t. native builds
(
dir=$GOPATH/bin/${go.GOOS}_${go.GOARCH}
if [[ -n "$(shopt -s nullglob; echo $dir/*)" ]]; then
mv $dir/* $dir/..
fi
if [[ -d $dir ]]; then
rmdir $dir
fi
)
'' + ''
runHook postBuild
'';
for pkg in $(getGoDirs test); do doCheck = attrs.doCheck or true;
buildGoDir test $checkFlags "$pkg" checkPhase = attrs.checkPhase or ''
done runHook preCheck
runHook postCheck for pkg in $(getGoDirs test); do
''; buildGoDir test $checkFlags "$pkg"
done
installPhase = attrs.installPhase or '' runHook postCheck
runHook preInstall '';
mkdir -p $out installPhase = attrs.installPhase or ''
dir="$GOPATH/bin" runHook preInstall
[ -e "$dir" ] && cp -r $dir $out
runHook postInstall mkdir -p $out
''; dir="$GOPATH/bin"
[ -e "$dir" ] && cp -r $dir $out
preFixup = (attrs.preFixup or "") + '' runHook postInstall
find $out/{bin,libexec,lib} -type f 2>/dev/null | xargs -r ${removeExpr removeReferences} || true '';
'';
strictDeps = true; preFixup = (attrs.preFixup or "") + ''
find $out/{bin,libexec,lib} -type f 2>/dev/null | xargs -r ${removeExpr removeReferences} || true
'';
disallowedReferences = lib.optional (!allowGoReference) go; strictDeps = true;
passthru = { inherit go vendorEnv; } // passthru; disallowedReferences = lib.optional (!allowGoReference) go;
meta = { platforms = go.meta.platforms or lib.platforms.all; } // meta; passthru = { inherit go vendorEnv; } // passthru;
});
meta = { platforms = go.meta.platforms or lib.platforms.all; } // meta;
});
in in
package; package;