about summary refs log tree commit diff
path: root/pkgs/development/compilers/swift/swiftpm/setup-hook.sh
blob: 160fbb1ccca318d7bf3ec567d7b9f31bd9dd0a31 (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
# Build using 'swift-build'.
swiftpmBuildPhase() {
    runHook preBuild

    local buildCores=1
    if [ "${enableParallelBuilding-1}" ]; then
        buildCores="$NIX_BUILD_CORES"
    fi

    local flagsArray=(
        -j $buildCores
        -c "${swiftpmBuildConfig-release}"
        $swiftpmFlags "${swiftpmFlagsArray[@]}"
    )

    echoCmd 'build flags' "${flagsArray[@]}"
    TERM=dumb swift-build "${flagsArray[@]}"

    runHook postBuild
}

if [ -z "${dontUseSwiftpmBuild-}" ] && [ -z "${buildPhase-}" ]; then
    buildPhase=swiftpmBuildPhase
fi

# Check using 'swift-test'.
swiftpmCheckPhase() {
    runHook preCheck

    local buildCores=1
    if [ "${enableParallelBuilding-1}" ]; then
        buildCores="$NIX_BUILD_CORES"
    fi

    local flagsArray=(
        -j $buildCores
        -c "${swiftpmBuildConfig-release}"
        $swiftpmFlags "${swiftpmFlagsArray[@]}"
    )

    echoCmd 'check flags' "${flagsArray[@]}"
    TERM=dumb swift-test "${flagsArray[@]}"

    runHook postCheck
}

if [ -z "${dontUseSwiftpmCheck-}" ] && [ -z "${checkPhase-}" ]; then
    checkPhase=swiftpmCheckPhase
fi

# Helper used to find the binary output path.
# Useful for performing the installPhase of swiftpm packages.
swiftpmBinPath() {
    local flagsArray=(
        -c "${swiftpmBuildConfig-release}"
        $swiftpmFlags "${swiftpmFlagsArray[@]}"
    )

    swift-build --show-bin-path "${flagsArray[@]}"
}