From b1685747a7982e70090a9844089d69eb387b203c Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 8 Sep 2024 00:40:47 -0300 Subject: [PATCH] nuget-package-hook: move package unpacking from buildDotnetModule --- .../dotnet/build-dotnet-module/default.nix | 4 -- .../hooks/dotnet-install-hook.sh | 18 +-------- .../compilers/dotnet/nuget-package-hook.nix | 4 +- .../compilers/dotnet/nuget-package-hook.sh | 38 +++++++++++++++++++ 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/pkgs/build-support/dotnet/build-dotnet-module/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/default.nix index 34bac2c03686..b9f7a2ff724b 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/default.nix +++ b/pkgs/build-support/dotnet/build-dotnet-module/default.nix @@ -8,8 +8,6 @@ makeWrapper, dotnetCorePackages, cacert, - unzip, - yq, addNuGetDeps, }: let @@ -149,8 +147,6 @@ let cacert makeWrapper dotnet-sdk - unzip - yq ]; buildInputs = 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 73d2863419a2..cdd4a50f5d2e 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 @@ -62,8 +62,6 @@ dotnetInstallHook() { done } - local -r pkgs=$PWD/.nuget-pack - dotnetPack() { local -r projectFile="${1-}" @@ -73,7 +71,7 @@ dotnetInstallHook() { -p:ContinuousIntegrationBuild=true \ -p:Deterministic=true \ -p:OverwriteReadOnlyFiles=true \ - --output "$pkgs" \ + --output "$out/share/nuget/source" \ --configuration "$dotnetBuildType" \ --no-build \ --runtime "$runtimeId" \ @@ -102,20 +100,6 @@ dotnetInstallHook() { fi fi - local -r unpacked="$pkgs/.unpacked" - for nupkg in "$pkgs"/*.nupkg; do - rm -rf "$unpacked" - unzip -qd "$unpacked" "$nupkg" - chmod -R +rw "$unpacked" - echo {} > "$unpacked"/.nupkg.metadata - local id version - id=$(xq -r '.package.metadata.id|ascii_downcase' "$unpacked"/*.nuspec) - version=$(xq -r '.package.metadata.version|ascii_downcase' "$unpacked"/*.nuspec) - mkdir -p "$out/share/nuget/packages/$id" - mv "$unpacked" "$out/share/nuget/packages/$id/$version" - # TODO: should we fix executable flags here? - done - runHook postInstall echo "Finished dotnetInstallHook" diff --git a/pkgs/development/compilers/dotnet/nuget-package-hook.nix b/pkgs/development/compilers/dotnet/nuget-package-hook.nix index 4fe926b4684e..1d00e1d781a1 100644 --- a/pkgs/development/compilers/dotnet/nuget-package-hook.nix +++ b/pkgs/development/compilers/dotnet/nuget-package-hook.nix @@ -1,12 +1,14 @@ { makeSetupHook, + unzip, zip, + xmlstarlet, strip-nondeterminism, }: makeSetupHook { name = "nuget-package-hook"; substitutions = { - inherit zip; + inherit unzip zip xmlstarlet; stripNondeterminism = strip-nondeterminism; }; } ./nuget-package-hook.sh diff --git a/pkgs/development/compilers/dotnet/nuget-package-hook.sh b/pkgs/development/compilers/dotnet/nuget-package-hook.sh index 2bb79a0150cb..8f82f9bf4505 100644 --- a/pkgs/development/compilers/dotnet/nuget-package-hook.sh +++ b/pkgs/development/compilers/dotnet/nuget-package-hook.sh @@ -1,5 +1,43 @@ # shellcheck shell=bash disable=SC2154 +_unpackNugetPackagesInOutput() { + local -r unpacked="$prefix"/share/nuget/packages/.unpacked + ( + shopt -s nullglob globstar + for nupkg in "$prefix"/share/nuget/source/**/*.nupkg; do + mkdir -p "$unpacked" + @unzip@/bin/unzip -qd "$unpacked" "$nupkg" + chmod -R +rw "$unpacked" + echo {} > "$unpacked"/.nupkg.metadata + @xmlstarlet@/bin/xmlstarlet \ + sel -t \ + -m /_:package/_:metadata \ + -v _:id -nl \ + -v _:version -nl \ + "$unpacked"/*.nuspec | ( + read id + read version + id=''${id,,} + version=''${version,,} + mkdir -p "$prefix"/share/nuget/packages/"$id" + mv "$unpacked" "$prefix"/share/nuget/packages/"$id"/"$version" + ) + done + rm -rf "$prefix"/share/nuget/source + ) +} + +unpackNugetPackages() { + local output + for output in $(getAllOutputNames); do + prefix="${!output}" _unpackNugetPackagesInOutput + done +} + +if [[ -z ${dontUnpackNugetPackages-} ]]; then + preFixupHooks+=(unpackNugetPackages) +fi + _createNugetSourceInOutput() { local package version id dir nupkg content local -a nuspec