forked from avengineers/SPLed
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·240 lines (206 loc) · 6.79 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·240 lines (206 loc) · 6.79 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/bin/bash
# SPLed build script for Linux/Unix systems.
# Linux counterpart of the Windows PowerShell build.ps1: installs dependencies,
# builds variants via CMake/Ninja and runs the pytest self tests.
set -e
set -o pipefail
# Default values
INSTALL=false
BUILD=false
CLEAN=false
SELFTESTS=false
RECONFIGURE=false
BUILD_KIT="prod"
BUILD_TYPE=""
TARGET="all"
VARIANT=""
MARKER="gate_develop_push"
FILTER=""
COMMAND=""
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
show_help() {
cat << EOF
SPLed build script
Usage: $0 [OPTIONS]
Options:
--install Install Python dependencies (creates .venv via Poetry)
--build Build the project
--clean Clean build artifacts (and .venv when combined with --install)
--selftests Run the pytest self tests
--build-kit <kit> Build kit: 'prod' or 'test' (default: prod)
--build-type <type> Build type (Debug, Release, ...)
--target <target> Build target (default: all)
--variant <variant> Variant to build (default: Disco)
--marker <marker> pytest marker for --selftests (default: gate_develop_push)
--filter <expr> pytest -k filter expression for --selftests
--reconfigure Delete CMake cache and reconfigure
--command <cmd> Command to execute in the environment
--help Show this help message
Examples:
$0 --install
$0 --build --variant Disco
$0 --build --build-kit test --build-type Debug --variant Sleep
$0 --clean --build --variant Spa
$0 --selftests --marker gate_develop_pr
EOF
}
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--install) INSTALL=true; shift ;;
--build) BUILD=true; shift ;;
--clean) CLEAN=true; shift ;;
--selftests) SELFTESTS=true; shift ;;
--reconfigure) RECONFIGURE=true; shift ;;
--build-kit) BUILD_KIT="$2"; shift 2 ;;
--build-type) BUILD_TYPE="$2"; shift 2 ;;
--target) TARGET="$2"; shift 2 ;;
--variant) VARIANT="$2"; shift 2 ;;
--marker) MARKER="$2"; shift 2 ;;
--filter) FILTER="$2"; shift 2 ;;
--command) COMMAND="$2"; shift 2 ;;
--help) show_help; exit 0 ;;
*)
echo "Unknown option $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
cd "$SCRIPT_DIR"
echo "SPLed build script"
echo "Working directory: $(pwd)"
# Resolve the interpreter from the in-project virtual environment when present.
venv_python() {
if [ -x ".venv/bin/python" ]; then
echo ".venv/bin/python"
else
echo ""
fi
}
# Remove a file or directory if it exists.
remove_path() {
local path="$1"
if [ -e "$path" ]; then
echo "Deleting '$path' ..."
rm -rf "$path"
fi
}
install_dependencies() {
echo "Installing dependencies ..."
if ! command -v poetry &> /dev/null; then
echo "Error: Poetry not found. Please install Poetry first: https://python-poetry.org/docs/#installation"
exit 1
fi
# Keep the virtual environment inside the project (.venv) to match build.ps1.
poetry config virtualenvs.in-project true --local &> /dev/null || true
poetry install
# Provision the OS-independent toolchain (gcc/clang/cmake/ninja) via poks and
# generate build/env_setup.sh. This runs the same pypeline pipeline as Windows;
# the Windows-only ScoopInstall step self-skips on Linux/macOS.
echo "Provisioning toolchain via poks (pypeline) ..."
poetry run pypeline run
echo "Dependencies installed successfully."
}
# Put the poks-provisioned tools (compilers, cmake, ninja) on PATH by sourcing the
# env setup script generated by pypeline's GenerateEnvSetupScript step.
load_env_setup() {
if [ -f "build/env_setup.sh" ]; then
echo "Loading poks environment from build/env_setup.sh ..."
# shellcheck disable=SC1091
source "build/env_setup.sh"
fi
}
build_variant() {
if [ -z "$VARIANT" ]; then
VARIANT="Disco"
fi
local build_dir="build/$VARIANT/$BUILD_KIT"
if [ -n "$BUILD_TYPE" ]; then
build_dir="build/$VARIANT/$BUILD_KIT/$BUILD_TYPE"
fi
echo "Building variant '$VARIANT' (kit '$BUILD_KIT') into '$build_dir' ..."
mkdir -p "$build_dir"
if [ "$RECONFIGURE" = true ]; then
echo "Deleting CMake cache for reconfiguration ..."
rm -f "$build_dir/CMakeCache.txt"
rm -rf "$build_dir/CMakeFiles"
fi
local cmake_args=("-DVARIANT=$VARIANT" "-DBUILD_KIT=$BUILD_KIT")
if [ -n "$BUILD_TYPE" ]; then
cmake_args+=("-DBUILD_TYPE=$BUILD_TYPE" "-DCMAKE_BUILD_TYPE=$BUILD_TYPE")
fi
if [ "$BUILD_KIT" = "test" ]; then
cmake_args+=("-DCMAKE_TOOLCHAIN_FILE=tools/toolchains/gcc/toolchain_linux.cmake")
fi
echo "Configuring with CMake ..."
if command -v ninja &> /dev/null; then
cmake -B "$build_dir" -G Ninja "${cmake_args[@]}"
else
cmake -B "$build_dir" "${cmake_args[@]}"
fi
echo "Building target '$TARGET' ..."
if [ -n "$BUILD_TYPE" ]; then
cmake --build "$build_dir" --config "$BUILD_TYPE" --target "$TARGET"
else
cmake --build "$build_dir" --target "$TARGET"
fi
echo "Build completed successfully."
}
run_selftests() {
echo "Running self tests (marker '$MARKER') ..."
local junit_xml="test/output/test-report.xml"
remove_path "$junit_xml"
local pytest_args=("--junitxml=$junit_xml")
if [ -n "$FILTER" ]; then
pytest_args+=("-k" "$FILTER")
fi
if [ -n "$MARKER" ]; then
pytest_args+=("-m" "$MARKER")
fi
# Do not abort the script on test failures; the JUnit report is evaluated by CI.
local python
python="$(venv_python)"
if [ -n "$python" ]; then
"$python" -m pytest "${pytest_args[@]}" || true
elif command -v poetry &> /dev/null; then
poetry run pytest "${pytest_args[@]}" || true
else
pytest "${pytest_args[@]}" || true
fi
echo "Self tests completed."
}
# --- main ---------------------------------------------------------------------
if [ "$CLEAN" = true ]; then
echo "Cleaning ..."
if [ "$INSTALL" = true ]; then
remove_path ".venv"
fi
if [ "$SELFTESTS" = true ]; then
remove_path "build"
elif [ "$BUILD" = true ]; then
if [ -n "$VARIANT" ]; then
remove_path "build/$VARIANT"
else
remove_path "build"
fi
fi
fi
if [ "$INSTALL" = true ]; then
install_dependencies
fi
# Make the poks-provisioned toolchain available for building and testing.
if [ "$BUILD" = true ] || [ "$SELFTESTS" = true ]; then
load_env_setup
fi
if [ "$BUILD" = true ]; then
build_variant
fi
if [ "$SELFTESTS" = true ]; then
run_selftests
fi
if [ -n "$COMMAND" ]; then
echo "Executing command: $COMMAND"
eval "$COMMAND"
fi
echo "Script completed successfully."