lol

Test __structuredAttrs support in autoPatchelf

This commit adds a test for the newly added support for
__structuredAttrs in autoPatchelf(hook). It copied a reasonably
small-closure binary derivation that makes use of autoPatchelf, stripped
it down for the purpose of the test, and check that autoPatchelf
correctly set the interpreter and runpath whether __structuredAttrs is
set to true or not.

+104
+6
pkgs/test/auto-patchelf-hook/default.nix
··· 1 + { lib, callPackage }: 2 + 3 + lib.recurseIntoAttrs { 4 + withStructuredAttrs = callPackage ./package.nix { __structuredAttrs = true; }; 5 + withoutStructuredAttrs = callPackage ./package.nix { __structuredAttrs = false; }; 6 + }
+96
pkgs/test/auto-patchelf-hook/package.nix
··· 1 + # This is a test for autoPatchelfHook. To test it, we just need a simple binary 2 + # which uses the hook. We took the derivation from tonelib-jam, which sounds 3 + # like a good candidate with a small closure, and trimmed it down. 4 + 5 + { stdenv 6 + , lib 7 + , fetchurl 8 + , autoPatchelfHook 9 + , dpkg 10 + , freetype 11 + , curl 12 + # This test checks that the behavior of autoPatchelfHook is correct whether 13 + # __structuredAttrs 14 + # (https://nixos.org/manual/nix/stable/language/advanced-attributes#adv-attr-structuredAttrs) 15 + # is set or not. Hence __structuredAttrs is provided as a parameter. 16 + , __structuredAttrs 17 + }: 18 + 19 + let runtimeDependencies = [ 20 + (lib.getLib curl) 21 + "/some/dep" 22 + "/some/other/dep" 23 + ] 24 + # A dependency with space only works with __structuredAttrs set to true. 25 + ++ lib.lists.optional __structuredAttrs "/some/dep with space"; 26 + in 27 + 28 + stdenv.mkDerivation { 29 + name = "auto-patchelf-test"; 30 + 31 + src = fetchurl { 32 + url = "https://tonelib.net/download/221222/ToneLib-Jam-amd64.deb"; 33 + sha256 = "sha256-c6At2lRPngQPpE7O+VY/Hsfw+QfIb3COIuHfbqqIEuM="; 34 + }; 35 + 36 + unpackCmd = '' 37 + dpkg -x $curSrc source 38 + ''; 39 + 40 + nativeBuildInputs = [ 41 + dpkg 42 + autoPatchelfHook 43 + ]; 44 + 45 + installPhase = '' 46 + mv usr $out 47 + ''; 48 + 49 + buildInputs = [ 50 + freetype 51 + ]; 52 + 53 + autoPatchelfIgnoreMissingDeps = [ 54 + "libGL.so.1" 55 + "libasound.so.2" 56 + ]; 57 + 58 + inherit runtimeDependencies; 59 + 60 + # Additional phase performing the actual test. 61 + installCheckPhase = 62 + let allDeps = runtimeDependencies ++ [ (lib.getLib freetype) ]; 63 + in 64 + '' 65 + local binary="$out/bin/ToneLib-Jam" 66 + local interpreter=$(patchelf --print-interpreter $binary) 67 + local runpath=$(patchelf --print-rpath $binary) 68 + local glibcStorePath="${stdenv.cc.libc}" 69 + 70 + # Check that the glibc path is a prefix of the interpreter. If 71 + # autoPatchelfHook ran correctly, the binary should have set the interpreter 72 + # to point to the store. 73 + echo "[auto-patchelf-hook-test]: Check that the interpreter is in the store" 74 + test "''${interpreter#$glibcStorePath}" != "$interpreter" 75 + 76 + readarray -td':' runpathArray < <(echo -n "$runpath") 77 + 78 + echo "[auto-patchelf-hook-test]: Check that the runpath has the right number of entries" 79 + test "''${#runpathArray[@]}" -eq ${builtins.toString (builtins.length allDeps)} 80 + 81 + echo "[auto-patchelf-hook-test]: Check that the runpath contains the expected runtime deps" 82 + '' 83 + + lib.strings.concatStringsSep "\n" 84 + (lib.lists.imap0 85 + (i: path: 86 + let iAsStr = builtins.toString i; in 87 + '' 88 + echo "[auto-patchelf-hook-test]: Check that entry ${iAsStr} is ${path}" 89 + test "''${paths[${iAsStr}]}" = "$path" 90 + '') 91 + allDeps 92 + ); 93 + 94 + doInstallCheck = true; 95 + inherit __structuredAttrs; 96 + }
+2
pkgs/test/default.nix
··· 167 167 pkgs-lib = recurseIntoAttrs (import ../pkgs-lib/tests { inherit pkgs; }); 168 168 169 169 nixpkgs-check-by-name = callPackage ./nixpkgs-check-by-name { }; 170 + 171 + auto-patchelf-hook = callPackage ./auto-patchelf-hook { }; 170 172 }