10
10
11
11
12
12
_is_windows = os .name == 'nt'
13
- _boost_root = Path (os .path .expanduser ('~' )).joinpath ('boost-root' )
13
+ _home = Path (os .path .expanduser ('~' ))
14
+ _boost_root = _home .joinpath ('boost-root' )
15
+ _b2_distro = _home .joinpath ('boost-b2-distro' )
16
+ _cmake_distro = _home .joinpath ('boost-cmake-distro' )
14
17
_b2_command = str (_boost_root .joinpath ('b2' ))
15
18
16
19
@@ -68,7 +71,10 @@ def _deduce_boost_branch() -> str:
68
71
return res
69
72
70
73
71
- def _install_boost (
74
+ # Gets Boost (develop or master, depending on the CI branch we're operating on),
75
+ # with the required dependencies, and leaves it at _boost_root. Places our library,
76
+ # located under source_dir, under $BOOST_ROOT/libs. Also runs the bootstrap script so b2 is usable.
77
+ def _setup_boost (
72
78
source_dir : Path
73
79
) -> None :
74
80
assert source_dir .is_absolute ()
@@ -103,21 +109,22 @@ def _install_boost(
103
109
_run ([_b2_command , 'headers' ])
104
110
105
111
106
- def _build_b2_distro (
107
- install_prefix : Path
108
- ):
112
+ # Builds a Boost distribution using ./b2 install, and places it into _b2_distro.
113
+ # This emulates a regular Boost distribution, like the ones in releases
114
+ def _build_b2_distro ( ):
109
115
os .chdir (str (_boost_root ))
110
116
_run ([
111
117
_b2_command ,
112
- '--prefix={}' .format (install_prefix ),
118
+ '--prefix={}' .format (_b2_distro ),
113
119
'--with-system' ,
114
120
'-d0' ,
115
121
'install'
116
122
])
117
123
118
124
125
+ # Builds a Boost distribution using cmake, and places it into _cmake_distro.
126
+ # It includes only our library and any dependency.
119
127
def _build_cmake_distro (
120
- install_prefix : Path ,
121
128
generator : str ,
122
129
build_type : str ,
123
130
cxxstd : str ,
@@ -133,7 +140,7 @@ def _build_cmake_distro(
133
140
'-DCMAKE_CXX_STANDARD={}' .format (cxxstd ),
134
141
'-DBOOST_INCLUDE_LIBRARIES=redis' ,
135
142
'-DBUILD_SHARED_LIBS={}' .format (_cmake_bool (build_shared_libs )),
136
- '-DCMAKE_INSTALL_PREFIX={}' .format (install_prefix ),
143
+ '-DCMAKE_INSTALL_PREFIX={}' .format (_cmake_distro ),
137
144
'-DBUILD_TESTING=ON' ,
138
145
'-DBoost_VERBOSE=ON' ,
139
146
'-DCMAKE_INSTALL_MESSAGE=NEVER' ,
@@ -144,8 +151,10 @@ def _build_cmake_distro(
144
151
_run (['cmake' , '--build' , '.' , '--target' , 'install' , '--config' , build_type ])
145
152
146
153
154
+ # Builds and runs our CMake tests as a standalone project
155
+ # (BOOST_REDIS_MAIN_PROJECT is ON) and we find_package Boost.
156
+ # This ensures that all our test suite is run.
147
157
def _run_cmake_standalone_tests (
148
- b2_distro : Path ,
149
158
generator : str ,
150
159
build_type : str ,
151
160
cxxstd : str ,
@@ -155,7 +164,7 @@ def _run_cmake_standalone_tests(
155
164
_run ([
156
165
'cmake' ,
157
166
'-DBUILD_TESTING=ON' ,
158
- '-DCMAKE_PREFIX_PATH={}' .format (_build_prefix_path (b2_distro )),
167
+ '-DCMAKE_PREFIX_PATH={}' .format (_build_prefix_path (_b2_distro )),
159
168
'-DCMAKE_BUILD_TYPE={}' .format (build_type ),
160
169
'-DBUILD_SHARED_LIBS={}' .format (_cmake_bool (build_shared_libs )),
161
170
'-DCMAKE_CXX_STANDARD={}' .format (cxxstd ),
@@ -167,6 +176,7 @@ def _run_cmake_standalone_tests(
167
176
_run (['ctest' , '--output-on-failure' , '--build-config' , build_type , '--no-tests=error' ])
168
177
169
178
179
+ # Tests that the library can be consumed using add_subdirectory()
170
180
def _run_cmake_add_subdirectory_tests (
171
181
generator : str ,
172
182
build_type : str ,
@@ -188,8 +198,8 @@ def _run_cmake_add_subdirectory_tests(
188
198
_run (['ctest' , '--output-on-failure' , '--build-config' , build_type , '--no-tests=error' ])
189
199
190
200
201
+ # Tests that the library can be consumed using find_package on a distro built by cmake
191
202
def _run_cmake_find_package_tests (
192
- cmake_distro : Path ,
193
203
generator : str ,
194
204
build_type : str ,
195
205
build_shared_libs : bool = False
@@ -203,15 +213,15 @@ def _run_cmake_find_package_tests(
203
213
'-DBOOST_CI_INSTALL_TEST=ON' ,
204
214
'-DCMAKE_BUILD_TYPE={}' .format (build_type ),
205
215
'-DBUILD_SHARED_LIBS={}' .format (_cmake_bool (build_shared_libs )),
206
- '-DCMAKE_PREFIX_PATH={}' .format (_build_prefix_path (cmake_distro )),
216
+ '-DCMAKE_PREFIX_PATH={}' .format (_build_prefix_path (_cmake_distro )),
207
217
'..'
208
218
])
209
219
_run (['cmake' , '--build' , '.' , '--config' , build_type ])
210
220
_run (['ctest' , '--output-on-failure' , '--build-config' , build_type , '--no-tests=error' ])
211
221
212
222
223
+ # Tests that the library can be consumed using find_package on a distro built by b2
213
224
def _run_cmake_b2_find_package_tests (
214
- b2_distro : Path ,
215
225
generator : str ,
216
226
build_type : str ,
217
227
build_shared_libs : bool = False
@@ -222,7 +232,7 @@ def _run_cmake_b2_find_package_tests(
222
232
'-G' ,
223
233
generator ,
224
234
'-DBUILD_TESTING=ON' ,
225
- '-DCMAKE_PREFIX_PATH={}' .format (_build_prefix_path (b2_distro )),
235
+ '-DCMAKE_PREFIX_PATH={}' .format (_build_prefix_path (_b2_distro )),
226
236
'-DCMAKE_BUILD_TYPE={}' .format (build_type ),
227
237
'-DBUILD_SHARED_LIBS={}' .format (_cmake_bool (build_shared_libs )),
228
238
'-DBUILD_TESTING=ON' ,
@@ -232,68 +242,25 @@ def _run_cmake_b2_find_package_tests(
232
242
_run (['ctest' , '--output-on-failure' , '--build-config' , build_type , '--no-tests=error' ])
233
243
234
244
235
- def _run_b2_tests (
236
- toolset : str ,
237
- cxxstd : str ,
238
- variant : str ,
239
- stdlib : str = 'native' ,
240
- address_model : str = '64' ,
241
- address_sanitizer : bool = False ,
242
- undefined_sanitizer : bool = False ,
243
- ):
244
- os .chdir (str (_boost_root ))
245
- _run ([
246
- _b2_command ,
247
- '--abbreviate-paths' ,
248
- 'toolset={}' .format (toolset ),
249
- 'cxxstd={}' .format (cxxstd ),
250
- 'address-model={}' .format (address_model ),
251
- 'variant={}' .format (variant ),
252
- 'stdlib={}' .format (stdlib ),
253
- ] + (['address-sanitizer=norecover' ] if address_sanitizer else []) # can only be disabled by omitting the arg
254
- + (['undefined-sanitizer=norecover' ] if undefined_sanitizer else []) # can only be disabled by omitting the arg
255
- + [
256
- 'warnings-as-errors=on' ,
257
- '-j4' ,
258
- 'libs/redis/test' ,
259
- 'libs/redis/example'
260
- ])
261
-
262
- # Get Boost
263
- # Generate "pre-built" b2 distro
264
- # Build the library, run the tests, and install, from the superproject
265
- # Library tests, using the b2 Boost distribution generated before (this tests our normal dev workflow)
266
- # Subdir tests, using add_subdirectory() (lib can be consumed using add_subdirectory)
267
- # Subdir tests, using find_package with the library installed in the previous step
268
- # (library can be consumed using find_package on a distro built by cmake)
269
-
270
- # Subdir tests, using find_package with the b2 distribution
271
- # (library can be consumed using find_package on a distro built by b2)
272
-
273
-
274
-
275
245
def main ():
276
246
parser = argparse .ArgumentParser ()
277
247
subparsers = parser .add_subparsers ()
278
248
279
- subp = subparsers .add_parser ('install -boost' )
249
+ subp = subparsers .add_parser ('setup -boost' )
280
250
subp .add_argument ('--source-dir' , type = Path , required = True )
281
- subp .set_defaults (func = _install_boost )
251
+ subp .set_defaults (func = _setup_boost )
282
252
283
253
subp = subparsers .add_parser ('build-b2-distro' )
284
- subp .add_argument ('--install-prefix' , type = Path , required = True )
285
254
subp .set_defaults (func = _build_b2_distro )
286
255
287
256
subp = subparsers .add_parser ('build-cmake-distro' )
288
- subp .add_argument ('--install-prefix' , type = Path , required = True )
289
257
subp .add_argument ('--generator' , default = 'Unix Makefiles' )
290
258
subp .add_argument ('--build-type' , default = 'Debug' )
291
259
subp .add_argument ('--cxxstd' , default = '20' )
292
260
subp .add_argument ('--build-shared-libs' , type = _str2bool , default = False )
293
261
subp .set_defaults (func = _build_cmake_distro )
294
262
295
263
subp = subparsers .add_parser ('run-cmake-standalone-tests' )
296
- subp .add_argument ('--b2-distro' , type = Path , required = True )
297
264
subp .add_argument ('--generator' , default = 'Unix Makefiles' )
298
265
subp .add_argument ('--build-type' , default = 'Debug' )
299
266
subp .add_argument ('--cxxstd' , default = '20' )
@@ -307,29 +274,17 @@ def main():
307
274
subp .set_defaults (func = _run_cmake_add_subdirectory_tests )
308
275
309
276
subp = subparsers .add_parser ('run-cmake-find-package-tests' )
310
- subp .add_argument ('--cmake-distro' , type = Path , required = True )
311
277
subp .add_argument ('--generator' , default = 'Unix Makefiles' )
312
278
subp .add_argument ('--build-type' , default = 'Debug' )
313
279
subp .add_argument ('--build-shared-libs' , type = _str2bool , default = False )
314
280
subp .set_defaults (func = _run_cmake_find_package_tests )
315
281
316
282
subp = subparsers .add_parser ('run-cmake-b2-find-package-tests' )
317
- subp .add_argument ('--cmake-distro' , type = Path , required = True )
318
283
subp .add_argument ('--generator' , default = 'Unix Makefiles' )
319
284
subp .add_argument ('--build-type' , default = 'Debug' )
320
285
subp .add_argument ('--build-shared-libs' , type = _str2bool , default = False )
321
286
subp .set_defaults (func = _run_cmake_b2_find_package_tests )
322
287
323
- subp = subparsers .add_parser ('run-b2-tests' )
324
- subp .add_argument ('--toolset' , required = True )
325
- subp .add_argument ('--cxxstd' , default = '20' )
326
- subp .add_argument ('--variant' , default = 'debug,release' )
327
- subp .add_argument ('--stdlib' , default = 'native' )
328
- subp .add_argument ('--address-model' , default = '64' )
329
- subp .add_argument ('--address-sanitizer' , type = _str2bool , default = False )
330
- subp .add_argument ('--undefined-sanitizer' , type = _str2bool , default = False )
331
- subp .set_defaults (func = _run_b2_tests )
332
-
333
288
args = parser .parse_args ()
334
289
335
290
os .environ ['CMAKE_BUILD_PARALLEL_LEVEL' ] = '4'
0 commit comments