nuget-package-hook: move package unpacking from buildDotnetModule

This commit is contained in:
David McFarland 2024-09-08 00:40:47 -03:00
parent c1ee815d03
commit b1685747a7
4 changed files with 42 additions and 22 deletions

View File

@ -8,8 +8,6 @@
makeWrapper,
dotnetCorePackages,
cacert,
unzip,
yq,
addNuGetDeps,
}:
let
@ -149,8 +147,6 @@ let
cacert
makeWrapper
dotnet-sdk
unzip
yq
];
buildInputs =

View File

@ -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"

View File

@ -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

View File

@ -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