-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinstall_kcov.sh
executable file
·50 lines (43 loc) · 1.66 KB
/
install_kcov.sh
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
#!/bin/bash
set -euxo pipefail
command_exists() {
command -v "$1" &> /dev/null
}
CARGO_HOME=${CARGO_HOME:-${HOME}/.cargo}
KCOV_DEFAULT_VERSION="v36"
GITHUB_KCOV="https://api.github.com/repos/SimonKagstrom/kcov/releases/latest"
# Usage: download and install the latest kcov version by default.
# Fall back to ${KCOV_DEFAULT_VERSION} from the kcov archive if the latest is unavailable.
KCOV_VERSION=$(curl --silent --show-error --fail ${GITHUB_KCOV} | jq -Mr .tag_name || echo)
KCOV_VERSION=${KCOV_VERSION:-$KCOV_DEFAULT_VERSION}
KCOV_TGZ="https://github.com/SimonKagstrom/kcov/archive/${KCOV_VERSION}.tar.gz"
rm -rf "kcov-${KCOV_VERSION}/"
mkdir "kcov-${KCOV_VERSION}"
curl -L --retry 3 "${KCOV_TGZ}" | tar xzvf - -C "kcov-${KCOV_VERSION}" --strip-components 1
num_proc=1
# If PARALLEL_BUILD environment variable is set then parallel build is enabled
if [ "${PARALLEL_BUILD:-}" != "" ]; then
# If PARALLEL_BUILD content is a number then use it as number of parallel jobs
if [ -n "${PARALLEL_BUILD##*[!0-9]*}" ]; then
num_proc=${PARALLEL_BUILD}
else
# Try to determine the number of available CPUs
if command_exists nproc; then
num_proc=$(nproc)
elif command_exists sysctl; then
num_proc=$(sysctl -n hw.ncpu)
fi
fi
fi
cd "kcov-${KCOV_VERSION}"
mkdir build
cd build
if [ "$(uname)" = Darwin ]; then
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -GXcode ..
xcodebuild -configuration Release
cp src/Release/kcov src/Release/libkcov_system_lib.so "${CARGO_HOME}/bin"
else
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
make -j "${num_proc}"
cp src/kcov src/libkcov_sowrapper.so "${CARGO_HOME}/bin"
fi