summary refs log tree commit diff
path: root/pkgs/development/tools/build-managers/scons/setup-hook.sh
blob: 55159aa5a93aa1bdd85e06d47a7bb276abbe0c4c (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
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 '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=(
        $sconsFlags ${sconsFlagsArray[@]}
        $installFlags ${installFlagsArray[@]}
        ${installTargets:-install}
    )

    echoCmd '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 'check flags' "${flagsArray[@]}"
        scons "${flagsArray[@]}"
    fi

    runHook postCheck
}

if [ -z "$buildPhase" ]; then
    buildPhase=sconsBuildPhase
fi

if [ -z "$dontUseSconsInstall" -a -z "$installPhase" ]; then
    installPhase=sconsInstallPhase
fi

if [ -z "$checkPhase" ]; then
    checkPhase=sconsCheckPhase
fi