treewide: handle *Phases variables __structuredAttrs-agnostically (#339117)

This commit is contained in:
Philip Taron 2024-09-07 09:17:57 -07:00 committed by GitHub
commit 4160ccc634
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
41 changed files with 72 additions and 56 deletions

View File

@ -518,8 +518,10 @@ There are a number of variables that control what phases are executed and in wha
Specifies the phases. You can change the order in which phases are executed, or add new phases, by setting this variable. If its not set, the default value is used, which is `$prePhases unpackPhase patchPhase $preConfigurePhases configurePhase $preBuildPhases buildPhase checkPhase $preInstallPhases installPhase fixupPhase installCheckPhase $preDistPhases distPhase $postPhases`. Specifies the phases. You can change the order in which phases are executed, or add new phases, by setting this variable. If its not set, the default value is used, which is `$prePhases unpackPhase patchPhase $preConfigurePhases configurePhase $preBuildPhases buildPhase checkPhase $preInstallPhases installPhase fixupPhase installCheckPhase $preDistPhases distPhase $postPhases`.
The elements of `phases` must not contain spaces. If `phases` is specified as a Nix Language attribute, it should be specified as lists instead of strings. The same rules apply to the `*Phases` variables.
It is discouraged to set this variable, as it is easy to miss some important functionality hidden in some of the less obviously needed phases (like `fixupPhase` which patches the shebang of scripts). It is discouraged to set this variable, as it is easy to miss some important functionality hidden in some of the less obviously needed phases (like `fixupPhase` which patches the shebang of scripts).
Usually, if you just want to add a few phases, its more convenient to set one of the variables below (such as `preInstallPhases`). Usually, if you just want to add a few phases, its more convenient to set one of the `*Phases` variables below.
##### `prePhases` {#var-stdenv-prePhases} ##### `prePhases` {#var-stdenv-prePhases}

View File

@ -16,6 +16,6 @@ neovimRequireCheckHook () {
} }
echo "Using neovimRequireCheckHook" echo "Using neovimRequireCheckHook"
preDistPhases+=" neovimRequireCheckHook" appendToVar preDistPhases neovimRequireCheckHook

View File

@ -21,5 +21,5 @@ vimCommandCheckHook () {
} }
echo "Using vimCommandCheckHook" echo "Using vimCommandCheckHook"
preDistPhases+=" vimCommandCheckHook" appendToVar preDistPhases vimCommandCheckHook

View File

@ -17,7 +17,7 @@ let
pluginDerivation = attrs: let pluginDerivation = attrs: let
name = attrs.name or "${attrs.pname}-${attrs.version}"; name = attrs.name or "${attrs.pname}-${attrs.version}";
in stdenv.mkDerivation ({ in stdenv.mkDerivation ({
prePhases = "extraLib"; prePhases = [ "extraLib" ];
extraLib = '' extraLib = ''
installScripts(){ installScripts(){
mkdir -p $out/${gimp.targetScriptDir}/${name}; mkdir -p $out/${gimp.targetScriptDir}/${name};
@ -54,7 +54,7 @@ let
}); });
scriptDerivation = {src, ...}@attrs : pluginDerivation ({ scriptDerivation = {src, ...}@attrs : pluginDerivation ({
prePhases = "extraLib"; prePhases = [ "extraLib" ];
dontUnpack = true; dontUnpack = true;
installPhase = '' installPhase = ''
runHook preInstall runHook preInstall

View File

@ -146,7 +146,7 @@ stdenv.mkDerivation (removeAttrs ({
}) })
// (optionalAttrs (args?useMelquiondRemake) rec { // (optionalAttrs (args?useMelquiondRemake) rec {
COQUSERCONTRIB = "$out/lib/coq/${coq.coq-version}/user-contrib"; COQUSERCONTRIB = "$out/lib/coq/${coq.coq-version}/user-contrib";
preConfigurePhases = "autoconf"; preConfigurePhases = [ "autoconf" ];
configureFlags = [ "--libdir=${COQUSERCONTRIB}/${useMelquiondRemake.logpath or ""}" ]; configureFlags = [ "--libdir=${COQUSERCONTRIB}/${useMelquiondRemake.logpath or ""}" ];
buildPhase = "./remake -j$NIX_BUILD_CORES"; buildPhase = "./remake -j$NIX_BUILD_CORES";
installPhase = "./remake install"; installPhase = "./remake install";

View File

@ -22,5 +22,5 @@ writeShellScript "make-darwin-bundle-${name}" (''
${writeDarwinBundle}/bin/write-darwin-bundle "''${!outputBin}" "${name}" "${exec}" ${writeDarwinBundle}/bin/write-darwin-bundle "''${!outputBin}" "${name}" "${exec}"
} }
preDistPhases+=" makeDarwinBundlePhase" appendToVar preDistPhases makeDarwinBundlePhase
'') '')

View File

@ -24,7 +24,7 @@ stdenv.mkDerivation (
prefix = "/usr/local"; prefix = "/usr/local";
postPhases = "finalPhase"; postPhases = [ "finalPhase" ];
} }
// args // // args //

View File

@ -18,7 +18,7 @@ vmTools.runInLinuxImage (stdenv.mkDerivation (
prefix = "/usr"; prefix = "/usr";
prePhases = "installExtraDebsPhase sysInfoPhase"; prePhases = [ "installExtraDebsPhase" "sysInfoPhase" ];
} }
// removeAttrs args ["vmTools" "lib"] // // removeAttrs args ["vmTools" "lib"] //

View File

@ -31,8 +31,8 @@ stdenv.mkDerivation (
showBuildStats = true; showBuildStats = true;
preConfigurePhases = "autoconfPhase"; preConfigurePhases = [ "autoconfPhase" ];
postPhases = "finalPhase"; postPhases = [ "finalPhase" ];
# Autoconfiscate the sources. # Autoconfiscate the sources.
autoconfPhase = '' autoconfPhase = ''

View File

@ -1,4 +1,4 @@
preConfigurePhases="${preConfigurePhases:-} autoreconfPhase" appendToVar preConfigurePhases autoreconfPhase
autoreconfPhase() { autoreconfPhase() {
runHook preAutoreconf runHook preAutoreconf

View File

@ -1,4 +1,4 @@
postPhases+=" cleanupBuildDir" appendToVar postPhases cleanupBuildDir
# Force GCC to build with coverage instrumentation. Also disable # Force GCC to build with coverage instrumentation. Also disable
# optimisation, since it may confuse things. # optimisation, since it may confuse things.

View File

@ -1,4 +1,4 @@
prePhases+=" moveBuildDir" appendToVar prePhases moveBuildDir
moveBuildDir() { moveBuildDir() {
mkdir -p $out/.build mkdir -p $out/.build

View File

@ -1,4 +1,4 @@
postPhases+=" coverageReportPhase" appendToVar postPhases coverageReportPhase
coverageReportPhase() { coverageReportPhase() {
lcov --directory . --capture --output-file app.info lcov --directory . --capture --output-file app.info

View File

@ -1,11 +1,11 @@
prePhases+=" moveBuildDir" appendToVar prePhases moveBuildDir
moveBuildDir() { moveBuildDir() {
mkdir -p $out/.build mkdir -p $out/.build
cd $out/.build cd $out/.build
} }
postPhases+=" removeBuildDir" appendToVar postPhases removeBuildDir
removeBuildDir() { removeBuildDir() {
rm -rf $out/.build rm -rf $out/.build

View File

@ -1,4 +1,4 @@
preConfigurePhases+=" updateAutotoolsGnuConfigScriptsPhase" appendToVar preConfigurePhases updateAutotoolsGnuConfigScriptsPhase
updateAutotoolsGnuConfigScriptsPhase() { updateAutotoolsGnuConfigScriptsPhase() {
if [ -n "${dontUpdateAutotoolsGnuConfigScripts-}" ]; then return; fi if [ -n "${dontUpdateAutotoolsGnuConfigScripts-}" ]; then return; fi

View File

@ -18,7 +18,7 @@ echoCmd "HAREPATH" "$HAREPATH"
echoCmd "hare" "$(command -v hare)" echoCmd "hare" "$(command -v hare)"
echoCmd "hare-native" "$(command -v hare-native)" echoCmd "hare-native" "$(command -v hare-native)"
' '
prePhases+=("hareSetStdlibPhase" "hareInfoPhase") appendToVar prePhases hareSetStdlibPhase hareInfoPhase
readonly hare_unconditional_flags="@hare_unconditional_flags@" readonly hare_unconditional_flags="@hare_unconditional_flags@"
case "${hareBuildType:-"release"}" in case "${hareBuildType:-"release"}" in

View File

@ -18,7 +18,7 @@ addGnustepInstallFlags() {
) )
} }
preInstallPhases+=" addGnustepInstallFlags" appendToVar preInstallPhases addGnustepInstallFlags
addGNUstepEnvVars() { addGNUstepEnvVars() {
local filename local filename

View File

@ -10,5 +10,5 @@ xdtAutogenPhase() {
} }
if [ -z "${dontUseXdtAutogenPhase-}" ]; then if [ -z "${dontUseXdtAutogenPhase-}" ]; then
preConfigurePhases+=(xdtAutogenPhase) appendToVar preConfigurePhases xdtAutogenPhase
fi fi

View File

@ -77,6 +77,6 @@ configureNuget() {
} }
if [[ -z ${dontConfigureNuget-} ]]; then if [[ -z ${dontConfigureNuget-} ]]; then
prePhases+=(createNugetDirs) appendToVar prePhases createNugetDirs
preConfigurePhases+=(configureNuget) appendToVar preConfigurePhases configureNuget
fi fi

View File

@ -13,5 +13,5 @@ octaveWriteRequiredOctavePackagesPhase() {
# Yes its a bit long... # Yes its a bit long...
if [ -z "${dontWriteRequiredOctavePackagesPhase-}" ]; then if [ -z "${dontWriteRequiredOctavePackagesPhase-}" ]; then
echo "Using octaveWriteRequiredOctavePackagesPhase" echo "Using octaveWriteRequiredOctavePackagesPhase"
preDistPhases+=" octaveWriteRequiredOctavePackagesPhase" appendToVar preDistPhases octaveWriteRequiredOctavePackagesPhase
fi fi

View File

@ -13,5 +13,5 @@ writeRequiredOctavePackagesPhase() {
# Yes its a bit long... # Yes its a bit long...
if [ -z "${dontWriteRequiredOctavePackagesPhase-}" ]; then if [ -z "${dontWriteRequiredOctavePackagesPhase-}" ]; then
echo "Using writeRequiredOctavePackagesPhase" echo "Using writeRequiredOctavePackagesPhase"
preDistPhases+=" writeRequiredOctavePackagesPhase" appendToVar preDistPhases writeRequiredOctavePackagesPhase
fi fi

View File

@ -58,5 +58,5 @@ function pytestCheckPhase() {
if [ -z "${dontUsePytestCheck-}" ] && [ -z "${installCheckPhase-}" ]; then if [ -z "${dontUsePytestCheck-}" ] && [ -z "${installCheckPhase-}" ]; then
echo "Using pytestCheckPhase" echo "Using pytestCheckPhase"
preDistPhases+=" pytestCheckPhase" appendToVar preDistPhases pytestCheckPhase
fi fi

View File

@ -6,5 +6,5 @@ pythonCatchConflictsPhase() {
} }
if [ -z "${dontUsePythonCatchConflicts-}" ]; then if [ -z "${dontUsePythonCatchConflicts-}" ]; then
preDistPhases+=" pythonCatchConflictsPhase" appendToVar preDistPhases pythonCatchConflictsPhase
fi fi

View File

@ -18,5 +18,5 @@ pythonImportsCheckPhase () {
if [ -z "${dontUsePythonImportsCheck-}" ]; then if [ -z "${dontUsePythonImportsCheck-}" ]; then
echo "Using pythonImportsCheckPhase" echo "Using pythonImportsCheckPhase"
preDistPhases+=" pythonImportsCheckPhase" appendToVar preDistPhases pythonImportsCheckPhase
fi fi

View File

@ -20,5 +20,5 @@ pythonRecompileBytecodePhase () {
} }
if [ -z "${dontUsePythonRecompileBytecode-}" ]; then if [ -z "${dontUsePythonRecompileBytecode-}" ]; then
postPhases+=" pythonRecompileBytecodePhase" appendToVar postPhases pythonRecompileBytecodePhase
fi fi

View File

@ -13,5 +13,5 @@ pythonRemoveBinBytecodePhase () {
} }
if [ -z "${dontUsePythonRemoveBinBytecode-}" ]; then if [ -z "${dontUsePythonRemoveBinBytecode-}" ]; then
preDistPhases+=" pythonRemoveBinBytecodePhase" appendToVar preDistPhases pythonRemoveBinBytecodePhase
fi fi

View File

@ -16,5 +16,5 @@ pythonRuntimeDepsCheckHook() {
if [ -z "${dontCheckRuntimeDeps-}" ]; then if [ -z "${dontCheckRuntimeDeps-}" ]; then
echo "Using pythonRuntimeDepsCheckHook" echo "Using pythonRuntimeDepsCheckHook"
preInstallPhases+=" pythonRuntimeDepsCheckHook" appendToVar preInstallPhases pythonRuntimeDepsCheckHook
fi fi

View File

@ -69,4 +69,4 @@ installSphinxPhase() {
runHook postInstallSphinx runHook postInstallSphinx
} }
preDistPhases+=" buildSphinxPhase installSphinxPhase" appendToVar preDistPhases buildSphinxPhase installSphinxPhase

View File

@ -13,5 +13,5 @@ unittestCheckPhase() {
if [ -z "${dontUseUnittestCheck-}" ] && [ -z "${installCheckPhase-}" ]; then if [ -z "${dontUseUnittestCheck-}" ] && [ -z "${installCheckPhase-}" ]; then
echo "Using unittestCheckPhase" echo "Using unittestCheckPhase"
preDistPhases+=" unittestCheckPhase" appendToVar preDistPhases unittestCheckPhase
fi fi

View File

@ -12,7 +12,7 @@ addEnvHooks "$targetOffset" make_glib_find_gsettings_schemas
glibPreInstallPhase() { glibPreInstallPhase() {
makeFlagsArray+=("gsettingsschemadir=${!outputLib}/share/gsettings-schemas/$name/glib-2.0/schemas/") makeFlagsArray+=("gsettingsschemadir=${!outputLib}/share/gsettings-schemas/$name/glib-2.0/schemas/")
} }
preInstallPhases+=" glibPreInstallPhase" appendToVar preInstallPhases glibPreInstallPhase
glibPreFixupPhase() { glibPreFixupPhase() {
# Move gschemas in case the install flag didn't help # Move gschemas in case the install flag didn't help

View File

@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
sourceRoot = "liquidfun/Box2D"; sourceRoot = "liquidfun/Box2D";
preConfigurePhases = "preConfigure"; preConfigurePhases = [ "preConfigure" ];
preConfigure = '' preConfigure = ''
sed -i Box2D/Common/b2Settings.h -e 's@b2_maxPolygonVertices .*@b2_maxPolygonVertices 15@' sed -i Box2D/Common/b2Settings.h -e 's@b2_maxPolygonVertices .*@b2_maxPolygonVertices 15@'

View File

@ -20,7 +20,7 @@ qmakePrePhase() {
# do the stripping ourselves (needed for separateDebugInfo) # do the stripping ourselves (needed for separateDebugInfo)
prependToVar qmakeFlags "CONFIG+=nostrip" prependToVar qmakeFlags "CONFIG+=nostrip"
} }
prePhases+=" qmakePrePhase" appendToVar prePhases qmakePrePhase
qmakeConfigurePhase() { qmakeConfigurePhase() {
runHook preConfigure runHook preConfigure

View File

@ -97,7 +97,7 @@ postPatchMkspecs() {
fi fi
} }
if [ -z "${dontPatchMkspecs-}" ]; then if [ -z "${dontPatchMkspecs-}" ]; then
postPhases="${postPhases-}${postPhases:+ }postPatchMkspecs" appendToVar postPhases postPatchMkspecs
fi fi
qtPreHook() { qtPreHook() {
@ -107,6 +107,6 @@ qtPreHook() {
exit 1 exit 1
fi fi
} }
prePhases+=" qtPreHook" appendToVar prePhases qtPreHook
fi fi

View File

@ -13,7 +13,7 @@ qmakePrePhase() {
"NIX_OUTPUT_QML=${!outputBin}/${qtQmlPrefix:?}" \ "NIX_OUTPUT_QML=${!outputBin}/${qtQmlPrefix:?}" \
"NIX_OUTPUT_PLUGIN=${!outputBin}/${qtPluginPrefix:?}" "NIX_OUTPUT_PLUGIN=${!outputBin}/${qtPluginPrefix:?}"
} }
prePhases+=" qmakePrePhase" appendToVar prePhases qmakePrePhase
qmakeConfigurePhase() { qmakeConfigurePhase() {
runHook preConfigure runHook preConfigure

View File

@ -71,7 +71,7 @@ else # Only set up Qt once.
fi fi
} }
if [ -z "${dontPatchMkspecs-}" ]; then if [ -z "${dontPatchMkspecs-}" ]; then
postPhases="${postPhases-}${postPhases:+ }postPatchMkspecs" appendToVar postPhases postPatchMkspecs
fi fi
qtPreHook() { qtPreHook() {
@ -81,7 +81,7 @@ else # Only set up Qt once.
exit 1 exit 1
fi fi
} }
prePhases+=" qtPreHook" appendToVar prePhases qtPreHook
addQtModulePrefix() { addQtModulePrefix() {
addToSearchPath QT_ADDITIONAL_PACKAGES_PREFIX_PATH $1 addToSearchPath QT_ADDITIONAL_PACKAGES_PREFIX_PATH $1

View File

@ -16,10 +16,17 @@ pytestForkedHook() {
# until we have dependency mechanism in generic builder, we need to use this ugly hack. # until we have dependency mechanism in generic builder, we need to use this ugly hack.
if [ -z "${dontUsePytestForked-}" ] && [ -z "${dontUsePytestCheck-}" ]; then if [ -z "${dontUsePytestForked-}" ] && [ -z "${dontUsePytestCheck-}" ]; then
if [[ " ${preDistPhases:-} " =~ " pytestCheckPhase " ]]; then if [[ " ${preDistPhases[*]:-} " =~ " pytestCheckPhase " ]]; then
preDistPhases+=" " _preDistPhases="${preDistPhases[*]} "
preDistPhases="${preDistPhases/ pytestCheckPhase / pytestForkedHook pytestCheckPhase }" _preDistPhases="${_preDistPhases/ pytestCheckPhase / pytestForkedHook pytestCheckPhase }"
if [[ -n "${__structuredAttrs-}" ]]; then
preDistPhases=()
else else
preDistPhases+=" pytestForkedHook" preDistPhases=""
fi
appendToVar preDistPhases $_preDistPhases
unset _preDistPhases
else
appendToVar preDistPhases pytestForkedHook
fi fi
fi fi

View File

@ -8,10 +8,17 @@ pytestXdistHook() {
# until we have dependency mechanism in generic builder, we need to use this ugly hack. # until we have dependency mechanism in generic builder, we need to use this ugly hack.
if [ -z "${dontUsePytestXdist-}" ] && [ -z "${dontUsePytestCheck-}" ]; then if [ -z "${dontUsePytestXdist-}" ] && [ -z "${dontUsePytestCheck-}" ]; then
if [[ " ${preDistPhases:-} " =~ " pytestCheckPhase " ]]; then if [[ " ${preDistPhases[*]:-} " =~ " pytestCheckPhase " ]]; then
preDistPhases+=" " _preDistPhases="${preDistPhases[*]} "
preDistPhases="${preDistPhases/ pytestCheckPhase / pytestXdistHook pytestCheckPhase }" _preDistPhases="${_preDistPhases/ pytestCheckPhase / pytestXdistHook pytestCheckPhase }"
if [[ -n "${__structuredAttrs-}" ]]; then
preDistPhases=()
else else
preDistPhases+=" pytestXdistHook" preDistPhases=""
fi
appendToVar preDistPhases $_preDistPhases
unset _preDistPhases
else
appendToVar preDistPhases pytestXdistHook
fi fi
fi fi

View File

@ -87,7 +87,7 @@ let
pytestcachePhase() { pytestcachePhase() {
find $out -name .pytest_cache -type d -exec rm -rf {} + 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. # pytest generates it's own bytecode files to improve assertion messages.
# These files similar to cpython's bytecode files but are never laoded # 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 # https://github.com/pytest-dev/pytest/blob/7.2.1/src/_pytest/assertion/rewrite.py#L51-L53
find $out -name "*-pytest-*.py[co]" -delete find $out -name "*-pytest-*.py[co]" -delete
} }
preDistPhases+=" pytestRemoveBytecodePhase" appendToVar preDistPhases pytestRemoveBytecodePhase
''; '';
pythonImportsCheck = [ "pytest" ]; pythonImportsCheck = [ "pytest" ];

View File

@ -84,7 +84,7 @@ buildPythonPackage rec {
pytestcachePhase() { pytestcachePhase() {
find $out -name .pytest_cache -type d -exec rm -rf {} + 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. # pytest generates it's own bytecode files to improve assertion messages.
# These files similar to cpython's bytecode files but are never laoded # 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 # https://github.com/pytest-dev/pytest/blob/7.2.1/src/_pytest/assertion/rewrite.py#L51-L53
find $out -name "*-pytest-*.py[co]" -delete find $out -name "*-pytest-*.py[co]" -delete
} }
preDistPhases+=" pytestRemoveBytecodePhase" appendToVar preDistPhases pytestRemoveBytecodePhase
''; '';
pythonImportsCheck = [ "pytest" ]; pythonImportsCheck = [ "pytest" ];

View File

@ -42,7 +42,7 @@ buildPythonPackage rec {
find $out -name .pytest_cache -type d -exec rm -rf {} + 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. # pytest generates it's own bytecode files to improve assertion messages.
# These files similar to cpython's bytecode files but are never laoded # 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 # https://github.com/pytest-dev/pytest/blob/4.6.11/src/_pytest/assertion/rewrite.py#L32-L47
find $out -name "*-PYTEST.py[co]" -delete find $out -name "*-PYTEST.py[co]" -delete
} }
preDistPhases+=" pytestRemoveBytecodePhase" appendToVar preDistPhases pytestRemoveBytecodePhase
''; '';
meta = with lib; { meta = with lib; {

View File

@ -21,5 +21,5 @@ function manifestCheckPhase() {
if [ -z "${dontCheckManifest-}" ] && [ -z "${installCheckPhase-}" ]; then if [ -z "${dontCheckManifest-}" ] && [ -z "${installCheckPhase-}" ]; then
echo "Using manifestCheckPhase" echo "Using manifestCheckPhase"
preDistPhases+=" manifestCheckPhase" appendToVar preDistPhases manifestCheckPhase
fi fi