From 054c5f0e106d8a0169582fed4c1b2ba86647f73d Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Tue, 3 Sep 2024 04:14:28 +0800 Subject: [PATCH] treewide: handle preDistPhases __structuredAttrs-agnostically Always specify the preDistPhases attribute as a list instead of a string. Append elements to the preDistPhases Bash variable using appendToVar instead of string or Bash array concatenation. Handle element insertion before a specific element using string substitution as before, but handle both structured and unstructured attributes. --- .../vim/plugins/neovim-require-check-hook.sh | 2 +- .../editors/vim/plugins/vim-command-check-hook.sh | 2 +- pkgs/build-support/make-darwin-bundle/default.nix | 2 +- .../octave-write-required-octave-packages-hook.sh | 2 +- .../hooks/write-required-octave-packages-hook.sh | 2 +- .../python/hooks/pytest-check-hook.sh | 2 +- .../python/hooks/python-catch-conflicts-hook.sh | 2 +- .../python/hooks/python-imports-check-hook.sh | 2 +- .../hooks/python-remove-bin-bytecode-hook.sh | 2 +- .../interpreters/python/hooks/sphinx-hook.sh | 2 +- .../python/hooks/unittest-check-hook.sh | 2 +- .../python-modules/pytest-forked/setup-hook.sh | 15 +++++++++++---- .../python-modules/pytest-xdist/setup-hook.sh | 15 +++++++++++---- pkgs/development/python-modules/pytest/7.nix | 4 ++-- .../development/python-modules/pytest/default.nix | 4 ++-- .../python2-modules/pytest/default.nix | 4 ++-- .../manifest-requirements-check-hook.sh | 2 +- 17 files changed, 40 insertions(+), 26 deletions(-) diff --git a/pkgs/applications/editors/vim/plugins/neovim-require-check-hook.sh b/pkgs/applications/editors/vim/plugins/neovim-require-check-hook.sh index 0c6a0010845d..e901e4fd2774 100644 --- a/pkgs/applications/editors/vim/plugins/neovim-require-check-hook.sh +++ b/pkgs/applications/editors/vim/plugins/neovim-require-check-hook.sh @@ -16,6 +16,6 @@ neovimRequireCheckHook () { } echo "Using neovimRequireCheckHook" -preDistPhases+=" neovimRequireCheckHook" +appendToVar preDistPhases neovimRequireCheckHook diff --git a/pkgs/applications/editors/vim/plugins/vim-command-check-hook.sh b/pkgs/applications/editors/vim/plugins/vim-command-check-hook.sh index c4ddd8e0c5af..402910fd0cbd 100644 --- a/pkgs/applications/editors/vim/plugins/vim-command-check-hook.sh +++ b/pkgs/applications/editors/vim/plugins/vim-command-check-hook.sh @@ -21,5 +21,5 @@ vimCommandCheckHook () { } echo "Using vimCommandCheckHook" -preDistPhases+=" vimCommandCheckHook" +appendToVar preDistPhases vimCommandCheckHook diff --git a/pkgs/build-support/make-darwin-bundle/default.nix b/pkgs/build-support/make-darwin-bundle/default.nix index 52dd54b0b2c4..a80ebf8fac9e 100644 --- a/pkgs/build-support/make-darwin-bundle/default.nix +++ b/pkgs/build-support/make-darwin-bundle/default.nix @@ -22,5 +22,5 @@ writeShellScript "make-darwin-bundle-${name}" ('' ${writeDarwinBundle}/bin/write-darwin-bundle "''${!outputBin}" "${name}" "${exec}" } - preDistPhases+=" makeDarwinBundlePhase" + appendToVar preDistPhases makeDarwinBundlePhase '') diff --git a/pkgs/development/interpreters/octave/hooks/octave-write-required-octave-packages-hook.sh b/pkgs/development/interpreters/octave/hooks/octave-write-required-octave-packages-hook.sh index 64e87d68246f..fb808485a36a 100644 --- a/pkgs/development/interpreters/octave/hooks/octave-write-required-octave-packages-hook.sh +++ b/pkgs/development/interpreters/octave/hooks/octave-write-required-octave-packages-hook.sh @@ -13,5 +13,5 @@ octaveWriteRequiredOctavePackagesPhase() { # Yes its a bit long... if [ -z "${dontWriteRequiredOctavePackagesPhase-}" ]; then echo "Using octaveWriteRequiredOctavePackagesPhase" - preDistPhases+=" octaveWriteRequiredOctavePackagesPhase" + appendToVar preDistPhases octaveWriteRequiredOctavePackagesPhase fi diff --git a/pkgs/development/interpreters/octave/hooks/write-required-octave-packages-hook.sh b/pkgs/development/interpreters/octave/hooks/write-required-octave-packages-hook.sh index 032ea398ac56..6c5de6e4fc4f 100644 --- a/pkgs/development/interpreters/octave/hooks/write-required-octave-packages-hook.sh +++ b/pkgs/development/interpreters/octave/hooks/write-required-octave-packages-hook.sh @@ -13,5 +13,5 @@ writeRequiredOctavePackagesPhase() { # Yes its a bit long... if [ -z "${dontWriteRequiredOctavePackagesPhase-}" ]; then echo "Using writeRequiredOctavePackagesPhase" - preDistPhases+=" writeRequiredOctavePackagesPhase" + appendToVar preDistPhases writeRequiredOctavePackagesPhase fi diff --git a/pkgs/development/interpreters/python/hooks/pytest-check-hook.sh b/pkgs/development/interpreters/python/hooks/pytest-check-hook.sh index 06694e79e492..a9e82674c5f8 100644 --- a/pkgs/development/interpreters/python/hooks/pytest-check-hook.sh +++ b/pkgs/development/interpreters/python/hooks/pytest-check-hook.sh @@ -58,5 +58,5 @@ function pytestCheckPhase() { if [ -z "${dontUsePytestCheck-}" ] && [ -z "${installCheckPhase-}" ]; then echo "Using pytestCheckPhase" - preDistPhases+=" pytestCheckPhase" + appendToVar preDistPhases pytestCheckPhase fi diff --git a/pkgs/development/interpreters/python/hooks/python-catch-conflicts-hook.sh b/pkgs/development/interpreters/python/hooks/python-catch-conflicts-hook.sh index 0abcad3c42f2..6ba3d7f65cb4 100644 --- a/pkgs/development/interpreters/python/hooks/python-catch-conflicts-hook.sh +++ b/pkgs/development/interpreters/python/hooks/python-catch-conflicts-hook.sh @@ -6,5 +6,5 @@ pythonCatchConflictsPhase() { } if [ -z "${dontUsePythonCatchConflicts-}" ]; then - preDistPhases+=" pythonCatchConflictsPhase" + appendToVar preDistPhases pythonCatchConflictsPhase fi diff --git a/pkgs/development/interpreters/python/hooks/python-imports-check-hook.sh b/pkgs/development/interpreters/python/hooks/python-imports-check-hook.sh index b65d6e745247..f4ef271ac1b2 100644 --- a/pkgs/development/interpreters/python/hooks/python-imports-check-hook.sh +++ b/pkgs/development/interpreters/python/hooks/python-imports-check-hook.sh @@ -18,5 +18,5 @@ pythonImportsCheckPhase () { if [ -z "${dontUsePythonImportsCheck-}" ]; then echo "Using pythonImportsCheckPhase" - preDistPhases+=" pythonImportsCheckPhase" + appendToVar preDistPhases pythonImportsCheckPhase fi diff --git a/pkgs/development/interpreters/python/hooks/python-remove-bin-bytecode-hook.sh b/pkgs/development/interpreters/python/hooks/python-remove-bin-bytecode-hook.sh index 1180694294db..d67c0c557353 100644 --- a/pkgs/development/interpreters/python/hooks/python-remove-bin-bytecode-hook.sh +++ b/pkgs/development/interpreters/python/hooks/python-remove-bin-bytecode-hook.sh @@ -13,5 +13,5 @@ pythonRemoveBinBytecodePhase () { } if [ -z "${dontUsePythonRemoveBinBytecode-}" ]; then - preDistPhases+=" pythonRemoveBinBytecodePhase" + appendToVar preDistPhases pythonRemoveBinBytecodePhase fi diff --git a/pkgs/development/interpreters/python/hooks/sphinx-hook.sh b/pkgs/development/interpreters/python/hooks/sphinx-hook.sh index 0307e83d9479..0f32a6ec0e82 100644 --- a/pkgs/development/interpreters/python/hooks/sphinx-hook.sh +++ b/pkgs/development/interpreters/python/hooks/sphinx-hook.sh @@ -69,4 +69,4 @@ installSphinxPhase() { runHook postInstallSphinx } -preDistPhases+=" buildSphinxPhase installSphinxPhase" +appendToVar preDistPhases buildSphinxPhase installSphinxPhase diff --git a/pkgs/development/interpreters/python/hooks/unittest-check-hook.sh b/pkgs/development/interpreters/python/hooks/unittest-check-hook.sh index f4bd34747730..64ecb13cbc71 100644 --- a/pkgs/development/interpreters/python/hooks/unittest-check-hook.sh +++ b/pkgs/development/interpreters/python/hooks/unittest-check-hook.sh @@ -13,5 +13,5 @@ unittestCheckPhase() { if [ -z "${dontUseUnittestCheck-}" ] && [ -z "${installCheckPhase-}" ]; then echo "Using unittestCheckPhase" - preDistPhases+=" unittestCheckPhase" + appendToVar preDistPhases unittestCheckPhase fi diff --git a/pkgs/development/python-modules/pytest-forked/setup-hook.sh b/pkgs/development/python-modules/pytest-forked/setup-hook.sh index e613feadf834..0eff690e9079 100644 --- a/pkgs/development/python-modules/pytest-forked/setup-hook.sh +++ b/pkgs/development/python-modules/pytest-forked/setup-hook.sh @@ -16,10 +16,17 @@ pytestForkedHook() { # until we have dependency mechanism in generic builder, we need to use this ugly hack. if [ -z "${dontUsePytestForked-}" ] && [ -z "${dontUsePytestCheck-}" ]; then - if [[ " ${preDistPhases:-} " =~ " pytestCheckPhase " ]]; then - preDistPhases+=" " - preDistPhases="${preDistPhases/ pytestCheckPhase / pytestForkedHook pytestCheckPhase }" + if [[ " ${preDistPhases[*]:-} " =~ " pytestCheckPhase " ]]; then + _preDistPhases="${preDistPhases[*]} " + _preDistPhases="${_preDistPhases/ pytestCheckPhase / pytestForkedHook pytestCheckPhase }" + if [[ -n "${__structuredAttrs-}" ]]; then + preDistPhases=() + else + preDistPhases="" + fi + appendToVar preDistPhases $_preDistPhases + unset _preDistPhases else - preDistPhases+=" pytestForkedHook" + appendToVar preDistPhases pytestForkedHook fi fi diff --git a/pkgs/development/python-modules/pytest-xdist/setup-hook.sh b/pkgs/development/python-modules/pytest-xdist/setup-hook.sh index 4c6473cea64d..9819e0d3ec7d 100644 --- a/pkgs/development/python-modules/pytest-xdist/setup-hook.sh +++ b/pkgs/development/python-modules/pytest-xdist/setup-hook.sh @@ -8,10 +8,17 @@ pytestXdistHook() { # until we have dependency mechanism in generic builder, we need to use this ugly hack. if [ -z "${dontUsePytestXdist-}" ] && [ -z "${dontUsePytestCheck-}" ]; then - if [[ " ${preDistPhases:-} " =~ " pytestCheckPhase " ]]; then - preDistPhases+=" " - preDistPhases="${preDistPhases/ pytestCheckPhase / pytestXdistHook pytestCheckPhase }" + if [[ " ${preDistPhases[*]:-} " =~ " pytestCheckPhase " ]]; then + _preDistPhases="${preDistPhases[*]} " + _preDistPhases="${_preDistPhases/ pytestCheckPhase / pytestXdistHook pytestCheckPhase }" + if [[ -n "${__structuredAttrs-}" ]]; then + preDistPhases=() + else + preDistPhases="" + fi + appendToVar preDistPhases $_preDistPhases + unset _preDistPhases else - preDistPhases+=" pytestXdistHook" + appendToVar preDistPhases pytestXdistHook fi fi diff --git a/pkgs/development/python-modules/pytest/7.nix b/pkgs/development/python-modules/pytest/7.nix index 8ca33b158e5c..3468bc73c098 100644 --- a/pkgs/development/python-modules/pytest/7.nix +++ b/pkgs/development/python-modules/pytest/7.nix @@ -87,7 +87,7 @@ let pytestcachePhase() { find $out -name .pytest_cache -type d -exec rm -rf {} + } - preDistPhases+=" pytestcachePhase" + appendToVar preDistPhases pytestcachePhase # pytest generates it's own bytecode files to improve assertion messages. # These files similar to cpython's bytecode files but are never laoded @@ -100,7 +100,7 @@ let # https://github.com/pytest-dev/pytest/blob/7.2.1/src/_pytest/assertion/rewrite.py#L51-L53 find $out -name "*-pytest-*.py[co]" -delete } - preDistPhases+=" pytestRemoveBytecodePhase" + appendToVar preDistPhases pytestRemoveBytecodePhase ''; pythonImportsCheck = [ "pytest" ]; diff --git a/pkgs/development/python-modules/pytest/default.nix b/pkgs/development/python-modules/pytest/default.nix index fc5ca9c2a37b..1dcc23658394 100644 --- a/pkgs/development/python-modules/pytest/default.nix +++ b/pkgs/development/python-modules/pytest/default.nix @@ -84,7 +84,7 @@ buildPythonPackage rec { pytestcachePhase() { find $out -name .pytest_cache -type d -exec rm -rf {} + } - preDistPhases+=" pytestcachePhase" + appendToVar preDistPhases pytestcachePhase # pytest generates it's own bytecode files to improve assertion messages. # These files similar to cpython's bytecode files but are never laoded @@ -97,7 +97,7 @@ buildPythonPackage rec { # https://github.com/pytest-dev/pytest/blob/7.2.1/src/_pytest/assertion/rewrite.py#L51-L53 find $out -name "*-pytest-*.py[co]" -delete } - preDistPhases+=" pytestRemoveBytecodePhase" + appendToVar preDistPhases pytestRemoveBytecodePhase ''; pythonImportsCheck = [ "pytest" ]; diff --git a/pkgs/development/python2-modules/pytest/default.nix b/pkgs/development/python2-modules/pytest/default.nix index 0edfd3039112..fa086eb46c7c 100644 --- a/pkgs/development/python2-modules/pytest/default.nix +++ b/pkgs/development/python2-modules/pytest/default.nix @@ -42,7 +42,7 @@ buildPythonPackage rec { find $out -name .pytest_cache -type d -exec rm -rf {} + } - preDistPhases+=" pytestcachePhase" + appendToVar preDistPhases pytestcachePhase # pytest generates it's own bytecode files to improve assertion messages. # These files similar to cpython's bytecode files but are never laoded @@ -55,7 +55,7 @@ buildPythonPackage rec { # https://github.com/pytest-dev/pytest/blob/4.6.11/src/_pytest/assertion/rewrite.py#L32-L47 find $out -name "*-PYTEST.py[co]" -delete } - preDistPhases+=" pytestRemoveBytecodePhase" + appendToVar preDistPhases pytestRemoveBytecodePhase ''; meta = with lib; { diff --git a/pkgs/servers/home-assistant/build-custom-component/manifest-requirements-check-hook.sh b/pkgs/servers/home-assistant/build-custom-component/manifest-requirements-check-hook.sh index 74f29ca399ed..1fb366d13b43 100644 --- a/pkgs/servers/home-assistant/build-custom-component/manifest-requirements-check-hook.sh +++ b/pkgs/servers/home-assistant/build-custom-component/manifest-requirements-check-hook.sh @@ -21,5 +21,5 @@ function manifestCheckPhase() { if [ -z "${dontCheckManifest-}" ] && [ -z "${installCheckPhase-}" ]; then echo "Using manifestCheckPhase" - preDistPhases+=" manifestCheckPhase" + appendToVar preDistPhases manifestCheckPhase fi