buildDotnetModule: support setting projectFile as an array && properly interpret disabledTests

This commit is contained in:
IvarWithoutBones 2021-11-21 22:47:53 +01:00
parent 4f871e232b
commit 1b366cb92b
2 changed files with 46 additions and 38 deletions

View file

@ -71,7 +71,7 @@ The `dotnetCorePackages.sdk` contains both a runtime and the full sdk of a given
To package Dotnet applications, you can use `buildDotnetModule`. This has similar arguments to `stdenv.mkDerivation`, with the following additions: To package Dotnet applications, you can use `buildDotnetModule`. This has similar arguments to `stdenv.mkDerivation`, with the following additions:
* `projectFile` has to be used for specifying the dotnet project file relative to the source root. These usually have `.sln` or `.csproj` file extensions. * `projectFile` has to be used for specifying the dotnet project file relative to the source root. These usually have `.sln` or `.csproj` file extensions. This can be an array of multiple projects as well.
* `nugetDeps` has to be used to specify the NuGet dependency file. Unfortunately, these cannot be deterministically fetched without a lockfile. This file should be generated using `nuget-to-nix` tool, which is available in nixpkgs. * `nugetDeps` has to be used to specify the NuGet dependency file. Unfortunately, these cannot be deterministically fetched without a lockfile. This file should be generated using `nuget-to-nix` tool, which is available in nixpkgs.
* `executables` is used to specify which executables get wrapped to `$out/bin`, relative to `$out/lib/$pname`. If this is unset, all executables generated will get installed. If you do not want to install any, set this to `[]`. * `executables` is used to specify which executables get wrapped to `$out/bin`, relative to `$out/lib/$pname`. If this is unset, all executables generated will get installed. If you do not want to install any, set this to `[]`.
* `runtimeDeps` is used to wrap libraries into `LD_LIBRARY_PATH`. This is how dotnet usually handles runtime dependencies. * `runtimeDeps` is used to wrap libraries into `LD_LIBRARY_PATH`. This is how dotnet usually handles runtime dependencies.

View file

@ -21,7 +21,7 @@
# Unfortunately, dotnet has no method for doing this automatically. # Unfortunately, dotnet has no method for doing this automatically.
# If unset, all executables in the projects root will get installed. This may cause bloat! # If unset, all executables in the projects root will get installed. This may cause bloat!
, executables ? null , executables ? null
# The packages project file, which contains instructions on how to compile it. # The packages project file, which contains instructions on how to compile it. This can be an array of multiple project files as well.
, projectFile ? null , projectFile ? null
# The NuGet dependency file. This locks all NuGet dependency versions, as otherwise they cannot be deterministically fetched. # The NuGet dependency file. This locks all NuGet dependency versions, as otherwise they cannot be deterministically fetched.
# This can be generated using the `nuget-to-nix` tool. # This can be generated using the `nuget-to-nix` tool.
@ -102,13 +102,15 @@ let
export HOME=$(mktemp -d) export HOME=$(mktemp -d)
dotnet restore "$projectFile" \ for project in ''${projectFile[@]}; do
${lib.optionalString (!enableParallelBuilding) "--disable-parallel"} \ dotnet restore "$project" \
-p:ContinuousIntegrationBuild=true \ ${lib.optionalString (!enableParallelBuilding) "--disable-parallel"} \
-p:Deterministic=true \ -p:ContinuousIntegrationBuild=true \
--source "${nuget-source}/lib" \ -p:Deterministic=true \
"''${dotnetRestoreFlags[@]}" \ --source "${nuget-source}/lib" \
"''${dotnetFlags[@]}" "''${dotnetRestoreFlags[@]}" \
"''${dotnetFlags[@]}"
done
runHook postConfigure runHook postConfigure
''; '';
@ -116,16 +118,18 @@ let
buildPhase = args.buildPhase or '' buildPhase = args.buildPhase or ''
runHook preBuild runHook preBuild
dotnet build "$projectFile" \ for project in ''${projectFile[@]}; do
-maxcpucount:${if enableParallelBuilding then "$NIX_BUILD_CORES" else "1"} \ dotnet build "$project" \
-p:BuildInParallel=${if enableParallelBuilding then "true" else "false"} \ -maxcpucount:${if enableParallelBuilding then "$NIX_BUILD_CORES" else "1"} \
-p:ContinuousIntegrationBuild=true \ -p:BuildInParallel=${if enableParallelBuilding then "true" else "false"} \
-p:Deterministic=true \ -p:ContinuousIntegrationBuild=true \
-p:Version=${args.version} \ -p:Deterministic=true \
--configuration "$buildType" \ -p:Version=${args.version} \
--no-restore \ --configuration "$buildType" \
"''${dotnetBuildFlags[@]}" \ --no-restore \
"''${dotnetFlags[@]}" "''${dotnetBuildFlags[@]}" \
"''${dotnetFlags[@]}"
done
runHook postBuild runHook postBuild
''; '';
@ -133,16 +137,18 @@ let
checkPhase = args.checkPhase or '' checkPhase = args.checkPhase or ''
runHook preCheck runHook preCheck
${lib.getBin dotnet-test-sdk}/bin/dotnet test "$testProjectFile" \ for project in ''${testProjectFile[@]}; do
-maxcpucount:${if enableParallelBuilding then "$NIX_BUILD_CORES" else "1"} \ ${lib.getBin dotnet-test-sdk}/bin/dotnet test "$project" \
-p:ContinuousIntegrationBuild=true \ -maxcpucount:${if enableParallelBuilding then "$NIX_BUILD_CORES" else "1"} \
-p:Deterministic=true \ -p:ContinuousIntegrationBuild=true \
--configuration "$buildType" \ -p:Deterministic=true \
--no-build \ --configuration "$buildType" \
--logger "console;verbosity=normal" \ --no-build \
${lib.optionalString (disabledTests != []) "--filter \"FullyQualifiedName!=${lib.concatStringsSep "|FullyQualifiedName!=" disabledTests}\""} \ --logger "console;verbosity=normal" \
"''${dotnetTestFlags[@]}" \ ${lib.optionalString (disabledTests != []) "--filter \"FullyQualifiedName!=${lib.concatStringsSep "&FullyQualifiedName!=" disabledTests}\""} \
"''${dotnetFlags[@]}" "''${dotnetTestFlags[@]}" \
"''${dotnetFlags[@]}"
done
runHook postCheck runHook postCheck
''; '';
@ -150,15 +156,17 @@ let
installPhase = args.installPhase or '' installPhase = args.installPhase or ''
runHook preInstall runHook preInstall
dotnet publish "$projectFile" \ for project in ''${projectFile[@]}; do
-p:ContinuousIntegrationBuild=true \ dotnet publish "$project" \
-p:Deterministic=true \ -p:ContinuousIntegrationBuild=true \
--output $out/lib/${args.pname} \ -p:Deterministic=true \
--configuration "$buildType" \ --output $out/lib/${args.pname} \
--no-build \ --configuration "$buildType" \
--no-self-contained \ --no-build \
"''${dotnetInstallFlags[@]}" \ --no-self-contained \
"''${dotnetFlags[@]}" "''${dotnetInstallFlags[@]}" \
"''${dotnetFlags[@]}"
done
'' + (if executables != null then '' '' + (if executables != null then ''
for executable in $executables; do for executable in $executables; do
execPath="$out/lib/${args.pname}/$executable" execPath="$out/lib/${args.pname}/$executable"