bmake: refactor setup-hook.sh

- shellcheck it
- move function definitions to the top of file
This commit is contained in:
Anderson Torres
2023-07-26 21:50:56 -03:00
parent aef415998b
commit 14d3808d2b
@@ -1,3 +1,5 @@
# shellcheck shell=bash disable=SC2086,SC2154,SC2206
addMakeFlags() {
export prefix="$out"
export MANDIR="${!outputMan}/share/man"
@@ -6,48 +8,40 @@ addMakeFlags() {
export STRIP_FLAG=
}
preConfigureHooks+=(addMakeFlags)
bmakeBuildPhase() {
runHook preBuild
local flagsArray=(
${enableParallelBuilding:+-j${NIX_BUILD_CORES}}
SHELL=$SHELL
SHELL="$SHELL"
$makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
$buildFlags ${buildFlagsArray+"${buildFlagsArray[@]}"}
)
echoCmd 'build flags' "${flagsArray[@]}"
bmake ${makefile:+-f $makefile} "${flagsArray[@]}"
unset flagsArray
runHook postBuild
}
if [ -z "${dontUseBmakeBuild-}" -a -z "${buildPhase-}" ]; then
buildPhase=bmakeBuildPhase
fi
bmakeCheckPhase() {
runHook preCheck
if [ -z "${checkTarget:-}" ]; then
#TODO(@oxij): should flagsArray influence make -n?
if bmake -n ${makefile:+-f $makefile} check >/dev/null 2>&1; then
checkTarget=check
checkTarget="check"
elif bmake -n ${makefile:+-f $makefile} test >/dev/null 2>&1; then
checkTarget=test
checkTarget="test"
fi
fi
if [ -z "${checkTarget:-}" ]; then
echo "no test target found in bmake, doing nothing"
else
# shellcheck disable=SC2086
local flagsArray=(
${enableParallelChecking:+-j${NIX_BUILD_CORES}}
SHELL=$SHELL
SHELL="$SHELL"
# Old bash empty array hack
$makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
${checkFlags:-VERBOSE=y} ${checkFlagsArray+"${checkFlagsArray[@]}"}
@@ -56,17 +50,11 @@ bmakeCheckPhase() {
echoCmd 'check flags' "${flagsArray[@]}"
bmake ${makefile:+-f $makefile} "${flagsArray[@]}"
unset flagsArray
fi
runHook postCheck
}
if [ -z "${dontUseBmakeCheck-}" -a -z "${checkPhase-}" ]; then
checkPhase=bmakeCheckPhase
fi
bmakeInstallPhase() {
runHook preInstall
@@ -74,10 +62,9 @@ bmakeInstallPhase() {
mkdir -p "$prefix"
fi
# shellcheck disable=SC2086
local flagsArray=(
${enableParallelInstalling:+-j${NIX_BUILD_CORES}}
SHELL=$SHELL
SHELL="$SHELL"
# Old bash empty array hack
$makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
$installFlags ${installFlagsArray+"${installFlagsArray[@]}"}
@@ -86,15 +73,10 @@ bmakeInstallPhase() {
echoCmd 'install flags' "${flagsArray[@]}"
bmake ${makefile:+-f $makefile} "${flagsArray[@]}"
unset flagsArray
runHook postInstall
}
if [ -z "${dontUseBmakeInstall-}" -a -z "${installPhase-}" ]; then
installPhase=bmakeInstallPhase
fi
bmakeDistPhase() {
runHook preDist
@@ -103,7 +85,6 @@ bmakeDistPhase() {
fi
# Old bash empty array hack
# shellcheck disable=SC2086
local flagsArray=(
$distFlags ${distFlagsArray+"${distFlagsArray[@]}"} ${distTarget:-dist}
)
@@ -116,13 +97,26 @@ bmakeDistPhase() {
# Note: don't quote $tarballs, since we explicitly permit
# wildcards in there.
# shellcheck disable=SC2086
cp -pvd ${tarballs:-*.tar.gz} "$out/tarballs"
fi
runHook postDist
}
if [ -z "${dontUseBmakeDist-}" -a -z "${distPhase-}" ]; then
preConfigureHooks+=(addMakeFlags)
if [ -z "${dontUseBmakeBuild-}" ] && [ -z "${buildPhase-}" ]; then
buildPhase=bmakeBuildPhase
fi
if [ -z "${dontUseBmakeCheck-}" ] && [ -z "${checkPhase-}" ]; then
checkPhase=bmakeCheckPhase
fi
if [ -z "${dontUseBmakeInstall-}" ] && [ -z "${installPhase-}" ]; then
installPhase=bmakeInstallPhase
fi
if [ -z "${dontUseBmakeDist-}" ] && [ -z "${distPhase-}" ]; then
distPhase=bmakeDistPhase
fi