forked from geospace-code/h5fortran
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci.cmake
212 lines (175 loc) · 5.88 KB
/
ci.cmake
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
cmake_minimum_required(VERSION 3.15...3.20)
set(CTEST_PROJECT_NAME "h5fortran")
set(CTEST_LABELS_FOR_SUBPROJECTS "unit;core;shaky")
set(opts)
# --- boilerplate follows
set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
set(CTEST_SUBMIT_URL "https://my.cdash.org/submit.php?project=${CTEST_PROJECT_NAME}")
# ctest -S doesn't have a way to pass -Dvar:type=value, so do this via env var
# cannot pass in lists--use CMakePresets.json for list variables. Example:
# ctest --preset=my1 -S setup.cmake
list(APPEND opts $ENV{CTEST_${CTEST_PROJECT_NAME}_ARGS})
# --- Experimental, Nightly, Continuous
# https://cmake.org/cmake/help/latest/manual/ctest.1.html#dashboard-client-modes
if(NOT CTEST_MODEL)
if(DEFINED ENV{CTEST_MODEL})
set(CTEST_MODEL $ENV{CTEST_MODEL})
endif()
endif()
if(NOT CTEST_MODEL)
if(DEFINED ENV{CI})
set(CI $ENV{CI})
if(CI)
set(CTEST_MODEL "Nightly")
endif()
endif()
endif()
if(NOT CTEST_MODEL)
set(CTEST_MODEL "Experimental")
endif()
# --- other defaults
set(CTEST_TEST_TIMEOUT 10)
set(CTEST_OUTPUT_ON_FAILURE true)
set(CTEST_SOURCE_DIRECTORY ${CTEST_SCRIPT_DIRECTORY})
if(NOT DEFINED CTEST_BINARY_DIRECTORY)
set(CTEST_BINARY_DIRECTORY ${CTEST_SOURCE_DIRECTORY}/build)
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()
list(APPEND opts -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
if(NOT DEFINED CTEST_SITE)
if(DEFINED ENV{CTEST_SITE})
set(CTEST_SITE $ENV{CTEST_SITE})
else()
cmake_host_system_information(RESULT sys_name QUERY OS_NAME OS_RELEASE OS_VERSION)
string(REPLACE ";" " " sys_name ${sys_name})
set(CTEST_SITE ${sys_name})
endif()
endif()
find_program(GIT_EXECUTABLE NAMES git REQUIRED)
if(NOT DEFINED CTEST_BUILD_NAME)
if(DEFINED ENV{CTEST_BUILD_NAME})
set(CTEST_BUILD_NAME $ENV{CTEST_BUILD_NAME})
else()
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags
WORKING_DIRECTORY ${CTEST_SOURCE_DIRECTORY}
OUTPUT_VARIABLE git_rev OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE _err)
if(NOT _err EQUAL 0)
# old Git
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY ${CTEST_SOURCE_DIRECTORY}
OUTPUT_VARIABLE git_rev OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE _err)
endif()
if(_err EQUAL 0)
set(CTEST_BUILD_NAME ${git_rev})
endif()
endif()
endif()
set(CTEST_USE_LAUNCHERS 1)
# --- find generator
function(find_generator)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17)
find_program(ninja NAMES ninja ninja-build samu)
if(ninja)
execute_process(COMMAND ${ninja} --version
OUTPUT_VARIABLE ninja_version OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE err
TIMEOUT 5)
if(err EQUAL 0 AND ninja_version VERSION_GREATER_EQUAL 1.10)
set(CTEST_CMAKE_GENERATOR Ninja)
endif()
endif(ninja)
endif()
if(NOT DEFINED CTEST_CMAKE_GENERATOR)
set(CTEST_BUILD_FLAGS -j) # not --parallel as this goes to generator directly
if(WIN32)
set(CTEST_CMAKE_GENERATOR "MinGW Makefiles")
else()
set(CTEST_CMAKE_GENERATOR "Unix Makefiles")
endif()
endif()
set(CTEST_CMAKE_GENERATOR ${CTEST_CMAKE_GENERATOR} PARENT_SCOPE)
endfunction(find_generator)
if(NOT DEFINED CTEST_CMAKE_GENERATOR)
if(DEFINED ENV{CMAKE_GENERATOR})
set(CTEST_CMAKE_GENERATOR $ENV{CMAKE_GENERATOR})
else()
find_generator()
endif()
endif()
# --- test parallelism
include(ProcessorCount)
function(cmake_cpu_count)
# on ARM e.g. Raspberry Pi, the usually reliable cmake_host_system_info gives 1 instead of true count
# fallback to less reliable ProcessorCount which does work on Raspberry Pi.
ProcessorCount(_ncount)
cmake_host_system_information(RESULT Ncpu QUERY NUMBER_OF_PHYSICAL_CORES)
if(Ncpu EQUAL 1 AND _ncount GREATER 0)
set(Ncpu ${_ncount})
endif()
set(Ncpu ${Ncpu} PARENT_SCOPE)
endfunction(cmake_cpu_count)
cmake_cpu_count()
# --- CTest Dashboard
set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
set(CTEST_SUBMIT_RETRY_COUNT 3)
# avoid auto-detect version control failures on some systems
set(CTEST_UPDATE_TYPE git)
set(CTEST_UPDATE_COMMAND git)
ctest_start(${CTEST_MODEL})
if(CTEST_MODEL STREQUAL Nightly OR CTEST_MODEL STREQUAL Continuous)
# this erases local code changes i.e. anything not "git push" already is lost forever!
# we try to avoid that by guarding with a Git porcelain check
execute_process(COMMAND ${GIT_EXECUTABLE} status --porcelain
WORKING_DIRECTORY ${CTEST_SOURCE_DIRECTORY}
OUTPUT_VARIABLE _ret OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE _err)
if(NOT _err EQUAL 0)
message(FATAL_ERROR "CTest could not check Git porcelain status")
endif()
if(_ret)
message(WARNING "CTest would have erased the non-Git Push'd changes, NOT updating.")
else()
ctest_update(RETURN_VALUE _ret)
if(_ret EQUAL 0 AND CTEST_MODEL STREQUAL Continuous)
message(STATUS "No Git-updated files, so no need to test in CTest Model ${CTEST_MODEL}. CTest stopping.")
return()
endif()
endif()
endif()
ctest_configure(
OPTIONS "${opts}"
RETURN_VALUE _ret
CAPTURE_CMAKE_ERROR _err)
ctest_submit(PARTS Configure)
if(NOT (_ret EQUAL 0 AND _err EQUAL 0))
message(FATAL_ERROR "Configure failed.")
endif()
ctest_build(
RETURN_VALUE _ret
CAPTURE_CMAKE_ERROR _err)
ctest_submit(PARTS Build)
if(NOT (_ret EQUAL 0 AND _err EQUAL 0))
message(FATAL_ERROR "Build failed.")
endif()
ctest_test(
# set PARALLEL_LEVEL here as the global option seems to be ignored
PARALLEL_LEVEL ${Ncpu}
# specify BUILD to avoid random return 255 despite tests passing
BUILD ${CTEST_BINARY_DIRECTORY}
SCHEDULE_RANDOM ON
REPEAT UNTIL_PASS:3
RETURN_VALUE _ret
CAPTURE_CMAKE_ERROR _err
)
ctest_submit(PARTS Test)
ctest_submit(
PARTS Done
BUILD_ID build_id)
if(NOT (_ret EQUAL 0 AND _err EQUAL 0))
message(FATAL_ERROR "Build ${build_id} failed: CTest code ${_ret}, CMake code ${_err}.")
endif()
message(STATUS "OK: CTest build ${build_id}")