#! @runtimeShell@ # shellcheck shell=bash set -euo pipefail export PATH="@path@" for arg in "$@"; do case "$arg" in --keep-sources|-k) keepSources=1 shift ;; --help|-h) echo "usage: $0 [--keep-sources] [--help] " echo " 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 if [[ ${TMPDIR:-} == /run/user/* ]]; then # /run/user is usually a tmpfs in RAM, which may be too small # to store all downloaded dotnet packages unset TMPDIR fi export tmp=$(mktemp -td "deps-@pname@-XXXXXX") HOME=$tmp/home exitTrap() { test -n "${ranTrap-}" && return ranTrap=1 if test -n "${keepSources-}"; then echo -e "Path to the source: $tmp/src\nPath to the fake home: $tmp/home" else rm -rf "$tmp" fi # Since mktemp is used this will be empty if the script didnt succesfully complete if ! test -s "$depsFile"; then rm -rf "$depsFile" fi } trap exitTrap EXIT INT TERM dotnetRestore() { local -r project="${1-}" local -r rid="$2" dotnet restore ${project-} \ -p:ContinuousIntegrationBuild=true \ -p:Deterministic=true \ --packages "$tmp/nuget_pkgs" \ --runtime "$rid" \ --no-cache \ --force \ @disableParallel@ \ @flags@ } declare -a projectFiles=( @projectFileStr@ ) declare -a testProjectFiles=( @testProjectFileStr@ ) export DOTNET_NOLOGO=1 export DOTNET_CLI_TELEMETRY_OPTOUT=1 depsFile=$(realpath "${1:-@defaultDepsFile@}") echo Will write lockfile to "$depsFile" mkdir -p "$tmp/nuget_pkgs" storeSrc="@storeSrc@" src=$tmp/src cp -rT "$storeSrc" "$src" chmod -R +w "$src" cd "$src" echo "Restoring project..." "@dotnetSdkPath@/bin/dotnet" tool restore cp -r $HOME/.nuget/packages/* $tmp/nuget_pkgs || true runtimeIds=(@runtimeIds@) for rid in "${runtimeIds[@]}"; do (( ${#projectFiles[@]} == 0 )) && dotnetRestore "" "$rid" for project in ${projectFiles[@]-} ${testProjectFiles[@]-}; do dotnetRestore "$project" "$rid" done done # Second copy, makes sure packages restored by ie. paket are included cp -r $HOME/.nuget/packages/* $tmp/nuget_pkgs || true echo "Succesfully restored project" echo "Writing lockfile..." excluded_sources=( @excludedSources@ ) for excluded_source in ${excluded_sources[@]}; do ls "$excluded_source" >> "$tmp/excluded_list" done tmpFile="$tmp"/deps.nix echo -e "# This file was automatically generated by passthru.fetch-deps.\n# Please dont edit it manually, your changes might get overwritten!\n" > "$tmpFile" nuget-to-nix "$tmp/nuget_pkgs" "$tmp/excluded_list" >> "$tmpFile" mv "$tmpFile" "$depsFile" echo "Succesfully wrote lockfile to $depsFile"