diff options
author | Ivar Scholten <ivar.scholten@protonmail.com> | 2022-09-09 00:14:04 +0200 |
---|---|---|
committer | Ivar Scholten <ivar.scholten@protonmail.com> | 2022-09-18 18:00:37 +0200 |
commit | 03a1b62cb38cf6a60c496c896dbdccd4e4d9b03a (patch) | |
tree | 0a01b2e25f41e17d4a4263f3ecbb2219aa26423b /pkgs/build-support/dotnet | |
parent | a7c598e458183b30a7218f3b1301a689b39a6542 (diff) | |
download | nixpkgs-03a1b62cb38cf6a60c496c896dbdccd4e4d9b03a.tar nixpkgs-03a1b62cb38cf6a60c496c896dbdccd4e4d9b03a.tar.gz nixpkgs-03a1b62cb38cf6a60c496c896dbdccd4e4d9b03a.tar.bz2 nixpkgs-03a1b62cb38cf6a60c496c896dbdccd4e4d9b03a.tar.lz nixpkgs-03a1b62cb38cf6a60c496c896dbdccd4e4d9b03a.tar.xz nixpkgs-03a1b62cb38cf6a60c496c896dbdccd4e4d9b03a.tar.zst nixpkgs-03a1b62cb38cf6a60c496c896dbdccd4e4d9b03a.zip |
buildDotnetModule: dont require specifing a projectFile
In a lot of cases dotnet can figure this out by itself, so we can just invoke it without the project argument.
Diffstat (limited to 'pkgs/build-support/dotnet')
4 files changed, 91 insertions, 54 deletions
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/default.nix index b321c8eb10c..569ad2615e6 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/default.nix +++ b/pkgs/build-support/dotnet/build-dotnet-module/default.nix @@ -82,8 +82,6 @@ , ... } @ args: -assert projectFile == null -> throw "Defining the `projectFile` attribute is required. This is usually an `.csproj`, or `.sln` file."; - # TODO: Automatically generate a dependency file when a lockfile is present. # This file is unfortunately almost never present, as Microsoft recommands not to push this in upstream repositories. assert nugetDeps == null -> throw "Defining the `nugetDeps` attribute is required, as to lock the NuGet dependencies. This file can be generated by running the `passthru.fetch-deps` script."; @@ -159,8 +157,6 @@ stdenvNoCC.mkDerivation (args // { # Because this list is rather long its put in its own store path to maintain readability of the generated script exclusions = writeText "nuget-package-exclusions" (lib.concatStringsSep "\n" (dotnet-sdk.passthru.packages { fetchNuGet = attrs: attrs.pname; })); - runtimeIds = map (system: dotnet-sdk.systemToDotnetRid system) (args.meta.platforms or dotnet-sdk.meta.platforms); - # Derivations may set flags such as `--runtime <rid>` based on the host platform to avoid restoring/building nuget dependencies they dont have or dont need. # This introduces an issue; In this script we loop over all platforms from `meta` and add the RID flag for it, as to fetch all required dependencies. # The script would inherit the RID flag from the derivation based on the platform building the script, and set the flag for any iteration we do over the RIDs. @@ -171,6 +167,7 @@ stdenvNoCC.mkDerivation (args // { in builtins.filter (flag: !(hasRid flag)) (dotnetFlags ++ dotnetRestoreFlags); + runtimeIds = map (system: dotnet-sdk.systemToDotnetRid system) (args.meta.platforms or dotnet-sdk.meta.platforms); in writeShellScript "fetch-${pname}-deps" '' set -euo pipefail @@ -202,15 +199,27 @@ stdenvNoCC.mkDerivation (args // { export DOTNET_NOLOGO=1 export DOTNET_CLI_TELEMETRY_OPTOUT=1 + declare -a projectFiles=( ${toString (lib.toList projectFile)} ) + declare -a testProjectFiles=( ${toString (lib.toList testProjectFile)} ) + + dotnetRestore() { + local -r project="''${1-}" + local -r rid="''${2-}" + + dotnet restore ''${project-} \ + -p:ContinuousIntegrationBuild=true \ + -p:Deterministic=true \ + --packages "$HOME/nuget_pkgs" \ + --runtime "$rid" \ + ${lib.optionalString (!enableParallelBuilding) "--disable-parallel"} \ + ${lib.optionalString (flags != []) (toString flags)} + } + for rid in "${lib.concatStringsSep "\" \"" runtimeIds}"; do - for project in "${lib.concatStringsSep "\" \"" ((lib.toList projectFile) ++ lib.optionals (testProjectFile != "") (lib.toList testProjectFile))}"; do - dotnet restore "$project" \ - -p:ContinuousIntegrationBuild=true \ - -p:Deterministic=true \ - --packages "$HOME/nuget_pkgs" \ - --runtime "$rid" \ - ${lib.optionalString (!enableParallelBuilding) "--disable-parallel"} \ - ${lib.optionalString (flags != []) (toString flags)} + (( ''${#projectFiles[@]} == 0 )) && dotnetRestore "" "$rid" + + for project in ''${projectFiles[@]-} ''${testProjectFiles[@]-}; do + dotnetRestore "$project" "$rid" done done diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh index 3e6f2bd8465..9199b8d02a8 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh @@ -24,19 +24,25 @@ dotnetBuildHook() { local -r versionFlag="-p:Version=${version-}" fi + dotnetBuild() { + local -r project="${1-}" + env dotnet build ${project-} \ + -maxcpucount:$maxCpuFlag \ + -p:BuildInParallel=$parallelBuildFlag \ + -p:ContinuousIntegrationBuild=true \ + -p:Deterministic=true \ + -p:UseAppHost=true \ + --configuration "@buildType@" \ + --no-restore \ + ${versionFlag-} \ + ${dotnetBuildFlags[@]} \ + ${dotnetFlags[@]} + } + + (( "${#projectFile[@]}" == 0 )) && dotnetBuild + for project in ${projectFile[@]} ${testProjectFile[@]-}; do - env \ - dotnet build "$project" \ - -maxcpucount:$maxCpuFlag \ - -p:BuildInParallel=$parallelBuildFlag \ - -p:ContinuousIntegrationBuild=true \ - -p:Deterministic=true \ - -p:UseAppHost=true \ - --configuration "@buildType@" \ - --no-restore \ - ${versionFlag-} \ - ${dotnetBuildFlags[@]} \ - ${dotnetFlags[@]} + dotnetBuild "$project" done runHook postBuild diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh index 5528f0e07a3..10067cf0882 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh @@ -13,15 +13,21 @@ dotnetConfigureHook() { local -r parallelFlag="--disable-parallel" fi + dotnetRestore() { + local -r project="${1-}" + env dotnet restore ${project-} \ + -p:ContinuousIntegrationBuild=true \ + -p:Deterministic=true \ + --source "@nugetSource@/lib" \ + ${parallelFlag-} \ + ${dotnetRestoreFlags[@]} \ + ${dotnetFlags[@]} + } + + (( "${#projectFile[@]}" == 0 )) && dotnetRestore + for project in ${projectFile[@]} ${testProjectFile[@]-}; do - env \ - dotnet restore "$project" \ - -p:ContinuousIntegrationBuild=true \ - -p:Deterministic=true \ - --source "@nugetSource@/lib" \ - ${parallelFlag-} \ - ${dotnetRestoreFlags[@]} \ - ${dotnetFlags[@]} + dotnetRestore "$project" done runHook postConfigure diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh index fd88ea32ec0..217e79e41b4 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh @@ -12,33 +12,49 @@ dotnetInstallHook() { dotnetInstallFlags+=("--no-self-contained") fi - for project in ${projectFile[@]}; do - env \ - dotnet publish "$project" \ - -p:ContinuousIntegrationBuild=true \ - -p:Deterministic=true \ - -p:UseAppHost=true \ - --output "$out/lib/${pname}" \ - --configuration "@buildType@" \ - --no-build \ - ${dotnetInstallFlags[@]} \ - ${dotnetFlags[@]} - done + dotnetPublish() { + local -r project="${1-}" + env dotnet publish ${project-} \ + -p:ContinuousIntegrationBuild=true \ + -p:Deterministic=true \ + -p:UseAppHost=true \ + --output "$out/lib/${pname}" \ + --configuration "@buildType@" \ + --no-build \ + ${dotnetInstallFlags[@]} \ + ${dotnetFlags[@]} + } - if [[ "${packNupkg-}" ]]; then + dotnetPack() { + local -r project="${1-}" + env dotnet pack ${project-} \ + -p:ContinuousIntegrationBuild=true \ + -p:Deterministic=true \ + --output "$out/share" \ + --configuration "@buildType@" \ + --no-build \ + ${dotnetPackFlags[@]} \ + ${dotnetFlags[@]} + } + + if (( "${#projectFile[@]}" == 0 )); then + dotnetPublish + else for project in ${projectFile[@]}; do - env \ - dotnet pack "$project" \ - -p:ContinuousIntegrationBuild=true \ - -p:Deterministic=true \ - --output "$out/share" \ - --configuration "@buildType@" \ - --no-build \ - ${dotnetPackFlags[@]} \ - ${dotnetFlags[@]} + dotnetPublish "$project" done fi + if [[ "${packNupkg-}" ]]; then + if (( "${#projectFile[@]}" == 0 )); then + dotnetPack + else + for project in ${projectFile[@]}; do + dotnetPack "$project" + done + fi + fi + runHook postInstall echo "Finished dotnetInstallHook" |