Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

Merge pull request #85976 from jtojnar/wrap-gapps-hook-tests

authored by

Jan Tojnar and committed by
GitHub
d489409a 5bd8316b

+236 -3
pkgs/build-support/setup-hooks/wrap-gapps-hook.sh pkgs/build-support/setup-hooks/wrap-gapps-hook/wrap-gapps-hook.sh
+175
pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix
··· 1 + { stdenv 2 + , lib 3 + , makeSetupHook 4 + , makeWrapper 5 + , gobject-introspection 6 + , gtk3 7 + , librsvg 8 + , dconf 9 + , callPackage 10 + , wrapGAppsHook 11 + , writeTextFile 12 + }: 13 + 14 + makeSetupHook { 15 + deps = lib.optionals (!stdenv.isDarwin) [ 16 + # It is highly probable that a program will use GSettings, 17 + # at minimum through GTK file chooser dialogue. 18 + # Let’s add a GIO module for “dconf” GSettings backend 19 + # to avoid falling back to “memory” backend. This is 20 + # required for GSettings-based settings to be persisted. 21 + # Unfortunately, it also requires the user to have dconf 22 + # D-Bus service enabled globally (e.g. through a NixOS module). 23 + dconf.lib 24 + ] ++ [ 25 + # TODO: remove this, packages should depend on GTK explicitly. 26 + gtk3 27 + 28 + # librsvg provides a module for gdk-pixbuf to allow rendering 29 + # SVG icons. Most icon themes are SVG-based and so are some 30 + # graphics in GTK (e.g. cross for closing window in window title bar) 31 + # so it is pretty much required for applications using GTK. 32 + librsvg 33 + 34 + # We use the wrapProgram function. 35 + makeWrapper 36 + ]; 37 + substitutions = { 38 + passthru.tests = let 39 + sample-project = ./tests/sample-project; 40 + 41 + testLib = callPackage ./tests/lib.nix { }; 42 + inherit (testLib) expectSomeLineContainingYInFileXToMentionZ; 43 + in rec { 44 + # Simple derivation containing a program and a daemon. 45 + basic = stdenv.mkDerivation { 46 + name = "basic"; 47 + 48 + src = sample-project; 49 + 50 + nativeBuildInputs = [ wrapGAppsHook ]; 51 + 52 + installFlags = [ "bin-foo" "libexec-bar" ]; 53 + }; 54 + 55 + # The wrapper for executable files should add path to dconf GIO module. 56 + basic-contains-dconf = let 57 + tested = basic; 58 + in testLib.runTest "basic-contains-dconf" ( 59 + testLib.skip stdenv.isDarwin '' 60 + ${expectSomeLineContainingYInFileXToMentionZ "${tested}/bin/foo" "GIO_EXTRA_MODULES=" "${dconf.lib}/lib/gio/modules"} 61 + ${expectSomeLineContainingYInFileXToMentionZ "${tested}/libexec/bar" "GIO_EXTRA_MODULES=" "${dconf.lib}/lib/gio/modules"} 62 + '' 63 + ); 64 + 65 + # Simple derivation containing a gobject-introspection typelib. 66 + typelib-Mahjong = stdenv.mkDerivation { 67 + name = "typelib-Mahjong"; 68 + 69 + src = sample-project; 70 + 71 + installFlags = [ "typelib-Mahjong" ]; 72 + }; 73 + 74 + # Simple derivation using a typelib. 75 + typelib-user = stdenv.mkDerivation { 76 + name = "typelib-user"; 77 + 78 + src = sample-project; 79 + 80 + nativeBuildInputs = [ 81 + gobject-introspection 82 + wrapGAppsHook 83 + ]; 84 + 85 + buildInputs = [ 86 + typelib-Mahjong 87 + ]; 88 + 89 + installFlags = [ "bin-foo" "libexec-bar" ]; 90 + }; 91 + 92 + # Testing cooperation with gobject-introspection setup hook, 93 + # which should populate GI_TYPELIB_PATH variable with paths 94 + # to typelibs among the derivation’s dependencies. 95 + # The resulting GI_TYPELIB_PATH should be picked up by the wrapper. 96 + typelib-user-has-gi-typelib-path = let 97 + tested = typelib-user; 98 + in testLib.runTest "typelib-user-has-gi-typelib-path" '' 99 + ${expectSomeLineContainingYInFileXToMentionZ "${tested}/bin/foo" "GI_TYPELIB_PATH=" "${typelib-Mahjong}/lib/girepository-1.0"} 100 + ${expectSomeLineContainingYInFileXToMentionZ "${tested}/libexec/bar" "GI_TYPELIB_PATH=" "${typelib-Mahjong}/lib/girepository-1.0"} 101 + ''; 102 + 103 + # Simple derivation containing a gobject-introspection typelib in lib output. 104 + typelib-Bechamel = stdenv.mkDerivation { 105 + name = "typelib-Bechamel"; 106 + 107 + outputs = [ "out" "lib" ]; 108 + 109 + src = sample-project; 110 + 111 + makeFlags = [ 112 + "LIBDIR=${placeholder "lib"}/lib" 113 + ]; 114 + 115 + installFlags = [ "typelib-Bechamel" ]; 116 + }; 117 + 118 + # Simple derivation using a typelib from non-default output. 119 + typelib-multiout-user = stdenv.mkDerivation { 120 + name = "typelib-multiout-user"; 121 + 122 + src = sample-project; 123 + 124 + nativeBuildInputs = [ 125 + gobject-introspection 126 + wrapGAppsHook 127 + ]; 128 + 129 + buildInputs = [ 130 + typelib-Bechamel 131 + ]; 132 + 133 + installFlags = [ "bin-foo" "libexec-bar" ]; 134 + }; 135 + 136 + # Testing cooperation with gobject-introspection setup hook, 137 + # which should populate GI_TYPELIB_PATH variable with paths 138 + # to typelibs among the derivation’s dependencies, 139 + # even when they are not in default output. 140 + # The resulting GI_TYPELIB_PATH should be picked up by the wrapper. 141 + typelib-multiout-user-has-gi-typelib-path = let 142 + tested = typelib-multiout-user; 143 + in testLib.runTest "typelib-multiout-user-has-gi-typelib-path" '' 144 + ${expectSomeLineContainingYInFileXToMentionZ "${tested}/bin/foo" "GI_TYPELIB_PATH=" "${typelib-Bechamel.lib}/lib/girepository-1.0"} 145 + ${expectSomeLineContainingYInFileXToMentionZ "${tested}/libexec/bar" "GI_TYPELIB_PATH=" "${typelib-Bechamel.lib}/lib/girepository-1.0"} 146 + ''; 147 + 148 + # Simple derivation that contains a typelib as well as a program using it. 149 + typelib-self-user = stdenv.mkDerivation { 150 + name = "typelib-self-user"; 151 + 152 + src = sample-project; 153 + 154 + nativeBuildInputs = [ 155 + gobject-introspection 156 + wrapGAppsHook 157 + ]; 158 + 159 + installFlags = [ "typelib-Cow" "bin-foo" "libexec-bar" ]; 160 + }; 161 + 162 + # Testing cooperation with gobject-introspection setup hook, 163 + # which should add the path to derivation’s own typelibs 164 + # to GI_TYPELIB_PATH variable. 165 + # The resulting GI_TYPELIB_PATH should be picked up by the wrapper. 166 + # https://github.com/NixOS/nixpkgs/issues/85515 167 + typelib-self-user-has-gi-typelib-path = let 168 + tested = typelib-self-user; 169 + in testLib.runTest "typelib-self-user-has-gi-typelib-path" '' 170 + ${expectSomeLineContainingYInFileXToMentionZ "${tested}/bin/foo" "GI_TYPELIB_PATH=" "${typelib-self-user}/lib/girepository-1.0"} 171 + ${expectSomeLineContainingYInFileXToMentionZ "${tested}/libexec/bar" "GI_TYPELIB_PATH=" "${typelib-self-user}/lib/girepository-1.0"} 172 + ''; 173 + }; 174 + }; 175 + } ./wrap-gapps-hook.sh
+30
pkgs/build-support/setup-hooks/wrap-gapps-hook/tests/lib.nix
··· 1 + { runCommand 2 + }: 3 + 4 + rec { 5 + runTest = name: body: runCommand name { } '' 6 + set -o errexit 7 + ${body} 8 + touch $out 9 + ''; 10 + 11 + skip = cond: text: 12 + if cond then '' 13 + echo "Skipping test $name" > /dev/stderr 14 + '' else text; 15 + 16 + fail = text: '' 17 + echo "FAIL: $name: ${text}" > /dev/stderr 18 + exit 1 19 + ''; 20 + 21 + expectSomeLineContainingYInFileXToMentionZ = file: filter: expected: '' 22 + if ! cat "${file}" | grep "${filter}"; then 23 + ${fail "The file “${file}” should include a line containing “${filter}”."} 24 + fi 25 + 26 + if ! cat "${file}" | grep "${filter}" | grep ${expected}; then 27 + ${fail "The file “${file}” should include a line containing “${filter}” that also contains “${expected}”."} 28 + fi 29 + ''; 30 + }
+30
pkgs/build-support/setup-hooks/wrap-gapps-hook/tests/sample-project/Makefile
··· 1 + PREFIX = $(out) 2 + BINDIR = $(PREFIX)/bin 3 + LIBEXECDIR = $(PREFIX)/libexec 4 + LIBDIR = $(PREFIX)/lib 5 + TYPELIBDIR = $(LIBDIR)/girepository-1.0 6 + 7 + all: 8 + echo "Compiling…" 9 + install: 10 + echo "Installing…" 11 + 12 + bin: 13 + mkdir -p $(BINDIR) 14 + # Adds `bin-${foo}` targets, that install `${foo}` executable to `$(BINDIR)`. 15 + bin-%: bin 16 + touch $(BINDIR)/$(@:bin-%=%) 17 + chmod +x $(BINDIR)/$(@:bin-%=%) 18 + 19 + libexec: 20 + mkdir -p $(LIBEXECDIR) 21 + # Adds `libexec-${foo}` targets, that install `${foo}` executable to `$(LIBEXECDIR)`. 22 + libexec-%: libexec 23 + touch $(LIBEXECDIR)/$(@:libexec-%=%) 24 + chmod +x $(LIBEXECDIR)/$(@:libexec-%=%) 25 + 26 + typelib: 27 + mkdir -p $(TYPELIBDIR) 28 + # Adds `typelib-${foo}` targets, that install `${foo}-1.0.typelib` file to `$(TYPELIBDIR)`. 29 + typelib-%: typelib 30 + touch $(TYPELIBDIR)/$(@:typelib-%=%)-1.0.typelib
+1 -3
pkgs/top-level/all-packages.nix
··· 502 502 503 503 findXMLCatalogs = makeSetupHook { } ../build-support/setup-hooks/find-xml-catalogs.sh; 504 504 505 - wrapGAppsHook = makeSetupHook { 506 - deps = lib.optional (!stdenv.isDarwin) dconf.lib ++ [ gtk3 librsvg makeWrapper ]; 507 - } ../build-support/setup-hooks/wrap-gapps-hook.sh; 505 + wrapGAppsHook = callPackage ../build-support/setup-hooks/wrap-gapps-hook { }; 508 506 509 507 separateDebugInfo = makeSetupHook { } ../build-support/setup-hooks/separate-debug-info.sh; 510 508