From a13513d7c358bd0173f9d43337b52e0ea9a5a091 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Thu, 19 Dec 2024 22:33:07 +0800 Subject: [PATCH] tests.overriding: restructure and categorise by test targets Split tests in the let-in block into tests-stdenv, tests-go, and tests-python. Place the dependent variables into the let-in block of each category. This chore commit causes no rebuilds. (cherry picked from commit 9e66d6ce585636cd243c91a54e09cb7faae5c021) --- pkgs/test/overriding.nix | 228 ++++++++++++++++++++------------------- 1 file changed, 120 insertions(+), 108 deletions(-) diff --git a/pkgs/test/overriding.nix b/pkgs/test/overriding.nix index 7708948730ca3..f268b1064c8dc 100644 --- a/pkgs/test/overriding.nix +++ b/pkgs/test/overriding.nix @@ -5,17 +5,43 @@ }: let - tests = + tests = tests-stdenv // tests-go // tests-python; + + tests-stdenv = let - p = pkgs.python3Packages.xpybutil.overridePythonAttrs (_: { - dontWrapPythonPrograms = true; - }); + addEntangled = + origOverrideAttrs: f: + origOverrideAttrs ( + lib.composeExtensions f ( + self: super: { + passthru = super.passthru // { + entangled = super.passthru.entangled.overrideAttrs f; + overrideAttrs = addEntangled self.overrideAttrs; + }; + } + ) + ); + + entangle = + pkg1: pkg2: + pkg1.overrideAttrs ( + self: super: { + passthru = super.passthru // { + entangled = pkg2; + overrideAttrs = addEntangled self.overrideAttrs; + }; + } + ); + + example = entangle pkgs.hello pkgs.figlet; + + overrides1 = example.overrideAttrs (_: super: { pname = "a-better-${super.pname}"; }); + + repeatedOverrides = overrides1.overrideAttrs ( + _: super: { pname = "${super.pname}-with-blackjack"; } + ); in { - overridePythonAttrs = { - expr = !lib.hasInfix "wrapPythonPrograms" p.postFixup; - expected = true; - }; repeatedOverrides-pname = { expr = repeatedOverrides.pname == "a-better-hello-with-blackjack"; expected = true; @@ -36,6 +62,81 @@ let }).pname == "hello-no-final-attrs-overridden"; expected = true; }; + }; + + tests-go = + let + pet_0_3_4 = pkgs.buildGoModule rec { + pname = "pet"; + version = "0.3.4"; + + src = pkgs.fetchFromGitHub { + owner = "knqyf263"; + repo = "pet"; + rev = "v${version}"; + hash = "sha256-Gjw1dRrgM8D3G7v6WIM2+50r4HmTXvx0Xxme2fH9TlQ="; + }; + + vendorHash = "sha256-ciBIR+a1oaYH+H1PcC8cD8ncfJczk1IiJ8iYNM+R6aA="; + + meta = { + description = "Simple command-line snippet manager, written in Go"; + homepage = "https://github.com/knqyf263/pet"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ kalbasit ]; + }; + }; + + pet_0_4_0 = pkgs.buildGoModule rec { + pname = "pet"; + version = "0.4.0"; + + src = pkgs.fetchFromGitHub { + owner = "knqyf263"; + repo = "pet"; + rev = "v${version}"; + hash = "sha256-gVTpzmXekQxGMucDKskGi+e+34nJwwsXwvQTjRO6Gdg="; + }; + + vendorHash = "sha256-dUvp7FEW09V0xMuhewPGw3TuAic/sD7xyXEYviZ2Ivs="; + + meta = { + description = "Simple command-line snippet manager, written in Go"; + homepage = "https://github.com/knqyf263/pet"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ kalbasit ]; + }; + }; + + pet_0_4_0-overridden = pet_0_3_4.overrideAttrs ( + finalAttrs: previousAttrs: { + version = "0.4.0"; + + src = pkgs.fetchFromGitHub { + inherit (previousAttrs.src) owner repo; + rev = "v${finalAttrs.version}"; + hash = "sha256-gVTpzmXekQxGMucDKskGi+e+34nJwwsXwvQTjRO6Gdg="; + }; + + vendorHash = "sha256-dUvp7FEW09V0xMuhewPGw3TuAic/sD7xyXEYviZ2Ivs="; + } + ); + + pet-foo = pet_0_3_4.overrideAttrs ( + finalAttrs: previousAttrs: { + passthru = previousAttrs.passthru // { + overrideModAttrs = lib.composeExtensions previousAttrs.passthru.overrideModAttrs ( + finalModAttrs: previousModAttrs: { + FOO = "foo"; + } + ); + }; + } + ); + + pet-vendored = pet-foo.overrideAttrs { vendorHash = null; }; + in + { buildGoModule-overrideAttrs = { expr = lib.all @@ -81,107 +182,18 @@ let }; }; - addEntangled = - origOverrideAttrs: f: - origOverrideAttrs ( - lib.composeExtensions f ( - self: super: { - passthru = super.passthru // { - entangled = super.passthru.entangled.overrideAttrs f; - overrideAttrs = addEntangled self.overrideAttrs; - }; - } - ) - ); - - entangle = - pkg1: pkg2: - pkg1.overrideAttrs ( - self: super: { - passthru = super.passthru // { - entangled = pkg2; - overrideAttrs = addEntangled self.overrideAttrs; - }; - } - ); - - example = entangle pkgs.hello pkgs.figlet; - - overrides1 = example.overrideAttrs (_: super: { pname = "a-better-${super.pname}"; }); - - repeatedOverrides = overrides1.overrideAttrs ( - _: super: { pname = "${super.pname}-with-blackjack"; } - ); - - pet_0_3_4 = pkgs.buildGoModule rec { - pname = "pet"; - version = "0.3.4"; - - src = pkgs.fetchFromGitHub { - owner = "knqyf263"; - repo = "pet"; - rev = "v${version}"; - hash = "sha256-Gjw1dRrgM8D3G7v6WIM2+50r4HmTXvx0Xxme2fH9TlQ="; - }; - - vendorHash = "sha256-ciBIR+a1oaYH+H1PcC8cD8ncfJczk1IiJ8iYNM+R6aA="; - - meta = { - description = "Simple command-line snippet manager, written in Go"; - homepage = "https://github.com/knqyf263/pet"; - license = lib.licenses.mit; - maintainers = with lib.maintainers; [ kalbasit ]; - }; - }; - - pet_0_4_0 = pkgs.buildGoModule rec { - pname = "pet"; - version = "0.4.0"; - - src = pkgs.fetchFromGitHub { - owner = "knqyf263"; - repo = "pet"; - rev = "v${version}"; - hash = "sha256-gVTpzmXekQxGMucDKskGi+e+34nJwwsXwvQTjRO6Gdg="; - }; - - vendorHash = "sha256-dUvp7FEW09V0xMuhewPGw3TuAic/sD7xyXEYviZ2Ivs="; - - meta = { - description = "Simple command-line snippet manager, written in Go"; - homepage = "https://github.com/knqyf263/pet"; - license = lib.licenses.mit; - maintainers = with lib.maintainers; [ kalbasit ]; - }; - }; - - pet_0_4_0-overridden = pet_0_3_4.overrideAttrs ( - finalAttrs: previousAttrs: { - version = "0.4.0"; - - src = pkgs.fetchFromGitHub { - inherit (previousAttrs.src) owner repo; - rev = "v${finalAttrs.version}"; - hash = "sha256-gVTpzmXekQxGMucDKskGi+e+34nJwwsXwvQTjRO6Gdg="; - }; - - vendorHash = "sha256-dUvp7FEW09V0xMuhewPGw3TuAic/sD7xyXEYviZ2Ivs="; - } - ); - - pet-foo = pet_0_3_4.overrideAttrs ( - finalAttrs: previousAttrs: { - passthru = previousAttrs.passthru // { - overrideModAttrs = lib.composeExtensions previousAttrs.passthru.overrideModAttrs ( - finalModAttrs: previousModAttrs: { - FOO = "foo"; - } - ); + tests-python = + let + p = pkgs.python3Packages.xpybutil.overridePythonAttrs (_: { + dontWrapPythonPrograms = true; + }); + in + { + overridePythonAttrs = { + expr = !lib.hasInfix "wrapPythonPrograms" p.postFixup; + expected = true; }; - } - ); - - pet-vendored = pet-foo.overrideAttrs { vendorHash = null; }; + }; in stdenvNoCC.mkDerivation {