summary refs log tree commit diff
path: root/pkgs/development/go-modules
diff options
context:
space:
mode:
authorManuel Mendez <mmendez534@gmail.com>2022-02-25 17:06:28 -0500
committerzowoq <59103226+zowoq@users.noreply.github.com>2022-03-04 13:32:44 +1000
commit8b5a7940b0cd1f6f232933099f12f383c3b3c32a (patch)
treeba9fc5fa7f76bc3b01387740b53e5b8b3fa8c9fd /pkgs/development/go-modules
parent7bd35b61fe880ae282b7a332431b740f20406c3c (diff)
downloadnixpkgs-8b5a7940b0cd1f6f232933099f12f383c3b3c32a.tar
nixpkgs-8b5a7940b0cd1f6f232933099f12f383c3b3c32a.tar.gz
nixpkgs-8b5a7940b0cd1f6f232933099f12f383c3b3c32a.tar.bz2
nixpkgs-8b5a7940b0cd1f6f232933099f12f383c3b3c32a.tar.lz
nixpkgs-8b5a7940b0cd1f6f232933099f12f383c3b3c32a.tar.xz
nixpkgs-8b5a7940b0cd1f6f232933099f12f383c3b3c32a.tar.zst
nixpkgs-8b5a7940b0cd1f6f232933099f12f383c3b3c32a.zip
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.

Make go-packages look a little bit more like go-modules, by adding testdata to
the default list of excluded packages.

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.
Diffstat (limited to 'pkgs/development/go-modules')
-rw-r--r--pkgs/development/go-modules/generic/default.nix12
1 files changed, 10 insertions, 2 deletions
diff --git a/pkgs/development/go-modules/generic/default.nix b/pkgs/development/go-modules/generic/default.nix
index 76d0dc961c5..ace8b820ee2 100644
--- a/pkgs/development/go-modules/generic/default.nix
+++ b/pkgs/development/go-modules/generic/default.nix
@@ -171,13 +171,20 @@ let
     buildPhase = args.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 '(no( buildable| non-test)?|build constraints exclude all) Go (source )?files'; then
@@ -214,6 +221,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