buildDotnetModule: add the option to keep sources to fetch-deps

This commit is contained in:
Ivar Scholten 2022-09-15 21:28:49 +02:00
parent 8e00d6ac26
commit 4a8eb528be
No known key found for this signature in database
GPG key ID: E22887AD87C33E3C

View file

@ -172,37 +172,41 @@ stdenvNoCC.mkDerivation (args // {
export PATH="${lib.makeBinPath [ coreutils dotnet-sdk nuget-to-nix ]}"
case "''${1-}" in
--help|-h)
echo "usage: $0 <output path> [--help]"
echo " <output path> The path to write the lockfile to"
echo " --help Show this help message"
exit
;;
esac
for arg in "$@"; do
case "$arg" in
--keep-sources|-k)
keepSources=1
shift
;;
--help|-h)
echo "usage: $0 <output path> [--keep-sources] [--help]"
echo " <output path> The path to write the lockfile to. A temporary file is used if this is not set"
echo " --keep-sources Dont remove temporary directories upon exit, useful for debugging"
echo " --help Show this help message"
exit
;;
esac
done
deps_file="$(realpath "''${1:-$(mktemp -t "${pname}-deps-XXXXXX.nix")}")"
export HOME=$(mktemp -td "${pname}-home-XXXXXX")
mkdir -p "$HOME/nuget_pkgs"
exitTrap() {
test -n "''${ranTrap-}" && return
ranTrap=1
store_src="${srcOnly args}"
src="$(mktemp -td "${pname}-src-XXXXXX")"
cp -rT "$store_src" "$src"
chmod -R +w "$src"
trap "rm -rf $src $HOME" EXIT
if test -n "''${keepSources-}"; then
echo -e "Path to the source: $src\nPath to the fake home: $HOME"
else
rm -rf "$src" "$HOME"
fi
cd "$src"
echo "Restoring project..."
# Since mktemp is used this will be empty if the script didnt succesfully complete
! test -s "$depsFile" && rm -rf "$depsFile"
}
export DOTNET_NOLOGO=1
export DOTNET_CLI_TELEMETRY_OPTOUT=1
declare -a projectFiles=( ${toString (lib.toList projectFile)} )
declare -a testProjectFiles=( ${toString (lib.toList testProjectFile)} )
trap exitTrap EXIT INT TERM
dotnetRestore() {
local -r project="''${1-}"
local -r rid="''${2-}"
local -r rid="$2"
dotnet restore ''${project-} \
-p:ContinuousIntegrationBuild=true \
@ -213,6 +217,24 @@ stdenvNoCC.mkDerivation (args // {
${lib.optionalString (flags != []) (toString flags)}
}
declare -a projectFiles=( ${toString (lib.toList projectFile)} )
declare -a testProjectFiles=( ${toString (lib.toList testProjectFile)} )
export HOME=$(mktemp -td "${pname}-home-XXXXXX")
export DOTNET_NOLOGO=1
export DOTNET_CLI_TELEMETRY_OPTOUT=1
depsFile="$(realpath "''${1:-$(mktemp -t "${pname}-deps-XXXXXX.nix")}")"
mkdir -p "$HOME/nuget_pkgs"
storeSrc="${srcOnly args}"
src="$(mktemp -td "${pname}-src-XXXXXX")"
cp -rT "$storeSrc" "$src"
chmod -R +w "$src"
cd "$src"
echo "Restoring project..."
for rid in "${lib.concatStringsSep "\" \"" runtimeIds}"; do
(( ''${#projectFiles[@]} == 0 )) && dotnetRestore "" "$rid"
@ -224,9 +246,9 @@ stdenvNoCC.mkDerivation (args // {
echo "Succesfully restored project"
echo "Writing lockfile..."
echo -e "# This file was automatically generated by passthru.fetch-deps.\n# Please dont edit it manually, your changes might get overwritten!\n" > "$deps_file"
nuget-to-nix "$HOME/nuget_pkgs" "${exclusions}" >> "$deps_file"
echo "Succesfully wrote lockfile to: $deps_file"
echo -e "# This file was automatically generated by passthru.fetch-deps.\n# Please dont edit it manually, your changes might get overwritten!\n" > "$depsFile"
nuget-to-nix "$HOME/nuget_pkgs" "${exclusions}" >> "$depsFile"
echo "Succesfully wrote lockfile to $depsFile"
'';
} // args.passthru or { };