about summary refs log tree commit diff
path: root/nixpkgs/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh
blob: 4fec939bed33f8cf4d1b7b26dcb2f94dd1981bfc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Inherit arguments from the derivation
declare -a derivationMakeWrapperArgs="( ${makeWrapperArgs-} )"
makeWrapperArgs=( "${derivationMakeWrapperArgs[@]}" )

# First argument is the executable you want to wrap,
# the second is the destination for the wrapper.
wrapDotnetProgram() {
    local dotnetRootFlags=()

    if [ ! "${selfContainedBuild-}" ]; then
        if [ "${useDotnetFromEnv-}" ]; then
            # if dotnet CLI is available, set DOTNET_ROOT based on it. Otherwise set to default .NET runtime
            dotnetRootFlags+=("--run" 'command -v dotnet &>/dev/null && export DOTNET_ROOT="$(@dirname@ "$(@realpath@ "$(@which@ dotnet)")")" || export DOTNET_ROOT="@dotnetRuntime@"')
            dotnetRootFlags+=("--suffix" "PATH" ":" "@dotnetRuntime@/bin")
        else
            dotnetRootFlags+=("--set" "DOTNET_ROOT" "@dotnetRuntime@")
            dotnetRootFlags+=("--prefix" "PATH" ":" "@dotnetRuntime@/bin")
        fi
    fi

    makeWrapper "$1" "$2" \
        --suffix "LD_LIBRARY_PATH" : "@runtimeDeps@" \
        "${dotnetRootFlags[@]}" \
        "${gappsWrapperArgs[@]}" \
        "${makeWrapperArgs[@]}"

    echo "installed wrapper to "$2""
}

dotnetFixupHook() {
    echo "Executing dotnetFixupPhase"

    if [ "${executables-}" ]; then
        for executable in ${executables[@]}; do
            path="$out/lib/$pname/$executable"

            if test -x "$path"; then
                wrapDotnetProgram "$path" "$out/bin/$(basename "$executable")"
            else
                echo "Specified binary \"$executable\" is either not an executable or does not exist!"
                echo "Looked in $path"
                exit 1
            fi
        done
    else
        while IFS= read -d '' executable; do
            wrapDotnetProgram "$executable" "$out/bin/$(basename "$executable")" \;
        done < <(find "$out/lib/$pname" ! -name "*.dll" -executable -type f -print0)
    fi

    echo "Finished dotnetFixupPhase"
}

if [[ -z "${dontDotnetFixup-}" ]]; then
    preFixupPhases+=" dotnetFixupHook"
fi