1
1
#!/usr/bin/python3
2
2
3
+ # Contains commands that are invoked by the CI scripts.
4
+ # Having this as a Python file makes it platform-independent.
5
+
3
6
from pathlib import Path
4
7
from typing import List , Union
5
8
import subprocess
9
12
import argparse
10
13
11
14
15
+ # Variables
12
16
_is_windows = os .name == 'nt'
13
17
_home = Path (os .path .expanduser ('~' ))
14
18
_boost_root = _home .joinpath ('boost-root' )
17
21
_b2_command = str (_boost_root .joinpath ('b2' ))
18
22
19
23
24
+ # Utilities
20
25
def _run (args : List [str ]) -> None :
21
26
print ('+ ' , args , flush = True )
22
27
subprocess .run (args , check = True )
@@ -36,10 +41,7 @@ def _remove_readonly(func, path, _):
36
41
func (path )
37
42
38
43
39
- def _build_prefix_path (* paths : Union [str , Path ]) -> str :
40
- return ';' .join (str (p ) for p in paths )
41
-
42
-
44
+ # Parses a string into a boolean (for command-line parsing)
43
45
def _str2bool (v : Union [bool , str ]) -> bool :
44
46
if isinstance (v , bool ):
45
47
return v
@@ -51,6 +53,8 @@ def _str2bool(v: Union[bool, str]) -> bool:
51
53
raise argparse .ArgumentTypeError ('Boolean value expected.' )
52
54
53
55
56
+ # Transforms a b2-like toolset into a compiler command suitable
57
+ # to be passed to CMAKE_CXX_COMPILER
54
58
def _compiler_from_toolset (toolset : str ) -> str :
55
59
if toolset .startswith ('gcc' ):
56
60
return toolset .replace ('gcc' , 'g++' )
@@ -62,6 +66,8 @@ def _compiler_from_toolset(toolset: str) -> str:
62
66
return toolset
63
67
64
68
69
+ # If we're on the master branch, we should use the Boost superproject master branch.
70
+ # Otherwise, use the superproject develop branch.
65
71
def _deduce_boost_branch () -> str :
66
72
# Are we in GitHub Actions?
67
73
if os .environ .get ('GITHUB_ACTIONS' ) is not None :
@@ -181,7 +187,7 @@ def _build_cmake_standalone_tests(
181
187
'cmake' ,
182
188
'-DBUILD_TESTING=ON' ,
183
189
'-DCMAKE_CXX_COMPILER={}' .format (_compiler_from_toolset (toolset )),
184
- '-DCMAKE_PREFIX_PATH={}' .format (_build_prefix_path ( _b2_distro ) ),
190
+ '-DCMAKE_PREFIX_PATH={}' .format (_b2_distro ),
185
191
'-DCMAKE_BUILD_TYPE={}' .format (build_type ),
186
192
'-DBUILD_SHARED_LIBS={}' .format (_cmake_bool (build_shared_libs )),
187
193
'-DCMAKE_CXX_STANDARD={}' .format (cxxstd ),
@@ -245,7 +251,7 @@ def _run_cmake_find_package_tests(
245
251
'-DCMAKE_BUILD_TYPE={}' .format (build_type ),
246
252
'-DBUILD_SHARED_LIBS={}' .format (_cmake_bool (build_shared_libs )),
247
253
'-DCMAKE_CXX_STANDARD={}' .format (cxxstd ),
248
- '-DCMAKE_PREFIX_PATH={}' .format (_build_prefix_path ( _cmake_distro ) ),
254
+ '-DCMAKE_PREFIX_PATH={}' .format (_cmake_distro ),
249
255
'..'
250
256
])
251
257
_run (['cmake' , '--build' , '.' , '--config' , build_type ])
@@ -267,7 +273,7 @@ def _run_cmake_b2_find_package_tests(
267
273
generator ,
268
274
'-DCMAKE_CXX_COMPILER={}' .format (_compiler_from_toolset (toolset )),
269
275
'-DBUILD_TESTING=ON' ,
270
- '-DCMAKE_PREFIX_PATH={}' .format (_build_prefix_path ( _b2_distro ) ),
276
+ '-DCMAKE_PREFIX_PATH={}' .format (_b2_distro ),
271
277
'-DCMAKE_BUILD_TYPE={}' .format (build_type ),
272
278
'-DBUILD_SHARED_LIBS={}' .format (_cmake_bool (build_shared_libs )),
273
279
'-DCMAKE_CXX_STANDARD={}' .format (cxxstd ),
@@ -297,6 +303,7 @@ def _run_b2_tests(
297
303
298
304
299
305
def main ():
306
+ # Command line parsing
300
307
parser = argparse .ArgumentParser ()
301
308
subparsers = parser .add_subparsers ()
302
309
@@ -358,10 +365,13 @@ def main():
358
365
subp .add_argument ('--toolset' , default = 'gcc' )
359
366
subp .set_defaults (func = _run_b2_tests )
360
367
368
+ # Actually parse the arguments
361
369
args = parser .parse_args ()
362
370
363
- os .environ ['CMAKE_BUILD_PARALLEL_LEVEL' ] = '4'
364
-
371
+ # Invoke the relevant function (as defined by the func default), with
372
+ # the command-line arguments the user passed us (we need to get rid
373
+ # of the func property to match function signatures)
374
+ # This approach is recommended by Python's argparse docs
365
375
args .func (** {k : v for k , v in vars (args ).items () if k != 'func' })
366
376
367
377
0 commit comments