From af9b49edab7bb92b319ff459c9ed52bd4a45f1ec Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 1 Mar 2025 22:45:57 +0100 Subject: [PATCH 1/3] tests.srcOnly: Add test cases for equivalences in the interface --- pkgs/build-support/src-only/tests.nix | 78 ++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 14 deletions(-) diff --git a/pkgs/build-support/src-only/tests.nix b/pkgs/build-support/src-only/tests.nix index 7ea7c23621be..51f5b4c96181 100644 --- a/pkgs/build-support/src-only/tests.nix +++ b/pkgs/build-support/src-only/tests.nix @@ -1,28 +1,78 @@ { runCommand, srcOnly, + hello, emptyDirectory, glibc, + stdenv, + testers, }: let emptySrc = srcOnly emptyDirectory; glibcSrc = srcOnly glibc; + + # It can be invoked in a number of ways. Let's make sure they're equivalent. + glibcSrcDrvAttrs = srcOnly glibc.drvAttrs; + # glibcSrcFreeform = # ???; + helloSrc = srcOnly hello; + helloSrcDrvAttrs = srcOnly hello.drvAttrs; + + # The srcOnly invocation leaks a lot of attrs into the srcOnly derivation, + # so for comparing with the freeform invocation, we need to make a selection. + # Otherwise, we'll be comparing against whatever attribute the fancy hello drv + # has. + helloDrvSimple = stdenv.mkDerivation { + inherit (hello) + name + pname + version + src + patches + ; + }; + helloDrvSimpleSrc = srcOnly helloDrvSimple; + helloDrvSimpleSrcFreeform = srcOnly { + inherit (helloDrvSimple) + name + pname + version + src + patches + stdenv + ; + }; + in -runCommand "srcOnly-tests" { } '' - # Test that emptySrc is empty - if [ -n "$(ls -A ${emptySrc})" ]; then - echo "emptySrc is not empty" - exit 1 - fi +runCommand "srcOnly-tests" + { + moreTests = [ + (testers.testEqualDerivation "glibcSrcDrvAttrs == glibcSrc" glibcSrcDrvAttrs glibcSrc) + # (testers.testEqualDerivation + # "glibcSrcFreeform == glibcSrc" + # glibcSrcFreeform + # glibcSrc) + (testers.testEqualDerivation "helloSrcDrvAttrs == helloSrc" helloSrcDrvAttrs helloSrc) + (testers.testEqualDerivation "helloDrvSimpleSrcFreeform == helloDrvSimpleSrc" + helloDrvSimpleSrcFreeform + helloDrvSimpleSrc + ) + ]; + } + '' + # Test that emptySrc is empty + if [ -n "$(ls -A ${emptySrc})" ]; then + echo "emptySrc is not empty" + exit 1 + fi - # Test that glibcSrc is not empty - if [ -z "$(ls -A ${glibcSrc})" ]; then - echo "glibcSrc is empty" - exit 1 - fi + # Test that glibcSrc is not empty + if [ -z "$(ls -A ${glibcSrc})" ]; then + echo "glibcSrc is empty" + exit 1 + fi - # Make $out exist to avoid build failure - mkdir -p $out -'' + # Make $out exist to avoid build failure + mkdir -p $out + '' From d93bb6f46ab4e33732f403a4f0aaff45ac020237 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 5 Apr 2025 18:45:26 +0200 Subject: [PATCH 2/3] tests.srcOnly: Use zlib instead of glibc This makes the test more portable, as glibc does not evaluate on all platforms. Unfortunately the test fails on darwin for an unrelated reason. __impureHostDeps values were duplicated. --- pkgs/build-support/src-only/tests.nix | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pkgs/build-support/src-only/tests.nix b/pkgs/build-support/src-only/tests.nix index 51f5b4c96181..d00a2060703e 100644 --- a/pkgs/build-support/src-only/tests.nix +++ b/pkgs/build-support/src-only/tests.nix @@ -3,18 +3,18 @@ srcOnly, hello, emptyDirectory, - glibc, + zlib, stdenv, testers, }: let emptySrc = srcOnly emptyDirectory; - glibcSrc = srcOnly glibc; + zlibSrc = srcOnly zlib; # It can be invoked in a number of ways. Let's make sure they're equivalent. - glibcSrcDrvAttrs = srcOnly glibc.drvAttrs; - # glibcSrcFreeform = # ???; + zlibSrcDrvAttrs = srcOnly zlib.drvAttrs; + # zlibSrcFreeform = # ???; helloSrc = srcOnly hello; helloSrcDrvAttrs = srcOnly hello.drvAttrs; @@ -48,11 +48,11 @@ in runCommand "srcOnly-tests" { moreTests = [ - (testers.testEqualDerivation "glibcSrcDrvAttrs == glibcSrc" glibcSrcDrvAttrs glibcSrc) + (testers.testEqualDerivation "zlibSrcDrvAttrs == zlibSrc" zlibSrcDrvAttrs zlibSrc) # (testers.testEqualDerivation - # "glibcSrcFreeform == glibcSrc" - # glibcSrcFreeform - # glibcSrc) + # "zlibSrcFreeform == zlibSrc" + # zlibSrcFreeform + # zlibSrc) (testers.testEqualDerivation "helloSrcDrvAttrs == helloSrc" helloSrcDrvAttrs helloSrc) (testers.testEqualDerivation "helloDrvSimpleSrcFreeform == helloDrvSimpleSrc" helloDrvSimpleSrcFreeform @@ -67,9 +67,9 @@ runCommand "srcOnly-tests" exit 1 fi - # Test that glibcSrc is not empty - if [ -z "$(ls -A ${glibcSrc})" ]; then - echo "glibcSrc is empty" + # Test that zlibSrc is not empty + if [ -z "$(ls -A ${zlibSrc})" ]; then + echo "zlibSrc is empty" exit 1 fi From 966fc630ddfae521af2fc9f5575a78275145827d Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 5 Apr 2025 18:54:01 +0200 Subject: [PATCH 3/3] tests.srcOnly: Work around duplication of attr on darwin --- pkgs/build-support/src-only/tests.nix | 31 ++++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/pkgs/build-support/src-only/tests.nix b/pkgs/build-support/src-only/tests.nix index d00a2060703e..f739715e717d 100644 --- a/pkgs/build-support/src-only/tests.nix +++ b/pkgs/build-support/src-only/tests.nix @@ -1,4 +1,5 @@ { + lib, runCommand, srcOnly, hello, @@ -32,16 +33,26 @@ let ; }; helloDrvSimpleSrc = srcOnly helloDrvSimple; - helloDrvSimpleSrcFreeform = srcOnly { - inherit (helloDrvSimple) - name - pname - version - src - patches - stdenv - ; - }; + helloDrvSimpleSrcFreeform = srcOnly ( + { + inherit (helloDrvSimple) + name + pname + version + src + patches + stdenv + ; + } + # __impureHostDeps get duplicated in helloDrvSimpleSrc (on darwin) + # This is harmless, but fails the test for what is arguably an + # unrelated non-problem, so we just work around it here. + # The inclusion of __impureHostDeps really shouldn't be required, + # and should be removed from this test. + // lib.optionalAttrs (helloDrvSimple ? __impureHostDeps) { + inherit (helloDrvSimple) __impureHostDeps; + } + ); in