buildDotnetModule: minor changes to hooks

Abide by `set -e` rules and use `local -r` where applicable.

Changed files
+28 -23
pkgs
+6 -6
pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh
···
runHook preBuild
if [ "${enableParallelBuilding-}" ]; then
-
maxCpuFlag="$NIX_BUILD_CORES"
-
parallelBuildFlag="true"
+
local -r maxCpuFlag="$NIX_BUILD_CORES"
+
local -r parallelBuildFlag="true"
else
-
maxCpuFlag="1"
-
parallelBuildFlag="false"
+
local -r maxCpuFlag="1"
+
local -r parallelBuildFlag="false"
fi
if [ "${selfContainedBuild-}" ]; then
···
fi
if [ "${version-}" ]; then
-
versionFlag="-p:Version=${version-}"
+
local -r versionFlag="-p:Version=${version-}"
fi
-
for project in ${projectFile[@]} ${testProjectFile[@]}; do
+
for project in ${projectFile[@]} ${testProjectFile[@]-}; do
env \
dotnet build "$project" \
-maxcpucount:$maxCpuFlag \
+8 -2
pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh
···
runHook preCheck
if [ "${disabledTests-}" ]; then
-
disabledTestsFlag="--filter FullyQualifiedName!=@disabledTests@"
+
local -r disabledTestsFlag="--filter FullyQualifiedName!=@disabledTests@"
fi
-
for project in ${testProjectFile[@]}; do
+
if [ "${enableParallelBuilding-}" ]; then
+
local -r maxCpuFlag="$NIX_BUILD_CORES"
+
else
+
local -r maxCpuFlag="1"
+
fi
+
+
for project in ${testProjectFile[@]-}; do
env "LD_LIBRARY_PATH=@libraryPath@" \
dotnet test "$project" \
-maxcpucount:$maxCpuFlag \
+2 -2
pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh
···
runHook preConfigure
if [ -z "${enableParallelBuilding-}" ]; then
-
parallelFlag="--disable-parallel"
+
local -r parallelFlag="--disable-parallel"
fi
-
for project in ${projectFile[@]} ${testProjectFile[@]}; do
+
for project in ${projectFile[@]} ${testProjectFile[@]-}; do
env \
dotnet restore "$project" \
-p:ContinuousIntegrationBuild=true \
+12 -13
pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh
···
# the second is the destination for the wrapper.
wrapDotnetProgram() {
if [ ! "${selfContainedBuild-}" ]; then
-
dotnetRootFlag=("--set" "DOTNET_ROOT" "@dotnetRuntime@")
+
local -r dotnetRootFlag=("--set" "DOTNET_ROOT" "@dotnetRuntime@")
fi
makeWrapper "$1" "$2" \
-
"${dotnetRootFlag[@]}" \
--suffix "LD_LIBRARY_PATH" : "@runtimeDeps@" \
+
"${dotnetRootFlag[@]}" \
"${gappsWrapperArgs[@]}" \
"${makeWrapperArgs[@]}"
-
echo "Installed wrapper to: "$2""
+
echo "installed wrapper to "$2""
}
dotnetFixupHook() {
echo "Executing dotnetFixupPhase"
-
if [ "${executables}" ]; then
+
if [ "${executables-}" ]; then
for executable in ${executables[@]}; do
-
execPath="$out/lib/${pname}/$executable"
+
path="$out/lib/$pname/$executable"
-
if [[ -f "$execPath" && -x "$execPath" ]]; then
-
wrapDotnetProgram "$execPath" "$out/bin/$(basename "$executable")"
+
if test -x "$path"; then
+
wrapDotnetProgram "$path" "$out/bin/$(basename "$executable")"
else
-
echo "Specified binary \"$executable\" is either not an executable, or does not exist!"
+
echo "Specified binary \"$executable\" is either not an executable or does not exist!"
+
echo "Looked in $path"
exit 1
fi
done
else
-
for executable in $out/lib/${pname}/*; do
-
if [[ -f "$executable" && -x "$executable" && "$executable" != *"dll"* ]]; then
-
wrapDotnetProgram "$executable" "$out/bin/$(basename "$executable")"
-
fi
-
done
+
while IFS= read -d '' executable; do
+
wrapDotnetProgram "$executable" "$out/bin/$(basename "$executable")" \;
+
done < <(find "$out/lib/$pname" ! -name "*.dll" -executable -type f -print0)
fi
echo "Finished dotnetFixupPhase"