diff options
author | Ivar Scholten <ivar.scholten@protonmail.com> | 2022-09-15 21:28:49 +0200 |
---|---|---|
committer | Ivar Scholten <ivar.scholten@protonmail.com> | 2022-09-18 18:02:03 +0200 |
commit | 4a8eb528bee9c9b76f5b3400b684bdb6ac83661e (patch) | |
tree | cb5075c504d7838f0a92b0c1c8bc2245dae9d410 /pkgs/build-support | |
parent | 8e00d6ac269e87705141f817f619d82cf45b6e24 (diff) | |
download | nixlib-4a8eb528bee9c9b76f5b3400b684bdb6ac83661e.tar nixlib-4a8eb528bee9c9b76f5b3400b684bdb6ac83661e.tar.gz nixlib-4a8eb528bee9c9b76f5b3400b684bdb6ac83661e.tar.bz2 nixlib-4a8eb528bee9c9b76f5b3400b684bdb6ac83661e.tar.lz nixlib-4a8eb528bee9c9b76f5b3400b684bdb6ac83661e.tar.xz nixlib-4a8eb528bee9c9b76f5b3400b684bdb6ac83661e.tar.zst nixlib-4a8eb528bee9c9b76f5b3400b684bdb6ac83661e.zip |
buildDotnetModule: add the option to keep sources to fetch-deps
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/dotnet/build-dotnet-module/default.nix | 76 |
1 files changed, 49 insertions, 27 deletions
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/default.nix index 41f3271f10cc..b65aecd7e05c 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/default.nix +++ b/pkgs/build-support/dotnet/build-dotnet-module/default.nix @@ -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 - - deps_file="$(realpath "''${1:-$(mktemp -t "${pname}-deps-XXXXXX.nix")}")" - export HOME=$(mktemp -td "${pname}-home-XXXXXX") - mkdir -p "$HOME/nuget_pkgs" + 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 - 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 + exitTrap() { + test -n "''${ranTrap-}" && return + ranTrap=1 - cd "$src" - echo "Restoring project..." + if test -n "''${keepSources-}"; then + echo -e "Path to the source: $src\nPath to the fake home: $HOME" + else + rm -rf "$src" "$HOME" + fi - export DOTNET_NOLOGO=1 - export DOTNET_CLI_TELEMETRY_OPTOUT=1 + # Since mktemp is used this will be empty if the script didnt succesfully complete + ! test -s "$depsFile" && rm -rf "$depsFile" + } - 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 { }; |