|
| 1 | +# Off-CI CDash submission script for h5cpp. |
| 2 | +# Invoked via: ctest -S scripts/CTestDashboard.cmake [options] -VV |
| 3 | +# or via the wrapper: scripts/cdash [KEY=value ...] |
| 4 | +# |
| 5 | +# Overridable variables (pass as -DKEY=value or KEY=value to the wrapper): |
| 6 | +# BUILD_TYPE Release|Debug|RelWithDebInfo (default: Debug when COVERAGE=ON, else Release) |
| 7 | +# TRACK Experimental|Nightly (default: Experimental) |
| 8 | +# JOBS N (default: SLURM CPU allocation if set, else logical CPU count) |
| 9 | +# HDF5_ROOT /path/to/hdf5 (default: cmake auto-detect) |
| 10 | +# HDF5_DIR /path/to/hdf5/cmake (default: cmake auto-detect) |
| 11 | +# CTEST_BUILD_NAME label (default: <os>-<arch>-<compiler>-<BUILD_TYPE>[-<node>] ) |
| 12 | +# CTEST_SITE label (default: SLURM_CLUSTER_NAME if set, else hostname) |
| 13 | +# SUBMIT ON|OFF (default: ON) |
| 14 | +# COVERAGE ON|OFF (default: ON; forces Debug + gcov) |
| 15 | +# BUILD_EXAMPLES ON|OFF (default: ON) |
| 16 | +# |
| 17 | +# Runs unattended on desktops and under SLURM (sbatch/srun) alike. Under SLURM, |
| 18 | +# JOBS honours the job's CPU allocation (SLURM_CPUS_PER_TASK / SLURM_CPUS_ON_NODE) |
| 19 | +# so the build never oversubscribes a shared node, the dashboard site defaults to |
| 20 | +# the cluster name (SLURM_CLUSTER_NAME) so all nodes group together, and the build |
| 21 | +# name is suffixed with the compute-node hostname to keep per-node runs distinct. |
| 22 | +# Note: compute nodes often lack direct outbound HTTPS — run on a login/interactive |
| 23 | +# node, set HTTPS_PROXY, or pass SUBMIT=OFF on the node and resubmit from a login node. |
| 24 | + |
| 25 | +cmake_minimum_required(VERSION 3.17) |
| 26 | + |
| 27 | +# ── paths ────────────────────────────────────────────────────────────────── |
| 28 | +get_filename_component(CTEST_SOURCE_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE) |
| 29 | +set(CTEST_BINARY_DIRECTORY "${CTEST_SOURCE_DIRECTORY}/build-cdash") |
| 30 | + |
| 31 | +# ── defaults ─────────────────────────────────────────────────────────────── |
| 32 | +if(NOT DEFINED BUILD_TYPE) |
| 33 | + set(BUILD_TYPE "Release") |
| 34 | +endif() |
| 35 | +if(NOT DEFINED TRACK) |
| 36 | + set(TRACK "Experimental") |
| 37 | +endif() |
| 38 | +if(NOT DEFINED SUBMIT) |
| 39 | + set(SUBMIT ON) |
| 40 | +endif() |
| 41 | +if(NOT DEFINED COVERAGE) |
| 42 | + set(COVERAGE ON) |
| 43 | +endif() |
| 44 | +if(COVERAGE) |
| 45 | + # gcov line counts are only meaningful against an unoptimised, instrumented |
| 46 | + # build, so coverage runs force Debug regardless of any BUILD_TYPE passed. |
| 47 | + set(BUILD_TYPE "Debug") |
| 48 | +endif() |
| 49 | +if(NOT DEFINED JOBS) |
| 50 | + # Under SLURM, honour the job's CPU allocation so the build does not |
| 51 | + # oversubscribe a shared node; fall back to the machine's logical core |
| 52 | + # count on a desktop / login node. |
| 53 | + if(DEFINED ENV{SLURM_CPUS_PER_TASK}) |
| 54 | + set(JOBS "$ENV{SLURM_CPUS_PER_TASK}") |
| 55 | + elseif(DEFINED ENV{SLURM_CPUS_ON_NODE}) |
| 56 | + set(JOBS "$ENV{SLURM_CPUS_ON_NODE}") |
| 57 | + else() |
| 58 | + cmake_host_system_information(RESULT JOBS QUERY NUMBER_OF_LOGICAL_CORES) |
| 59 | + endif() |
| 60 | +endif() |
| 61 | + |
| 62 | +# ── site: cluster name under SLURM, else hostname (overridable) ───────────── |
| 63 | +if(NOT DEFINED CTEST_SITE) |
| 64 | + if(DEFINED ENV{SLURM_CLUSTER_NAME}) |
| 65 | + set(CTEST_SITE "$ENV{SLURM_CLUSTER_NAME}") |
| 66 | + else() |
| 67 | + cmake_host_system_information(RESULT CTEST_SITE QUERY HOSTNAME) |
| 68 | + endif() |
| 69 | +endif() |
| 70 | + |
| 71 | +# ── build name: os-arch-compiler-type (auto, overridable) ───────────────── |
| 72 | +if(NOT DEFINED CTEST_BUILD_NAME) |
| 73 | + cmake_host_system_information(RESULT _os QUERY OS_NAME) |
| 74 | + cmake_host_system_information(RESULT _arch QUERY OS_PLATFORM) |
| 75 | + |
| 76 | + if(DEFINED ENV{CXX}) |
| 77 | + get_filename_component(_compiler "$ENV{CXX}" NAME) |
| 78 | + else() |
| 79 | + set(_compiler "c++") |
| 80 | + endif() |
| 81 | + |
| 82 | + set(CTEST_BUILD_NAME "${_os}-${_arch}-${_compiler}-${BUILD_TYPE}") |
| 83 | + |
| 84 | + # When running under SLURM the site is the (shared) cluster name, so append |
| 85 | + # the compute-node hostname to keep concurrent per-node submissions distinct. |
| 86 | + if(DEFINED ENV{SLURM_JOB_ID}) |
| 87 | + cmake_host_system_information(RESULT _node QUERY HOSTNAME) |
| 88 | + set(CTEST_BUILD_NAME "${CTEST_BUILD_NAME}-${_node}") |
| 89 | + endif() |
| 90 | +endif() |
| 91 | + |
| 92 | +# ── generator: prefer Ninja ──────────────────────────────────────────────── |
| 93 | +find_program(_ninja ninja) |
| 94 | +if(_ninja) |
| 95 | + set(CTEST_CMAKE_GENERATOR "Ninja") |
| 96 | +else() |
| 97 | + set(CTEST_CMAKE_GENERATOR "Unix Makefiles") |
| 98 | +endif() |
| 99 | +set(CTEST_BUILD_CONFIGURATION "${BUILD_TYPE}") |
| 100 | +set(CTEST_BUILD_FLAGS "-j${JOBS}") |
| 101 | + |
| 102 | +# ── cmake configure options ──────────────────────────────────────────────── |
| 103 | +if(NOT DEFINED BUILD_EXAMPLES) |
| 104 | + set(BUILD_EXAMPLES ON) |
| 105 | +endif() |
| 106 | + |
| 107 | +set(_options |
| 108 | + -DCMAKE_BUILD_TYPE=${BUILD_TYPE} |
| 109 | + -DCMAKE_CXX_STANDARD=17 |
| 110 | + -DH5CPP_BUILD_TESTS=ON |
| 111 | + -DH5CPP_BUILD_EXAMPLES=${BUILD_EXAMPLES} |
| 112 | +) |
| 113 | +if(DEFINED ENV{CC}) |
| 114 | + list(APPEND _options "-DCMAKE_C_COMPILER=$ENV{CC}") |
| 115 | +endif() |
| 116 | +if(DEFINED ENV{CXX}) |
| 117 | + list(APPEND _options "-DCMAKE_CXX_COMPILER=$ENV{CXX}") |
| 118 | +endif() |
| 119 | +if(DEFINED HDF5_ROOT) |
| 120 | + list(APPEND _options "-DHDF5_ROOT=${HDF5_ROOT}") |
| 121 | +endif() |
| 122 | +# HDF5_DIR (the package config dir) is the reliable discovery knob when an |
| 123 | +# h5cc on PATH would otherwise shadow the intended install. |
| 124 | +if(DEFINED HDF5_DIR) |
| 125 | + list(APPEND _options "-DHDF5_DIR=${HDF5_DIR}") |
| 126 | +endif() |
| 127 | + |
| 128 | +# ── coverage instrumentation (optional) ────────────────────────────────────── |
| 129 | +if(COVERAGE) |
| 130 | + list(APPEND _options |
| 131 | + "-DCMAKE_C_FLAGS=--coverage -fprofile-update=atomic -O0 -g" |
| 132 | + "-DCMAKE_CXX_FLAGS=--coverage -fprofile-update=atomic -O0 -g" |
| 133 | + "-DCMAKE_EXE_LINKER_FLAGS=--coverage") |
| 134 | + |
| 135 | + # gcov tool — honour $GCOV (e.g. gcov-14 to match g++-14), else first on PATH. |
| 136 | + if(DEFINED ENV{GCOV}) |
| 137 | + set(CTEST_COVERAGE_COMMAND "$ENV{GCOV}") |
| 138 | + else() |
| 139 | + find_program(CTEST_COVERAGE_COMMAND NAMES gcov) |
| 140 | + endif() |
| 141 | + |
| 142 | + # Scope the Coverage step to library headers only. CTestCustom.cmake already |
| 143 | + # carries these excludes for the build tree; we set them here too so the |
| 144 | + # off-CI -S run is self-contained. H5Zpipeline_pool.hpp is dead through the |
| 145 | + # public API (see #286) and excluded until activation is fixed. |
| 146 | + list(APPEND CTEST_CUSTOM_COVERAGE_EXCLUDE |
| 147 | + "/thirdparty/" "/test/" "/examples/" "/usr/" "/CMakeFiles/" |
| 148 | + "/H5Zpipeline_pool.hpp") |
| 149 | +endif() |
| 150 | + |
| 151 | +# ── announce ─────────────────────────────────────────────────────────────── |
| 152 | +message(STATUS "────────────────────────────────────────") |
| 153 | +message(STATUS "h5cpp CDash submission") |
| 154 | +message(STATUS " site: ${CTEST_SITE}") |
| 155 | +message(STATUS " build name: ${CTEST_BUILD_NAME}") |
| 156 | +message(STATUS " track: ${TRACK}") |
| 157 | +message(STATUS " build dir: ${CTEST_BINARY_DIRECTORY}") |
| 158 | +message(STATUS " jobs: ${JOBS}") |
| 159 | +message(STATUS " examples: ${BUILD_EXAMPLES}") |
| 160 | +message(STATUS " coverage: ${COVERAGE}") |
| 161 | +message(STATUS " submit: ${SUBMIT}") |
| 162 | +message(STATUS "────────────────────────────────────────") |
| 163 | + |
| 164 | +# ── pipeline ─────────────────────────────────────────────────────────────── |
| 165 | +ctest_start("${TRACK}") |
| 166 | + |
| 167 | +ctest_configure( |
| 168 | + BUILD "${CTEST_BINARY_DIRECTORY}" |
| 169 | + OPTIONS "${_options}" |
| 170 | + RETURN_VALUE _rv_configure |
| 171 | +) |
| 172 | + |
| 173 | +ctest_build( |
| 174 | + BUILD "${CTEST_BINARY_DIRECTORY}" |
| 175 | + RETURN_VALUE _rv_build |
| 176 | +) |
| 177 | + |
| 178 | +ctest_test( |
| 179 | + BUILD "${CTEST_BINARY_DIRECTORY}" |
| 180 | + PARALLEL_LEVEL "${JOBS}" |
| 181 | + RETURN_VALUE _rv_test |
| 182 | +) |
| 183 | + |
| 184 | +if(COVERAGE) |
| 185 | + ctest_coverage( |
| 186 | + BUILD "${CTEST_BINARY_DIRECTORY}" |
| 187 | + RETURN_VALUE _rv_coverage |
| 188 | + ) |
| 189 | + if(_rv_coverage) |
| 190 | + message(WARNING "CDash coverage step returned ${_rv_coverage}") |
| 191 | + endif() |
| 192 | +endif() |
| 193 | + |
| 194 | +if(SUBMIT) |
| 195 | + ctest_submit(RETURN_VALUE _rv_submit) |
| 196 | + if(_rv_submit) |
| 197 | + message(WARNING "CDash submit returned ${_rv_submit}") |
| 198 | + endif() |
| 199 | +else() |
| 200 | + message(STATUS "SUBMIT=OFF — skipping upload") |
| 201 | +endif() |
0 commit comments