Merge pull request #186323 from ShamrockLee/make-setuphook-passthru

trivial-builders.nix: Add input argument `passthru` to makeSetupHook
This commit is contained in:
Robert Hensing 2022-09-19 11:30:37 +01:00 committed by GitHub
commit 8deb17a36e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 9 deletions

View file

@ -16,12 +16,14 @@ makeSetupHook {
substitutions = { substitutions = {
cc = "${cc}/bin/${cc.targetPrefix}cc ${lib.escapeShellArgs (map (s: "-fsanitize=${s}") sanitizers)}"; cc = "${cc}/bin/${cc.targetPrefix}cc ${lib.escapeShellArgs (map (s: "-fsanitize=${s}") sanitizers)}";
};
passthru = {
# Extract the function call used to create a binary wrapper from its embedded docstring # Extract the function call used to create a binary wrapper from its embedded docstring
passthru.extractCmd = writeShellScript "extract-binary-wrapper-cmd" '' extractCmd = writeShellScript "extract-binary-wrapper-cmd" ''
strings -dw "$1" | sed -n '/^makeCWrapper/,/^$/ p' strings -dw "$1" | sed -n '/^makeCWrapper/,/^$/ p'
''; '';
passthru.tests = tests.makeBinaryWrapper; tests = tests.makeBinaryWrapper;
}; };
} ./make-binary-wrapper.sh } ./make-binary-wrapper.sh

View file

@ -1,9 +1,8 @@
{ callPackage, makeSetupHook }: { callPackage, makeSetupHook }:
(makeSetupHook { makeSetupHook {
name = "postgresql-test-hook"; name = "postgresql-test-hook";
} ./postgresql-test-hook.sh).overrideAttrs (o: {
passthru.tests = { passthru.tests = {
simple = callPackage ./test.nix { }; simple = callPackage ./test.nix { };
}; };
}) } ./postgresql-test-hook.sh

View file

@ -13,6 +13,7 @@
}: }:
makeSetupHook { makeSetupHook {
name = "wrap-gapps-hook";
deps = lib.optionals (!stdenv.isDarwin) [ deps = lib.optionals (!stdenv.isDarwin) [
# It is highly probable that a program will use GSettings, # It is highly probable that a program will use GSettings,
# at minimum through GTK file chooser dialogue. # at minimum through GTK file chooser dialogue.
@ -36,8 +37,8 @@ makeSetupHook {
# We use the wrapProgram function. # We use the wrapProgram function.
makeWrapper makeWrapper
]; ];
substitutions = { passthru = {
passthru.tests = let tests = let
sample-project = ./tests/sample-project; sample-project = ./tests/sample-project;
testLib = callPackage ./tests/lib.nix { }; testLib = callPackage ./tests/lib.nix { };

View file

@ -1,5 +1,12 @@
{ lib, stdenv, stdenvNoCC, lndir, runtimeShell, shellcheck }: { lib, stdenv, stdenvNoCC, lndir, runtimeShell, shellcheck }:
let
inherit (lib)
optionalAttrs
warn
;
in
rec { rec {
/* Run the shell command `buildCommand' to produce a store path named /* Run the shell command `buildCommand' to produce a store path named
@ -525,12 +532,25 @@ rec {
* substitutions = { bash = "${pkgs.bash}/bin/bash"; }; * substitutions = { bash = "${pkgs.bash}/bin/bash"; };
* meta.platforms = lib.platforms.linux; * meta.platforms = lib.platforms.linux;
* } ./myscript.sh; * } ./myscript.sh;
*
* # setup hook with a package test
* myhellohookTested = makeSetupHook {
* deps = [ hello ];
* substitutions = { bash = "${pkgs.bash}/bin/bash"; };
* meta.platforms = lib.platforms.linux;
* passthru.tests.greeting = callPackage ./test { };
* } ./myscript.sh;
*/ */
makeSetupHook = { name ? "hook", deps ? [], substitutions ? {}, meta ? {} }: script: makeSetupHook = { name ? "hook", deps ? [], substitutions ? {}, meta ? {}, passthru ? {} }: script:
runCommand name runCommand name
(substitutions // { (substitutions // {
inherit meta; inherit meta;
strictDeps = true; strictDeps = true;
# TODO 2023-01, no backport: simplify to inherit passthru;
passthru = passthru
// optionalAttrs (substitutions?passthru)
(warn "makeSetupHook (name = ${lib.strings.escapeNixString name}): `substitutions.passthru` is deprecated. Please set `passthru` directly."
substitutions.passthru);
}) })
('' (''
mkdir -p $out/nix-support mkdir -p $out/nix-support

View file

@ -918,7 +918,9 @@ with pkgs;
{ deps = [ dieHook ]; { deps = [ dieHook ];
substitutions = { substitutions = {
shell = targetPackages.runtimeShell; shell = targetPackages.runtimeShell;
passthru.tests = tests.makeWrapper; };
passthru = {
tests = tests.makeWrapper;
}; };
} }
../build-support/setup-hooks/make-wrapper.sh; ../build-support/setup-hooks/make-wrapper.sh;