Skip to content

Commit f659219

Browse files
committed
Add helper functions for warning and info, simplify error handling
1 parent e9d2ce3 commit f659219

File tree

1 file changed

+49
-36
lines changed

1 file changed

+49
-36
lines changed

scripts/gitlab/build_and_test.sh

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ print_error ()
5555
echo -e "\e[31m[Error]: ${error_msg}\e[0m"
5656
}
5757

58+
# Helper function to print warnings in gray
59+
print_warning ()
60+
{
61+
local warning_msg="${1}"
62+
echo -e "\e[1;30m[Warning]: ${warning_msg}\e[0m"
63+
}
64+
65+
# Helper function to print information
66+
print_info ()
67+
{
68+
local info_msg="${1}"
69+
echo -e "[Information]: ${info_msg}"
70+
}
71+
5872
# GitLab CI collapsible section helpers with nesting support
5973
section_start ()
6074
{
@@ -127,18 +141,18 @@ section_end ()
127141

128142
if [[ ${debug_mode} == true ]]
129143
then
130-
echo "[Information]: Debug mode:"
131-
echo "[Information]: - Spack debug mode."
132-
echo "[Information]: - Deactivated shared memory."
133-
echo "[Information]: - Do not push to buildcache."
144+
print_info "Debug mode:"
145+
print_info "- Spack debug mode."
146+
print_info "- Deactivated shared memory."
147+
print_info "- Do not push to buildcache."
134148
use_dev_shm=false
135149
spack_debug=true
136150
push_to_registry=false
137151
fi
138152

139153
if [[ -n ${module_list} ]]
140154
then
141-
echo "[Information]: Loading modules: ${module_list}"
155+
print_info "Loading modules: ${module_list}"
142156
module load ${module_list}
143157
fi
144158

@@ -161,8 +175,8 @@ else
161175
prefix="${project_dir}/../spack-and-build-root"
162176
fi
163177

164-
echo "[Information]: Creating directory ${prefix}"
165-
echo "[Information]: project_dir: ${project_dir}"
178+
print_info "Creating directory ${prefix}"
179+
print_info "project_dir: ${project_dir}"
166180

167181
mkdir -p ${prefix}
168182

@@ -249,7 +263,7 @@ else
249263
fi
250264

251265
hostconfig=$(basename ${hostconfig_path})
252-
echo "[Information]: Found hostconfig ${hostconfig_path}"
266+
print_info "Found hostconfig ${hostconfig_path}"
253267

254268
# Build Directory
255269
# When using /dev/shm, we use prefix for both spack builds and source build, unless BUILD_ROOT was defined
@@ -263,11 +277,11 @@ cmake_exe=`grep 'CMake executable' ${hostconfig_path} | cut -d ':' -f 2 | xargs`
263277
# Build
264278
if [[ "${option}" != "--deps-only" && "${option}" != "--test-only" ]]
265279
then
266-
echo "[Information]: Prefix ${prefix}"
267-
echo "[Information]: Host-config ${hostconfig_path}"
268-
echo "[Information]: Build Dir ${build_dir}"
269-
echo "[Information]: Project Dir ${project_dir}"
270-
echo "[Information]: Install Dir ${install_dir}"
280+
print_info "Prefix ${prefix}"
281+
print_info "Host-config ${hostconfig_path}"
282+
print_info "Build Dir ${build_dir}"
283+
print_info "Project Dir ${project_dir}"
284+
print_info "Install Dir ${install_dir}"
271285

272286
section_start "clean" "Cleaning working directory" "collapsed"
273287
# Map CPU core allocations
@@ -297,44 +311,43 @@ then
297311
-DCMAKE_INSTALL_PREFIX=${install_dir} \
298312
${project_dir}
299313
then
314+
status=$?
300315
section_end
301316
print_error "CMake configuration failed, dumping output..."
302-
section_start "cmake_config_verbose" "Verbose CMake Configuration"
303-
if ! $cmake_exe \
317+
318+
$cmake_exe \
304319
-C ${hostconfig_path} \
305320
${cmake_options} \
306321
-DCMAKE_INSTALL_PREFIX=${install_dir} \
307322
${project_dir} --debug-output --trace-expand
308-
then
309-
verbose_status=$?
310-
section_end
311-
exit ${verbose_status}
312-
fi
313-
section_end
314-
exit 1
315-
else
316-
section_end
323+
324+
exit ${status}
317325
fi
326+
section_end
318327

319328
section_start "build" "Building Umpire" "collapsed"
320329
if ! $cmake_exe --build . -j ${core_counts[$truehostname]}
321330
then
331+
status=$?
322332
section_end
323333
print_error "Compilation failed, building with verbose output..."
324-
section_start "build_verbose" "Verbose Rebuild" "collapsed"
334+
325335
$cmake_exe --build . --verbose -j 1
336+
337+
exit ${status}
338+
fi
339+
section_end
340+
341+
section_start "install" "Installing Umpire" "collapsed"
342+
if ! $cmake_exe --install .
343+
then
344+
status=$?
326345
section_end
327-
else
328-
section_end
329-
section_start "install" "Installing Umpire" "collapsed"
330-
if ! $cmake_exe --install .
331-
then
332-
section_end
333-
print_error "Installation failed."
334-
exit 1
335-
fi
336-
section_end
346+
print_error "Installation failed."
347+
348+
exit ${status}
337349
fi
350+
section_end
338351
fi
339352

340353
# Test
@@ -389,8 +402,8 @@ then
389402
section_start "install_test" "Testing Installed Examples" "collapsed"
390403
if grep -q -i "ENABLE_HIP.*ON" ${hostconfig_path}
391404
then
392-
echo "[Warning]: Not testing install with HIP"
393405
section_end
406+
echo "[Warning]: Not testing install with HIP"
394407
else
395408
if [[ ! -d ${install_dir} ]]
396409
then

0 commit comments

Comments
 (0)