-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild_linux.sh
More file actions
executable file
·176 lines (158 loc) · 6.39 KB
/
Copy pathbuild_linux.sh
File metadata and controls
executable file
·176 lines (158 loc) · 6.39 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env bash
set -euo pipefail
COVERAGE=false
BUILD_PYTHON=false
BUILD_BENCHMARKS=false
GENERATE=false
PYTHON_REQUESTED=false
PYTHON_VERSION=""
SUPPORTED_PYTHONS="3.9, 3.10, 3.11, 3.12, 3.13"
while [[ $# -gt 0 ]]; do
case "$1" in
--coverage) COVERAGE=true ;;
--full) BUILD_PYTHON=true; BUILD_BENCHMARKS=true ;;
--benchmarks) BUILD_BENCHMARKS=true ;;
--generate) GENERATE=true ;;
--python)
PYTHON_REQUESTED=true
BUILD_PYTHON=true
if [[ $# -lt 2 ]]; then
echo "--python requires one of $SUPPORTED_PYTHONS" >&2
exit 1
fi
PYTHON_VERSION=$2
shift
;;
*) echo "Unknown option: $1" >&2; exit 1 ;;
esac
shift
done
if [[ $PYTHON_REQUESTED == true ]]; then
case "$PYTHON_VERSION" in
3.9|3.10|3.11|3.12|3.13) ;;
*)
echo "--python: unsupported value '$PYTHON_VERSION'; expected one of $SUPPORTED_PYTHONS" >&2
exit 1
;;
esac
fi
DAL_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
BUILD_TYPE=${BUILD_TYPE:-Release}
PRESET="${BUILD_TYPE}-linux"
BUILD_DIR=${DAL_BUILD_DIR:-"$DAL_DIR/build/$PRESET"}
INSTALL_DIR=${DAL_INSTALL_DIR:-"$DAL_DIR/build/stage/$PRESET"}
NUM_CORES=${NUM_CORES:-$(nproc)}
if [[ "${ADDITIONAL_CMAKE_FLAGS:-}" =~ DAL_BUILD_PYTHON=(ON|on|TRUE|true|1) ]]; then
BUILD_PYTHON=true
fi
if [[ "${ADDITIONAL_CMAKE_FLAGS:-}" =~ DAL_CPP_BUILD_BENCHMARKS=(ON|on|TRUE|true|1) ]]; then
BUILD_BENCHMARKS=true
fi
cmake_flags=(
"-DUSE_COVERAGE=$COVERAGE"
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
"-DDAL_BUILD_PUBLIC=ON"
"-DDAL_CPP_BUILD_EXAMPLES=ON"
"-DDAL_CPP_BUILD_BENCHMARKS=$([[ $BUILD_BENCHMARKS == true ]] && echo ON || echo OFF)"
"-DDAL_BUILD_PYTHON=$([[ $BUILD_PYTHON == true ]] && echo ON || echo OFF)"
)
if [[ -n "${ADDITIONAL_CMAKE_FLAGS:-}" ]]; then
# Preserve the existing CI/user override contract. Values containing spaces
# should be supplied through a CMake cache or a preset instead.
read -r -a additional_flags <<< "$ADDITIONAL_CMAKE_FLAGS"
cmake_flags+=("${additional_flags[@]}")
fi
if [[ $BUILD_PYTHON == true ]]; then
venv_dir="$DAL_DIR/dal-python/.venv"
python_bin="$venv_dir/bin/python"
compat_script="$DAL_DIR/dal-python/scripts/python_compat.py"
remediation="remove or replace $venv_dir, then rerun"
compat_args=(
--entry-point build_linux.sh
--environment "$venv_dir"
--remediation "$remediation"
)
if [[ $PYTHON_REQUESTED == true ]]; then
compat_args+=(--requested "$PYTHON_VERSION")
fi
if [[ ! -x "$python_bin" ]]; then
if [[ -e "$venv_dir" ]]; then
echo "build_linux.sh: environment '$venv_dir' has no executable Python; $remediation" >&2
exit 1
fi
if command -v uv >/dev/null 2>&1; then
if [[ $PYTHON_REQUESTED == true ]]; then
uv venv "$venv_dir" --python "$PYTHON_VERSION"
else
uv venv "$venv_dir" --python ">=3.9,<3.14"
fi
elif command -v python3 >/dev/null 2>&1; then
python3 "$compat_script" "${compat_args[@]}"
python3 -m venv "$venv_dir"
else
echo "Python bindings requested, but neither uv nor python3 is available." >&2
exit 1
fi
fi
"$python_bin" "$compat_script" "${compat_args[@]}"
if ! "$python_bin" -c "import numpy, pytest" >/dev/null 2>&1; then
if command -v uv >/dev/null 2>&1; then
uv pip install --python "$python_bin" "numpy>=1.24" "pytest>=7.0"
else
"$python_bin" -m pip install "numpy>=1.24" "pytest>=7.0"
fi
fi
export PATH="$venv_dir/bin:$PATH"
cmake_flags+=("-DPython3_EXECUTABLE=$python_bin")
fi
echo "Build type: $BUILD_TYPE"
echo "Build directory: $BUILD_DIR"
echo "Install prefix: $INSTALL_DIR"
echo "Parallel jobs: $NUM_CORES"
echo "Coverage: $COVERAGE"
echo "Python: $BUILD_PYTHON"
echo "Benchmarks: $BUILD_BENCHMARKS"
cmake --preset "$PRESET" -S "$DAL_DIR" -B "$BUILD_DIR" "${cmake_flags[@]}"
if [[ $GENERATE == true ]]; then
cmake --build "$BUILD_DIR" --target dal_generate --parallel "$NUM_CORES"
fi
cmake --build "$BUILD_DIR" --parallel "$NUM_CORES"
canonical_root=$(realpath -m "$DAL_DIR")
canonical_install=$(realpath -m "$INSTALL_DIR")
case "$canonical_install" in
"$canonical_root"/build/*) rm -rf -- "$canonical_install" ;;
*) echo "Leaving custom install prefix in place: $canonical_install" ;;
esac
cmake --install "$BUILD_DIR" --prefix "$INSTALL_DIR"
# Benchmarks are registered as CTest tests (label "benchmark") so CI can discover
# them; never run them in the default test pass, even under --benchmarks/--full.
ctest_flags=(--test-dir "$BUILD_DIR" --output-on-failure -LE benchmark)
if [[ "${VERBOSE:-0}" == "1" ]]; then
ctest_flags+=(--verbose)
fi
ctest "${ctest_flags[@]}"
if [[ $COVERAGE == true ]]; then
echo "Generating coverage report..."
if command -v llvm-cov >/dev/null 2>&1 && [[ -f "$BUILD_DIR/default.profraw" ]]; then
llvm-profdata merge -sparse "$BUILD_DIR/default.profraw" -o "$BUILD_DIR/default.profdata"
test_binary=$(find "$BUILD_DIR" -type f -name dal_cpp_tests -print -quit)
llvm-cov report \
--ignore-filename-regex="(externals|tests|build|/usr/)" \
"$test_binary" -instr-profile="$BUILD_DIR/default.profdata"
elif command -v gcovr >/dev/null 2>&1; then
gcovr -r "$DAL_DIR" --object-directory="$BUILD_DIR" \
-e "externals" -e "tests" -e "build" \
--print-summary --sort-percentage --decisions
elif command -v lcov >/dev/null 2>&1; then
lcov --capture --directory "$BUILD_DIR" --output-file "$DAL_DIR/coverage.info" \
--rc lcov_branch_coverage=1 --ignore-errors mismatch,gcov,empty,source,negative
lcov --remove "$DAL_DIR/coverage.info" '*/externals/*' '*/tests/*' '*/build/*' '*/auto/*' '/usr/*' \
--output-file "$DAL_DIR/coverage_filtered.info" --ignore-errors empty,unused
genhtml "$DAL_DIR/coverage_filtered.info" --output-directory "$DAL_DIR/coverage" \
--branch-coverage --ignore-errors empty,corrupt
echo "HTML report saved to $DAL_DIR/coverage/index.html"
else
echo "No coverage tool found (llvm-cov, gcovr, or lcov)."
fi
fi
echo "Finished building Derivatives Algorithms Library"