buildDotnetModule: combine hooks (#420536)
This commit is contained in:
commit
f314020926
@ -98,13 +98,7 @@ let
|
||||
else
|
||||
dotnet-sdk.meta.platforms;
|
||||
|
||||
inherit (callPackage ./hooks { inherit dotnet-sdk dotnet-runtime; })
|
||||
dotnetConfigureHook
|
||||
dotnetBuildHook
|
||||
dotnetCheckHook
|
||||
dotnetInstallHook
|
||||
dotnetFixupHook
|
||||
;
|
||||
hook = callPackage ./hook { inherit dotnet-runtime; };
|
||||
|
||||
inherit (dotnetCorePackages) systemToDotnetRid;
|
||||
in
|
||||
@ -140,11 +134,7 @@ let
|
||||
;
|
||||
|
||||
nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [
|
||||
dotnetConfigureHook
|
||||
dotnetBuildHook
|
||||
dotnetCheckHook
|
||||
dotnetInstallHook
|
||||
dotnetFixupHook
|
||||
hook
|
||||
|
||||
cacert
|
||||
makeWrapper
|
||||
|
@ -0,0 +1,18 @@
|
||||
{
|
||||
lib,
|
||||
which,
|
||||
coreutils,
|
||||
makeSetupHook,
|
||||
# Passed from ../default.nix
|
||||
dotnet-runtime,
|
||||
}:
|
||||
makeSetupHook {
|
||||
name = "dotnet-hook";
|
||||
substitutions = {
|
||||
dotnetRuntime = dotnet-runtime;
|
||||
wrapperPath = lib.makeBinPath [
|
||||
which
|
||||
coreutils
|
||||
];
|
||||
};
|
||||
} ./dotnet-hook.sh
|
@ -0,0 +1,426 @@
|
||||
# shellcheck shell=bash
|
||||
|
||||
dotnetConfigurePhase() {
|
||||
echo "Executing dotnetConfigureHook"
|
||||
|
||||
runHook preConfigure
|
||||
|
||||
local -a projectFiles flags runtimeIds
|
||||
concatTo projectFiles dotnetProjectFiles dotnetTestProjectFiles
|
||||
concatTo flags dotnetFlags dotnetRestoreFlags
|
||||
concatTo runtimeIds dotnetRuntimeIds
|
||||
|
||||
if [[ -z ${enableParallelBuilding-} ]]; then
|
||||
flags+=(--disable-parallel)
|
||||
fi
|
||||
|
||||
if [[ -v dotnetSelfContainedBuild ]]; then
|
||||
if [[ -n $dotnetSelfContainedBuild ]]; then
|
||||
flags+=("-p:SelfContained=true")
|
||||
else
|
||||
flags+=("-p:SelfContained=false")
|
||||
fi
|
||||
fi
|
||||
|
||||
dotnetRestore() {
|
||||
local -r projectFile="${1-}"
|
||||
for runtimeId in "${runtimeIds[@]}"; do
|
||||
dotnet restore ${1+"$projectFile"} \
|
||||
-p:ContinuousIntegrationBuild=true \
|
||||
-p:Deterministic=true \
|
||||
-p:NuGetAudit=false \
|
||||
--runtime "$runtimeId" \
|
||||
"${flags[@]}"
|
||||
done
|
||||
}
|
||||
|
||||
if [[ -f .config/dotnet-tools.json || -f dotnet-tools.json ]]; then
|
||||
dotnet tool restore
|
||||
fi
|
||||
|
||||
# dotnetGlobalTool is set in buildDotnetGlobalTool to patch dependencies but
|
||||
# avoid other project-specific logic. This is a hack, but the old behavior
|
||||
# is worse as it relied on a bug: setting projectFile to an empty string
|
||||
# made the hooks actually skip all project-specific logic. It’s hard to keep
|
||||
# backwards compatibility with this odd behavior now since we are using
|
||||
# arrays, so instead we just pass a variable to indicate that we don’t have
|
||||
# projects.
|
||||
if [[ -z ${dotnetGlobalTool-} ]]; then
|
||||
if (( ${#projectFiles[@]} == 0 )); then
|
||||
dotnetRestore
|
||||
fi
|
||||
|
||||
local projectFile
|
||||
for projectFile in "${projectFiles[@]}"; do
|
||||
dotnetRestore "$projectFile"
|
||||
done
|
||||
fi
|
||||
|
||||
runHook postConfigure
|
||||
|
||||
echo "Finished dotnetConfigureHook"
|
||||
}
|
||||
|
||||
if [[ -z "${dontDotnetConfigure-}" && -z "${configurePhase-}" ]]; then
|
||||
configurePhase=dotnetConfigurePhase
|
||||
fi
|
||||
|
||||
dotnetBuildPhase() {
|
||||
echo "Executing dotnetBuildHook"
|
||||
|
||||
runHook preBuild
|
||||
|
||||
local -r dotnetBuildType="${dotnetBuildType-Release}"
|
||||
|
||||
local -a projectFiles flags runtimeIds
|
||||
concatTo projectFiles dotnetProjectFiles dotnetTestProjectFiles
|
||||
concatTo flags dotnetFlags dotnetBuildFlags
|
||||
concatTo runtimeIds dotnetRuntimeIds
|
||||
|
||||
if [[ -n "${enableParallelBuilding-}" ]]; then
|
||||
local -r maxCpuFlag="$NIX_BUILD_CORES"
|
||||
local -r parallelBuildFlag="true"
|
||||
else
|
||||
local -r maxCpuFlag="1"
|
||||
local -r parallelBuildFlag="false"
|
||||
fi
|
||||
|
||||
if [[ -v dotnetSelfContainedBuild ]]; then
|
||||
if [[ -n $dotnetSelfContainedBuild ]]; then
|
||||
flags+=("-p:SelfContained=true")
|
||||
else
|
||||
flags+=("-p:SelfContained=false")
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n ${dotnetUseAppHost-} ]]; then
|
||||
flags+=("-p:UseAppHost=true")
|
||||
fi
|
||||
|
||||
if [[ -n ${version-} ]]; then
|
||||
flags+=("-p:InformationalVersion=$version")
|
||||
fi
|
||||
|
||||
if [[ -n ${versionForDotnet-} ]]; then
|
||||
flags+=("-p:Version=$versionForDotnet")
|
||||
fi
|
||||
|
||||
dotnetBuild() {
|
||||
local -r projectFile="${1-}"
|
||||
|
||||
for runtimeId in "${runtimeIds[@]}"; do
|
||||
local runtimeIdFlags=()
|
||||
if [[ $projectFile == *.csproj || -n ${dotnetSelfContainedBuild-} ]]; then
|
||||
runtimeIdFlags+=("--runtime" "$runtimeId")
|
||||
fi
|
||||
|
||||
dotnet build ${1+"$projectFile"} \
|
||||
-maxcpucount:"$maxCpuFlag" \
|
||||
-p:BuildInParallel="$parallelBuildFlag" \
|
||||
-p:ContinuousIntegrationBuild=true \
|
||||
-p:Deterministic=true \
|
||||
-p:OverwriteReadOnlyFiles=true \
|
||||
--configuration "$dotnetBuildType" \
|
||||
--no-restore \
|
||||
"${runtimeIdFlags[@]}" \
|
||||
"${flags[@]}"
|
||||
done
|
||||
}
|
||||
|
||||
if (( ${#projectFiles[@]} == 0 )); then
|
||||
dotnetBuild
|
||||
fi
|
||||
|
||||
local projectFile
|
||||
for projectFile in "${projectFiles[@]}"; do
|
||||
dotnetBuild "$projectFile"
|
||||
done
|
||||
|
||||
runHook postBuild
|
||||
|
||||
echo "Finished dotnetBuildHook"
|
||||
}
|
||||
|
||||
if [[ -z ${dontDotnetBuild-} && -z ${buildPhase-} ]]; then
|
||||
buildPhase=dotnetBuildPhase
|
||||
fi
|
||||
|
||||
dotnetCheckPhase() {
|
||||
echo "Executing dotnetCheckHook"
|
||||
|
||||
runHook preCheck
|
||||
|
||||
local -r dotnetBuildType="${dotnetBuildType-Release}"
|
||||
|
||||
local -a projectFiles testProjectFiles testFilters disabledTests flags runtimeIds runtimeDeps
|
||||
concatTo projectFiles dotnetProjectFiles
|
||||
concatTo testProjectFiles dotnetTestProjectFiles
|
||||
concatTo testFilters dotnetTestFilters
|
||||
concatTo disabledTests dotnetDisabledTests
|
||||
concatTo flags dotnetFlags dotnetTestFlags
|
||||
concatTo runtimeIds dotnetRuntimeIds
|
||||
concatTo runtimeDeps dotnetRuntimeDeps
|
||||
|
||||
if (( ${#disabledTests[@]} > 0 )); then
|
||||
local disabledTestsFilters=("${disabledTests[@]/#/FullyQualifiedName!=}")
|
||||
testFilters=( "${testFilters[@]}" "${disabledTestsFilters[@]//,/%2C}" )
|
||||
fi
|
||||
|
||||
if (( ${#testFilters[@]} > 0 )); then
|
||||
local OLDIFS="$IFS" IFS='&'
|
||||
flags+=("--filter:${testFilters[*]}")
|
||||
IFS="$OLDIFS"
|
||||
fi
|
||||
|
||||
local libraryPath="${LD_LIBRARY_PATH-}"
|
||||
if (( ${#runtimeDeps[@]} > 0 )); then
|
||||
local libraryPaths=("${runtimeDeps[@]/%//lib}")
|
||||
local OLDIFS="$IFS" IFS=':'
|
||||
libraryPath="${libraryPaths[*]}${libraryPath:+':'}$libraryPath"
|
||||
IFS="$OLDIFS"
|
||||
fi
|
||||
|
||||
if [[ -n ${enableParallelBuilding-} ]]; then
|
||||
local -r maxCpuFlag="$NIX_BUILD_CORES"
|
||||
else
|
||||
local -r maxCpuFlag="1"
|
||||
fi
|
||||
|
||||
local projectFile runtimeId
|
||||
for projectFile in "${testProjectFiles[@]-${projectFiles[@]}}"; do
|
||||
for runtimeId in "${runtimeIds[@]}"; do
|
||||
local runtimeIdFlags=()
|
||||
if [[ $projectFile == *.csproj ]]; then
|
||||
runtimeIdFlags=("--runtime" "$runtimeId")
|
||||
fi
|
||||
|
||||
LD_LIBRARY_PATH=$libraryPath \
|
||||
dotnet test "$projectFile" \
|
||||
-maxcpucount:"$maxCpuFlag" \
|
||||
-p:ContinuousIntegrationBuild=true \
|
||||
-p:Deterministic=true \
|
||||
--configuration "$dotnetBuildType" \
|
||||
--no-restore \
|
||||
--no-build \
|
||||
--logger "console;verbosity=normal" \
|
||||
"${runtimeIdFlags[@]}" \
|
||||
"${flags[@]}"
|
||||
done
|
||||
done
|
||||
|
||||
runHook postCheck
|
||||
|
||||
echo "Finished dotnetCheckHook"
|
||||
}
|
||||
|
||||
if [[ -z "${dontDotnetCheck-}" && -z "${checkPhase-}" ]]; then
|
||||
checkPhase=dotnetCheckPhase
|
||||
fi
|
||||
|
||||
# For compatibility, convert makeWrapperArgs to an array unless we are using
|
||||
# structured attributes. That is, we ensure that makeWrapperArgs is always an
|
||||
# array.
|
||||
# See https://github.com/NixOS/nixpkgs/blob/858f4db3048c5be3527e183470e93c1a72c5727c/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh#L1-L3
|
||||
# and https://github.com/NixOS/nixpkgs/pull/313005#issuecomment-2175482920
|
||||
# shellcheck disable=2206
|
||||
if [[ -z $__structuredAttrs ]]; then
|
||||
makeWrapperArgs=( ${makeWrapperArgs-} )
|
||||
fi
|
||||
|
||||
# First argument is the executable you want to wrap,
|
||||
# the second is the destination for the wrapper.
|
||||
wrapDotnetProgram() {
|
||||
local -r dotnetRuntime=@dotnetRuntime@
|
||||
local -r wrapperPath=@wrapperPath@
|
||||
|
||||
# shellcheck disable=2016
|
||||
local -r dotnetFromEnvScript='dotnetFromEnv() {
|
||||
local dotnetPath
|
||||
if command -v dotnet 2>&1 >/dev/null; then
|
||||
dotnetPath=$(which dotnet) && \
|
||||
dotnetPath=$(realpath "$dotnetPath") && \
|
||||
dotnetPath=$(dirname "$dotnetPath") && \
|
||||
export DOTNET_ROOT="$dotnetPath"
|
||||
fi
|
||||
}
|
||||
dotnetFromEnv'
|
||||
|
||||
# shellcheck disable=2206
|
||||
local -a runtimeDeps
|
||||
concatTo runtimeDeps dotnetRuntimeDeps
|
||||
|
||||
local wrapperFlags=()
|
||||
if (( ${#runtimeDeps[@]} > 0 )); then
|
||||
local libraryPath=("${dotnetRuntimeDeps[@]/%//lib}")
|
||||
local OLDIFS="$IFS" IFS=':'
|
||||
wrapperFlags+=("--suffix" "LD_LIBRARY_PATH" ":" "${libraryPath[*]}")
|
||||
IFS="$OLDIFS"
|
||||
fi
|
||||
|
||||
if [[ -z ${dotnetSelfContainedBuild-} ]]; then
|
||||
if [[ -n ${useDotnetFromEnv-} ]]; then
|
||||
# if dotnet CLI is available, set DOTNET_ROOT based on it. Otherwise set to default .NET runtime
|
||||
wrapperFlags+=("--suffix" "PATH" ":" "$wrapperPath")
|
||||
wrapperFlags+=("--run" "$dotnetFromEnvScript")
|
||||
if [[ -n $dotnetRuntime ]]; then
|
||||
wrapperFlags+=("--set-default" "DOTNET_ROOT" "$dotnetRuntime/share/dotnet")
|
||||
wrapperFlags+=("--suffix" "PATH" ":" "$dotnetRuntime/bin")
|
||||
fi
|
||||
elif [[ -n $dotnetRuntime ]]; then
|
||||
wrapperFlags+=("--set" "DOTNET_ROOT" "$dotnetRuntime/share/dotnet")
|
||||
wrapperFlags+=("--prefix" "PATH" ":" "$dotnetRuntime/bin")
|
||||
fi
|
||||
fi
|
||||
|
||||
# shellcheck disable=2154
|
||||
makeWrapper "$1" "$2" \
|
||||
"${wrapperFlags[@]}" \
|
||||
"${gappsWrapperArgs[@]}" \
|
||||
"${makeWrapperArgs[@]}"
|
||||
|
||||
echo "installed wrapper to $2"
|
||||
}
|
||||
|
||||
dotnetFixupPhase() {
|
||||
local -r dotnetInstallPath="${dotnetInstallPath-$out/lib/$pname}"
|
||||
|
||||
local executable executableBasename
|
||||
|
||||
# check if dotnetExecutables is declared (including empty values, in which case we generate no executables)
|
||||
# shellcheck disable=2154
|
||||
if declare -p dotnetExecutables &>/dev/null; then
|
||||
# shellcheck disable=2206
|
||||
local -a executables
|
||||
concatTo executables dotnetExecutables
|
||||
for executable in "${executables[@]}"; do
|
||||
executableBasename=$(basename "$executable")
|
||||
|
||||
local path="$dotnetInstallPath/$executable"
|
||||
|
||||
if test -x "$path"; then
|
||||
wrapDotnetProgram "$path" "$out/bin/$executableBasename"
|
||||
else
|
||||
echo "Specified binary \"$executable\" is either not an executable or does not exist!"
|
||||
echo "Looked in $path"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
else
|
||||
while IFS= read -r -d '' executable; do
|
||||
executableBasename=$(basename "$executable")
|
||||
wrapDotnetProgram "$executable" "$out/bin/$executableBasename" \;
|
||||
done < <(find "$dotnetInstallPath" ! -name "*.dll" -executable -type f -print0)
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ -z "${dontFixup-}" && -z "${dontDotnetFixup-}" ]]; then
|
||||
appendToVar preFixupPhases dotnetFixupPhase
|
||||
fi
|
||||
|
||||
dotnetInstallPhase() {
|
||||
echo "Executing dotnetInstallHook"
|
||||
|
||||
runHook preInstall
|
||||
|
||||
local -r dotnetInstallPath="${dotnetInstallPath-$out/lib/$pname}"
|
||||
local -r dotnetBuildType="${dotnetBuildType-Release}"
|
||||
|
||||
local -a projectFiles flags installFlags packFlags runtimeIds
|
||||
concatTo projectFiles dotnetProjectFiles
|
||||
concatTo flags dotnetFlags
|
||||
concatTo installFlags dotnetInstallFlags
|
||||
concatTo packFlags dotnetPackFlags
|
||||
concatTo runtimeIds dotnetRuntimeIds
|
||||
|
||||
if [[ -v dotnetSelfContainedBuild ]]; then
|
||||
if [[ -n $dotnetSelfContainedBuild ]]; then
|
||||
installFlags+=("--self-contained")
|
||||
else
|
||||
installFlags+=("--no-self-contained")
|
||||
# https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained
|
||||
# Trimming is only available for self-contained build, so force disable it here
|
||||
installFlags+=("-p:PublishTrimmed=false")
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n ${dotnetUseAppHost-} ]]; then
|
||||
installFlags+=("-p:UseAppHost=true")
|
||||
fi
|
||||
|
||||
if [[ -n ${enableParallelBuilding-} ]]; then
|
||||
local -r maxCpuFlag="$NIX_BUILD_CORES"
|
||||
else
|
||||
local -r maxCpuFlag="1"
|
||||
fi
|
||||
|
||||
dotnetPublish() {
|
||||
local -r projectFile="${1-}"
|
||||
|
||||
for runtimeId in "${runtimeIds[@]}"; do
|
||||
runtimeIdFlags=()
|
||||
if [[ $projectFile == *.csproj || -n ${dotnetSelfContainedBuild-} ]]; then
|
||||
runtimeIdFlags+=("--runtime" "$runtimeId")
|
||||
fi
|
||||
|
||||
dotnet publish ${1+"$projectFile"} \
|
||||
-maxcpucount:"$maxCpuFlag" \
|
||||
-p:ContinuousIntegrationBuild=true \
|
||||
-p:Deterministic=true \
|
||||
-p:OverwriteReadOnlyFiles=true \
|
||||
--output "$dotnetInstallPath" \
|
||||
--configuration "$dotnetBuildType" \
|
||||
--no-restore \
|
||||
--no-build \
|
||||
"${runtimeIdFlags[@]}" \
|
||||
"${flags[@]}" \
|
||||
"${installFlags[@]}"
|
||||
done
|
||||
}
|
||||
|
||||
dotnetPack() {
|
||||
local -r projectFile="${1-}"
|
||||
|
||||
for runtimeId in "${runtimeIds[@]}"; do
|
||||
dotnet pack ${1+"$projectFile"} \
|
||||
-maxcpucount:"$maxCpuFlag" \
|
||||
-p:ContinuousIntegrationBuild=true \
|
||||
-p:Deterministic=true \
|
||||
-p:OverwriteReadOnlyFiles=true \
|
||||
--output "$out/share/nuget/source" \
|
||||
--configuration "$dotnetBuildType" \
|
||||
--no-restore \
|
||||
--no-build \
|
||||
--runtime "$runtimeId" \
|
||||
"${flags[@]}" \
|
||||
"${packFlags[@]}"
|
||||
done
|
||||
}
|
||||
|
||||
if (( ${#projectFiles[@]} == 0 )); then
|
||||
dotnetPublish
|
||||
else
|
||||
local projectFile
|
||||
for projectFile in "${projectFiles[@]}"; do
|
||||
dotnetPublish "$projectFile"
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ -n ${packNupkg-} ]]; then
|
||||
if (( ${#projectFiles[@]} == 0 )); then
|
||||
dotnetPack
|
||||
else
|
||||
local projectFile
|
||||
for projectFile in "${projectFiles[@]}"; do
|
||||
dotnetPack "$projectFile"
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
runHook postInstall
|
||||
|
||||
echo "Finished dotnetInstallHook"
|
||||
}
|
||||
|
||||
if [[ -z "${dontDotnetInstall-}" && -z "${installPhase-}" ]]; then
|
||||
installPhase=dotnetInstallPhase
|
||||
fi
|
@ -1,54 +0,0 @@
|
||||
{
|
||||
lib,
|
||||
stdenv,
|
||||
which,
|
||||
coreutils,
|
||||
zlib,
|
||||
openssl,
|
||||
makeSetupHook,
|
||||
zip,
|
||||
# Passed from ../default.nix
|
||||
dotnet-sdk,
|
||||
dotnet-runtime,
|
||||
}:
|
||||
{
|
||||
dotnetConfigureHook = makeSetupHook {
|
||||
name = "dotnet-configure-hook";
|
||||
substitutions = {
|
||||
dynamicLinker = "${stdenv.cc}/nix-support/dynamic-linker";
|
||||
libPath = lib.makeLibraryPath [
|
||||
stdenv.cc.cc
|
||||
stdenv.cc.libc
|
||||
dotnet-sdk.passthru.icu
|
||||
zlib
|
||||
openssl
|
||||
];
|
||||
};
|
||||
} ./dotnet-configure-hook.sh;
|
||||
|
||||
dotnetBuildHook = makeSetupHook {
|
||||
name = "dotnet-build-hook";
|
||||
} ./dotnet-build-hook.sh;
|
||||
|
||||
dotnetCheckHook = makeSetupHook {
|
||||
name = "dotnet-check-hook";
|
||||
} ./dotnet-check-hook.sh;
|
||||
|
||||
dotnetInstallHook = makeSetupHook {
|
||||
name = "dotnet-install-hook";
|
||||
substitutions = {
|
||||
inherit zip;
|
||||
};
|
||||
} ./dotnet-install-hook.sh;
|
||||
|
||||
dotnetFixupHook = makeSetupHook {
|
||||
name = "dotnet-fixup-hook";
|
||||
substitutions = {
|
||||
dotnetRuntime = if (dotnet-runtime != null) then dotnet-runtime else null;
|
||||
wrapperPath = lib.makeBinPath [
|
||||
which
|
||||
coreutils
|
||||
];
|
||||
};
|
||||
} ./dotnet-fixup-hook.sh;
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
dotnetBuildHook() {
|
||||
echo "Executing dotnetBuildHook"
|
||||
|
||||
runHook preBuild
|
||||
|
||||
local -r dotnetBuildType="${dotnetBuildType-Release}"
|
||||
|
||||
if [[ -n $__structuredAttrs ]]; then
|
||||
local dotnetProjectFilesArray=( "${dotnetProjectFiles[@]}" )
|
||||
local dotnetTestProjectFilesArray=( "${dotnetTestProjectFiles[@]}" )
|
||||
local dotnetFlagsArray=( "${dotnetFlags[@]}" )
|
||||
local dotnetBuildFlagsArray=( "${dotnetBuildFlags[@]}" )
|
||||
local dotnetRuntimeIdsArray=( "${dotnetRuntimeIds[@]}" )
|
||||
else
|
||||
local dotnetProjectFilesArray=($dotnetProjectFiles)
|
||||
local dotnetTestProjectFilesArray=($dotnetTestProjectFiles)
|
||||
local dotnetFlagsArray=($dotnetFlags)
|
||||
local dotnetBuildFlagsArray=($dotnetBuildFlags)
|
||||
local dotnetRuntimeIdsArray=($dotnetRuntimeIds)
|
||||
fi
|
||||
|
||||
if [[ -n "${enableParallelBuilding-}" ]]; then
|
||||
local -r maxCpuFlag="$NIX_BUILD_CORES"
|
||||
local -r parallelBuildFlag="true"
|
||||
else
|
||||
local -r maxCpuFlag="1"
|
||||
local -r parallelBuildFlag="false"
|
||||
fi
|
||||
|
||||
if [[ -v dotnetSelfContainedBuild ]]; then
|
||||
if [[ -n $dotnetSelfContainedBuild ]]; then
|
||||
dotnetBuildFlagsArray+=("-p:SelfContained=true")
|
||||
else
|
||||
dotnetBuildFlagsArray+=("-p:SelfContained=false")
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n ${dotnetUseAppHost-} ]]; then
|
||||
dotnetBuildFlagsArray+=("-p:UseAppHost=true")
|
||||
fi
|
||||
|
||||
local versionFlagsArray=()
|
||||
if [[ -n ${version-} ]]; then
|
||||
versionFlagsArray+=("-p:InformationalVersion=$version")
|
||||
fi
|
||||
|
||||
if [[ -n ${versionForDotnet-} ]]; then
|
||||
versionFlagsArray+=("-p:Version=$versionForDotnet")
|
||||
fi
|
||||
|
||||
dotnetBuild() {
|
||||
local -r projectFile="${1-}"
|
||||
|
||||
for runtimeId in "${dotnetRuntimeIdsArray[@]}"; do
|
||||
local runtimeIdFlagsArray=()
|
||||
if [[ $projectFile == *.csproj || -n ${dotnetSelfContainedBuild-} ]]; then
|
||||
runtimeIdFlagsArray+=("--runtime" "$runtimeId")
|
||||
fi
|
||||
|
||||
dotnet build ${1+"$projectFile"} \
|
||||
-maxcpucount:"$maxCpuFlag" \
|
||||
-p:BuildInParallel="$parallelBuildFlag" \
|
||||
-p:ContinuousIntegrationBuild=true \
|
||||
-p:Deterministic=true \
|
||||
-p:OverwriteReadOnlyFiles=true \
|
||||
--configuration "$dotnetBuildType" \
|
||||
--no-restore \
|
||||
"${versionFlagsArray[@]}" \
|
||||
"${runtimeIdFlagsArray[@]}" \
|
||||
"${dotnetBuildFlagsArray[@]}" \
|
||||
"${dotnetFlagsArray[@]}"
|
||||
done
|
||||
}
|
||||
|
||||
if (( ${#dotnetProjectFilesArray[@]} == 0 )); then
|
||||
dotnetBuild
|
||||
fi
|
||||
|
||||
local projectFile
|
||||
for projectFile in "${dotnetProjectFilesArray[@]}" "${dotnetTestProjectFilesArray[@]}"; do
|
||||
dotnetBuild "$projectFile"
|
||||
done
|
||||
|
||||
runHook postBuild
|
||||
|
||||
echo "Finished dotnetBuildHook"
|
||||
}
|
||||
|
||||
if [[ -z ${dontDotnetBuild-} && -z ${buildPhase-} ]]; then
|
||||
buildPhase=dotnetBuildHook
|
||||
fi
|
@ -1,81 +0,0 @@
|
||||
dotnetCheckHook() {
|
||||
echo "Executing dotnetCheckHook"
|
||||
|
||||
runHook preCheck
|
||||
|
||||
local -r dotnetBuildType="${dotnetBuildType-Release}"
|
||||
|
||||
if [[ -n $__structuredAttrs ]]; then
|
||||
local dotnetProjectFilesArray=( "${dotnetProjectFiles[@]}" )
|
||||
local dotnetTestProjectFilesArray=( "${dotnetTestProjectFiles[@]}" )
|
||||
local dotnetTestFlagsArray=( "${dotnetTestFlags[@]}" )
|
||||
local dotnetTestFiltersArray=( "${dotnetTestFilters[@]}" )
|
||||
local dotnetDisabledTestsArray=( "${dotnetDisabledTests[@]}" )
|
||||
local dotnetRuntimeDepsArray=( "${dotnetRuntimeDeps[@]}" )
|
||||
local dotnetRuntimeIdsArray=( "${dotnetRuntimeIds[@]}" )
|
||||
else
|
||||
local dotnetProjectFilesArray=($dotnetProjectFiles)
|
||||
local dotnetTestProjectFilesArray=($dotnetTestProjectFiles)
|
||||
local dotnetTestFlagsArray=($dotnetTestFlags)
|
||||
local dotnetTestFiltersArray=($dotnetTestFilters)
|
||||
local dotnetDisabledTestsArray=($dotnetDisabledTests)
|
||||
local dotnetRuntimeDepsArray=($dotnetRuntimeDeps)
|
||||
local dotnetRuntimeIdsArray=($dotnetRuntimeIds)
|
||||
fi
|
||||
|
||||
if (( ${#dotnetDisabledTestsArray[@]} > 0 )); then
|
||||
local disabledTestsFilters=("${dotnetDisabledTestsArray[@]/#/FullyQualifiedName!=}")
|
||||
dotnetTestFiltersArray=( "${dotnetTestFiltersArray[@]}" "${disabledTestsFilters[@]//,/%2C}" )
|
||||
fi
|
||||
|
||||
if (( ${#dotnetTestFiltersArray[@]} > 0 )); then
|
||||
local OLDIFS="$IFS" IFS='&'
|
||||
dotnetTestFlagsArray+=("--filter:${dotnetTestFiltersArray[*]}")
|
||||
IFS="$OLDIFS"
|
||||
fi
|
||||
|
||||
local libraryPath="${LD_LIBRARY_PATH-}"
|
||||
if (( ${#dotnetRuntimeDepsArray[@]} > 0 )); then
|
||||
local libraryPathArray=("${dotnetRuntimeDepsArray[@]/%//lib}")
|
||||
local OLDIFS="$IFS" IFS=':'
|
||||
libraryPath="${libraryPathArray[*]}${libraryPath:+':'}$libraryPath"
|
||||
IFS="$OLDIFS"
|
||||
fi
|
||||
|
||||
if [[ -n ${enableParallelBuilding-} ]]; then
|
||||
local -r maxCpuFlag="$NIX_BUILD_CORES"
|
||||
else
|
||||
local -r maxCpuFlag="1"
|
||||
fi
|
||||
|
||||
local projectFile runtimeId
|
||||
for projectFile in "${dotnetTestProjectFilesArray[@]-${dotnetProjectFilesArray[@]}}"; do
|
||||
for runtimeId in "${dotnetRuntimeIdsArray[@]}"; do
|
||||
local runtimeIdFlagsArray=()
|
||||
if [[ $projectFile == *.csproj ]]; then
|
||||
runtimeIdFlagsArray=("--runtime" "$runtimeId")
|
||||
fi
|
||||
|
||||
LD_LIBRARY_PATH=$libraryPath \
|
||||
dotnet test "$projectFile" \
|
||||
-maxcpucount:"$maxCpuFlag" \
|
||||
-p:ContinuousIntegrationBuild=true \
|
||||
-p:Deterministic=true \
|
||||
--configuration "$dotnetBuildType" \
|
||||
--no-restore \
|
||||
--no-build \
|
||||
--logger "console;verbosity=normal" \
|
||||
"${runtimeIdFlagsArray[@]}" \
|
||||
"${dotnetTestFlagsArray[@]}" \
|
||||
"${dotnetFlagsArray[@]}"
|
||||
done
|
||||
done
|
||||
|
||||
runHook postCheck
|
||||
|
||||
echo "Finished dotnetCheckHook"
|
||||
}
|
||||
|
||||
if [[ -z "${dontDotnetCheck-}" && -z "${checkPhase-}" ]]; then
|
||||
checkPhase=dotnetCheckHook
|
||||
fi
|
@ -1,78 +0,0 @@
|
||||
dotnetConfigureHook() {
|
||||
echo "Executing dotnetConfigureHook"
|
||||
|
||||
runHook preConfigure
|
||||
|
||||
local -r dynamicLinker=@dynamicLinker@
|
||||
local -r libPath=@libPath@
|
||||
|
||||
if [[ -n $__structuredAttrs ]]; then
|
||||
local dotnetProjectFilesArray=( "${dotnetProjectFiles[@]}" )
|
||||
local dotnetTestProjectFilesArray=( "${dotnetTestProjectFiles[@]}" )
|
||||
local dotnetFlagsArray=( "${dotnetFlags[@]}" )
|
||||
local dotnetRestoreFlagsArray=( "${dotnetRestoreFlags[@]}" )
|
||||
local dotnetRuntimeIdsArray=( "${dotnetRuntimeIds[@]}" )
|
||||
else
|
||||
local dotnetProjectFilesArray=($dotnetProjectFiles)
|
||||
local dotnetTestProjectFilesArray=($dotnetTestProjectFiles)
|
||||
local dotnetFlagsArray=($dotnetFlags)
|
||||
local dotnetRestoreFlagsArray=($dotnetRestoreFlags)
|
||||
local dotnetRuntimeIdsArray=($dotnetRuntimeIds)
|
||||
fi
|
||||
|
||||
if [[ -z ${enableParallelBuilding-} ]]; then
|
||||
local -r parallelFlag="--disable-parallel"
|
||||
fi
|
||||
|
||||
if [[ -v dotnetSelfContainedBuild ]]; then
|
||||
if [[ -n $dotnetSelfContainedBuild ]]; then
|
||||
dotnetRestoreFlagsArray+=("-p:SelfContained=true")
|
||||
else
|
||||
dotnetRestoreFlagsArray+=("-p:SelfContained=false")
|
||||
fi
|
||||
fi
|
||||
|
||||
dotnetRestore() {
|
||||
local -r projectFile="${1-}"
|
||||
for runtimeId in "${dotnetRuntimeIdsArray[@]}"; do
|
||||
dotnet restore ${1+"$projectFile"} \
|
||||
-p:ContinuousIntegrationBuild=true \
|
||||
-p:Deterministic=true \
|
||||
-p:NuGetAudit=false \
|
||||
--runtime "$runtimeId" \
|
||||
${parallelFlag-} \
|
||||
"${dotnetRestoreFlagsArray[@]}" \
|
||||
"${dotnetFlagsArray[@]}"
|
||||
done
|
||||
}
|
||||
|
||||
if [[ -f .config/dotnet-tools.json || -f dotnet-tools.json ]]; then
|
||||
dotnet tool restore
|
||||
fi
|
||||
|
||||
# dotnetGlobalTool is set in buildDotnetGlobalTool to patch dependencies but
|
||||
# avoid other project-specific logic. This is a hack, but the old behavior
|
||||
# is worse as it relied on a bug: setting projectFile to an empty string
|
||||
# made the hooks actually skip all project-specific logic. It’s hard to keep
|
||||
# backwards compatibility with this odd behavior now since we are using
|
||||
# arrays, so instead we just pass a variable to indicate that we don’t have
|
||||
# projects.
|
||||
if [[ -z ${dotnetGlobalTool-} ]]; then
|
||||
if (( ${#dotnetProjectFilesArray[@]} == 0 )); then
|
||||
dotnetRestore
|
||||
fi
|
||||
|
||||
local projectFile
|
||||
for projectFile in "${dotnetProjectFilesArray[@]}" "${dotnetTestProjectFilesArray[@]}"; do
|
||||
dotnetRestore "$projectFile"
|
||||
done
|
||||
fi
|
||||
|
||||
runHook postConfigure
|
||||
|
||||
echo "Finished dotnetConfigureHook"
|
||||
}
|
||||
|
||||
if [[ -z "${dontDotnetConfigure-}" && -z "${configurePhase-}" ]]; then
|
||||
configurePhase=dotnetConfigureHook
|
||||
fi
|
@ -1,101 +0,0 @@
|
||||
# For compatibility, convert makeWrapperArgs to an array unless we are using
|
||||
# structured attributes. That is, we ensure that makeWrapperArgs is always an
|
||||
# array.
|
||||
# See https://github.com/NixOS/nixpkgs/blob/858f4db3048c5be3527e183470e93c1a72c5727c/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh#L1-L3
|
||||
# and https://github.com/NixOS/nixpkgs/pull/313005#issuecomment-2175482920
|
||||
if [[ -z $__structuredAttrs ]]; then
|
||||
makeWrapperArgs=( ${makeWrapperArgs-} )
|
||||
fi
|
||||
|
||||
# First argument is the executable you want to wrap,
|
||||
# the second is the destination for the wrapper.
|
||||
wrapDotnetProgram() {
|
||||
local -r dotnetRuntime=@dotnetRuntime@
|
||||
local -r wrapperPath=@wrapperPath@
|
||||
|
||||
local -r dotnetFromEnvScript='dotnetFromEnv() {
|
||||
local dotnetPath
|
||||
if command -v dotnet 2>&1 >/dev/null; then
|
||||
dotnetPath=$(which dotnet) && \
|
||||
dotnetPath=$(realpath "$dotnetPath") && \
|
||||
dotnetPath=$(dirname "$dotnetPath") && \
|
||||
export DOTNET_ROOT="$dotnetPath"
|
||||
fi
|
||||
}
|
||||
dotnetFromEnv'
|
||||
|
||||
if [[ -n $__structuredAttrs ]]; then
|
||||
local -r dotnetRuntimeDepsArray=( "${dotnetRuntimeDeps[@]}" )
|
||||
else
|
||||
local -r dotnetRuntimeDepsArray=($dotnetRuntimeDeps)
|
||||
fi
|
||||
|
||||
local dotnetRuntimeDepsFlags=()
|
||||
if (( ${#dotnetRuntimeDepsArray[@]} > 0 )); then
|
||||
local libraryPathArray=("${dotnetRuntimeDepsArray[@]/%//lib}")
|
||||
local OLDIFS="$IFS" IFS=':'
|
||||
dotnetRuntimeDepsFlags+=("--suffix" "LD_LIBRARY_PATH" ":" "${libraryPathArray[*]}")
|
||||
IFS="$OLDIFS"
|
||||
fi
|
||||
|
||||
local dotnetRootFlagsArray=()
|
||||
if [[ -z ${dotnetSelfContainedBuild-} ]]; then
|
||||
if [[ -n ${useDotnetFromEnv-} ]]; then
|
||||
# if dotnet CLI is available, set DOTNET_ROOT based on it. Otherwise set to default .NET runtime
|
||||
dotnetRootFlagsArray+=("--suffix" "PATH" ":" "$wrapperPath")
|
||||
dotnetRootFlagsArray+=("--run" "$dotnetFromEnvScript")
|
||||
if [[ -n $dotnetRuntime ]]; then
|
||||
dotnetRootFlagsArray+=("--set-default" "DOTNET_ROOT" "$dotnetRuntime/share/dotnet")
|
||||
dotnetRootFlagsArray+=("--suffix" "PATH" ":" "$dotnetRuntime/bin")
|
||||
fi
|
||||
elif [[ -n $dotnetRuntime ]]; then
|
||||
dotnetRootFlagsArray+=("--set" "DOTNET_ROOT" "$dotnetRuntime/share/dotnet")
|
||||
dotnetRootFlagsArray+=("--prefix" "PATH" ":" "$dotnetRuntime/bin")
|
||||
fi
|
||||
fi
|
||||
|
||||
makeWrapper "$1" "$2" \
|
||||
"${dotnetRuntimeDepsFlags[@]}" \
|
||||
"${dotnetRootFlagsArray[@]}" \
|
||||
"${gappsWrapperArgs[@]}" \
|
||||
"${makeWrapperArgs[@]}"
|
||||
|
||||
echo "installed wrapper to "$2""
|
||||
}
|
||||
|
||||
dotnetFixupHook() {
|
||||
local -r dotnetInstallPath="${dotnetInstallPath-$out/lib/$pname}"
|
||||
|
||||
local executable executableBasename
|
||||
|
||||
# check if dotnetExecutables is declared (including empty values, in which case we generate no executables)
|
||||
if declare -p dotnetExecutables &>/dev/null; then
|
||||
if [[ -n $__structuredAttrs ]]; then
|
||||
local dotnetExecutablesArray=( "${dotnetExecutables[@]}" )
|
||||
else
|
||||
local dotnetExecutablesArray=($dotnetExecutables)
|
||||
fi
|
||||
for executable in "${dotnetExecutablesArray[@]}"; do
|
||||
executableBasename=$(basename "$executable")
|
||||
|
||||
local path="$dotnetInstallPath/$executable"
|
||||
|
||||
if test -x "$path"; then
|
||||
wrapDotnetProgram "$path" "$out/bin/$executableBasename"
|
||||
else
|
||||
echo "Specified binary \"$executable\" is either not an executable or does not exist!"
|
||||
echo "Looked in $path"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
else
|
||||
while IFS= read -d '' executable; do
|
||||
executableBasename=$(basename "$executable")
|
||||
wrapDotnetProgram "$executable" "$out/bin/$executableBasename" \;
|
||||
done < <(find "$dotnetInstallPath" ! -name "*.dll" -executable -type f -print0)
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ -z "${dontFixup-}" && -z "${dontDotnetFixup-}" ]]; then
|
||||
appendToVar preFixupPhases dotnetFixupHook
|
||||
fi
|
@ -1,114 +0,0 @@
|
||||
dotnetInstallHook() {
|
||||
echo "Executing dotnetInstallHook"
|
||||
|
||||
runHook preInstall
|
||||
|
||||
local -r dotnetInstallPath="${dotnetInstallPath-$out/lib/$pname}"
|
||||
local -r dotnetBuildType="${dotnetBuildType-Release}"
|
||||
|
||||
if [[ -n $__structuredAttrs ]]; then
|
||||
local dotnetProjectFilesArray=( "${dotnetProjectFiles[@]}" )
|
||||
local dotnetFlagsArray=( "${dotnetFlags[@]}" )
|
||||
local dotnetInstallFlagsArray=( "${dotnetInstallFlags[@]}" )
|
||||
local dotnetPackFlagsArray=( "${dotnetPackFlags[@]}" )
|
||||
local dotnetRuntimeIdsArray=( "${dotnetRuntimeIds[@]}" )
|
||||
else
|
||||
local dotnetProjectFilesArray=($dotnetProjectFiles)
|
||||
local dotnetFlagsArray=($dotnetFlags)
|
||||
local dotnetInstallFlagsArray=($dotnetInstallFlags)
|
||||
local dotnetPackFlagsArray=($dotnetPackFlags)
|
||||
local dotnetRuntimeIdsArray=($dotnetRuntimeIds)
|
||||
fi
|
||||
|
||||
if [[ -v dotnetSelfContainedBuild ]]; then
|
||||
if [[ -n $dotnetSelfContainedBuild ]]; then
|
||||
dotnetInstallFlagsArray+=("--self-contained")
|
||||
else
|
||||
dotnetInstallFlagsArray+=("--no-self-contained")
|
||||
# https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained
|
||||
# Trimming is only available for self-contained build, so force disable it here
|
||||
dotnetInstallFlagsArray+=("-p:PublishTrimmed=false")
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n ${dotnetUseAppHost-} ]]; then
|
||||
dotnetInstallFlagsArray+=("-p:UseAppHost=true")
|
||||
fi
|
||||
|
||||
if [[ -n ${enableParallelBuilding-} ]]; then
|
||||
local -r maxCpuFlag="$NIX_BUILD_CORES"
|
||||
else
|
||||
local -r maxCpuFlag="1"
|
||||
fi
|
||||
|
||||
dotnetPublish() {
|
||||
local -r projectFile="${1-}"
|
||||
|
||||
for runtimeId in "${dotnetRuntimeIdsArray[@]}"; do
|
||||
runtimeIdFlagsArray=()
|
||||
if [[ $projectFile == *.csproj || -n ${dotnetSelfContainedBuild-} ]]; then
|
||||
runtimeIdFlagsArray+=("--runtime" "$runtimeId")
|
||||
fi
|
||||
|
||||
dotnet publish ${1+"$projectFile"} \
|
||||
-maxcpucount:"$maxCpuFlag" \
|
||||
-p:ContinuousIntegrationBuild=true \
|
||||
-p:Deterministic=true \
|
||||
-p:OverwriteReadOnlyFiles=true \
|
||||
--output "$dotnetInstallPath" \
|
||||
--configuration "$dotnetBuildType" \
|
||||
--no-restore \
|
||||
--no-build \
|
||||
"${runtimeIdFlagsArray[@]}" \
|
||||
"${dotnetInstallFlagsArray[@]}" \
|
||||
"${dotnetFlagsArray[@]}"
|
||||
done
|
||||
}
|
||||
|
||||
dotnetPack() {
|
||||
local -r projectFile="${1-}"
|
||||
|
||||
for runtimeId in "${dotnetRuntimeIdsArray[@]}"; do
|
||||
dotnet pack ${1+"$projectFile"} \
|
||||
-maxcpucount:"$maxCpuFlag" \
|
||||
-p:ContinuousIntegrationBuild=true \
|
||||
-p:Deterministic=true \
|
||||
-p:OverwriteReadOnlyFiles=true \
|
||||
--output "$out/share/nuget/source" \
|
||||
--configuration "$dotnetBuildType" \
|
||||
--no-restore \
|
||||
--no-build \
|
||||
--runtime "$runtimeId" \
|
||||
"${dotnetPackFlagsArray[@]}" \
|
||||
"${dotnetFlagsArray[@]}"
|
||||
done
|
||||
}
|
||||
|
||||
if (( ${#dotnetProjectFilesArray[@]} == 0 )); then
|
||||
dotnetPublish
|
||||
else
|
||||
local projectFile
|
||||
for projectFile in "${dotnetProjectFilesArray[@]}"; do
|
||||
dotnetPublish "$projectFile"
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ -n ${packNupkg-} ]]; then
|
||||
if (( ${#dotnetProjectFilesArray[@]} == 0 )); then
|
||||
dotnetPack
|
||||
else
|
||||
local projectFile
|
||||
for projectFile in "${dotnetProjectFilesArray[@]}"; do
|
||||
dotnetPack "$projectFile"
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
runHook postInstall
|
||||
|
||||
echo "Finished dotnetInstallHook"
|
||||
}
|
||||
|
||||
if [[ -z "${dontDotnetInstall-}" && -z "${installPhase-}" ]]; then
|
||||
installPhase=dotnetInstallHook
|
||||
fi
|
@ -57,6 +57,7 @@ buildDotnetModule rec {
|
||||
|
||||
# Build translations
|
||||
dotnet build Pinta \
|
||||
--no-restore \
|
||||
-p:ContinuousIntegrationBuild=true \
|
||||
-p:Deterministic=true \
|
||||
-target:CompileTranslations,PublishTranslations \
|
||||
|
@ -18,6 +18,8 @@
|
||||
replaceVars,
|
||||
nugetPackageHook,
|
||||
xmlstarlet,
|
||||
pkgs,
|
||||
recurseIntoAttrs,
|
||||
}:
|
||||
type: unwrapped:
|
||||
stdenvNoCC.mkDerivation (finalAttrs: {
|
||||
@ -280,6 +282,17 @@ stdenvNoCC.mkDerivation (finalAttrs: {
|
||||
};
|
||||
}
|
||||
// lib.optionalAttrs (type == "sdk") ({
|
||||
buildDotnetModule = recurseIntoAttrs (
|
||||
(pkgs.appendOverlays [
|
||||
(self: super: {
|
||||
dotnet-sdk = finalAttrs.finalPackage;
|
||||
dotnet-runtime = finalAttrs.finalPackage.runtime;
|
||||
})
|
||||
]).callPackage
|
||||
../../../test/dotnet/default.nix
|
||||
{ }
|
||||
);
|
||||
|
||||
console = lib.recurseIntoAttrs {
|
||||
# yes, older SDKs omit the comma
|
||||
cs = mkConsoleTests "C#" "cs" "Hello,?\\ World!";
|
||||
|
@ -26,7 +26,7 @@ let
|
||||
'';
|
||||
});
|
||||
|
||||
runtimeVersion = lib.getVersion dotnet-runtime;
|
||||
runtimeVersion = lib.head (lib.splitString "-" (lib.getVersion dotnet-runtime));
|
||||
runtimeVersionFile = builtins.toFile "dotnet-version.txt" runtimeVersion;
|
||||
in
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user