about summary refs log tree commit diff
path: root/pkgs/by-name/sc/scons/setup-hook.sh
blob: bfd8f3cc07b92629740a7403e91d39acb506a83f (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# shellcheck shell=bash disable=SC2206

sconsBuildPhase() {
    runHook preBuild

    if [ -n "$prefix" ]; then
        mkdir -p "$prefix"
    fi

    if [ -z "${dontAddPrefix:-}" ] && [ -n "$prefix" ]; then
        buildFlags="${prefixKey:-prefix=}$prefix $buildFlags"
    fi

    local flagsArray=(
      ${enableParallelBuilding:+-j${NIX_BUILD_CORES}}
      $sconsFlags ${sconsFlagsArray[@]}
      $buildFlags ${buildFlagsArray[@]}
    )

    echoCmd 'scons build flags' "${flagsArray[@]}"
    scons "${flagsArray[@]}"

    runHook postBuild
}

sconsInstallPhase() {
    runHook preInstall

    if [ -n "$prefix" ]; then
        mkdir -p "$prefix"
    fi

    if [ -z "${dontAddPrefix:-}" ] && [ -n "$prefix" ]; then
        installFlags="${prefixKey:-prefix=}$prefix $installFlags"
    fi

    local flagsArray=(
        ${enableParallelInstalling:+-j${NIX_BUILD_CORES}}
        $sconsFlags ${sconsFlagsArray[@]}
        $installFlags ${installFlagsArray[@]}
        ${installTargets:-install}
    )

    echoCmd 'scons install flags' "${flagsArray[@]}"
    scons "${flagsArray[@]}"

    runHook postInstall
}

sconsCheckPhase() {
    runHook preCheck

    if [ -z "${checkTarget:-}" ]; then
        if scons -n check >/dev/null 2>&1; then
            checkTarget="check"
        elif scons -n test >/dev/null 2>&1; then
            checkTarget="test"
        fi
    fi

    if [ -z "${checkTarget:-}" ]; then
        echo "no check/test target found, doing nothing"
    else
        local flagsArray=(
            ${enableParallelChecking:+-j${NIX_BUILD_CORES}}
            $sconsFlags ${sconsFlagsArray[@]}
            ${checkFlagsArray[@]}
        )

        echoCmd 'scons check flags' "${flagsArray[@]}"
        scons "${flagsArray[@]}"
    fi

    runHook postCheck
}

if [ -z "${dontUseSconsBuild-}" ] && [ -z "${buildPhase-}" ]; then
    buildPhase=sconsBuildPhase
fi

if [ -z "${dontUseSconsCheck-}" ] && [ -z "${checkPhase-}" ]; then
    checkPhase=sconsCheckPhase
fi

if [ -z "${dontUseSconsInstall-}" ] && [ -z "${installPhase-}" ]; then
    installPhase=sconsInstallPhase
fi