From 31102e07534a7fa1fb93e4211e45ff88384d3200 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Tue, 14 Jun 2022 19:08:28 +0800 Subject: [PATCH] go: Bunch of fixes when using excludedPackages and other bits Few things going on in this commit: Do not print "Building subPakage $pkg" message if actually going to skip the package. This was confusing to me when I was trying to figure out how to set excludedPackages and seeing the "Building subpackage $pkg" messages for packages I wanted to skip. Turns out this messages was being printed before checking if we actually wanted to build the package and not necessarily that my excludedPackages was wrong. This commit also does some setup outside the buildGoDir function so that we avoid checking `excludedPackages` for every package and cut down the number of grep calls by half since we always want at least one grep for the default excludedPackages, might as well just add to the patterns being checked. Finally, adds documentation for usage of excludedPackages and subPackages. I had to read the implementation to figure out how to correctly use these function arguments since there was no documentation and different uses in the code base. So this commit documents usage of the arguments. This is a port of https://github.com/NixOS/nixpkgs/commit/8b5a7940b0cd1f6f232933099f12f383c3b3c32a --- builder/default.nix | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/builder/default.nix b/builder/default.nix index 731b415..ac06757 100644 --- a/builder/default.nix +++ b/builder/default.nix @@ -261,13 +261,20 @@ let 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 - echo "$d" | grep -q "\(/_\|examples\|Godeps\|testdata\)" && return 0 - [ -n "$excludedPackages" ] && echo "$d" | grep -q "$excludedPackages" && return 0 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 @@ -308,6 +315,7 @@ let export NIX_BUILD_CORES=1 fi for pkg in $(getGoDirs ""); do + grep -q "$exclude" <<<$pkg && continue echo "Building subPackage $pkg" buildGoDir install "$pkg" done