Skip to content

Commit d386b30

Browse files
committed
Simplified ci.py
1 parent 2951acc commit d386b30

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
name: CI
1+
# CI script to verify that CMake and B2 builds work.
2+
# B2 builds include only tests that don't require a DB server, to avoid race conditions.
3+
# CMake tests include the actual project tests and all the CMake integration workflows
4+
# recommended by Boost.CI.
5+
# Windows CMake jobs build the code but don't run the tests,
6+
# since we don't have a way to set up a Redis server on Windows (yet).
7+
# Subcommands are implemented by the tools/ci.py script in a platform-independent manner.
28

9+
name: CI
310

411
on: [push, pull_request]
512

@@ -14,10 +21,12 @@ jobs:
1421
fail-fast: false
1522
matrix:
1623
include:
17-
- { toolset: msvc-14.2, os: windows-2019, generator: "Visual Studio 16 2019", cxxstd: '17', build-type: 'Debug' }
18-
- { toolset: msvc-14.2, os: windows-2019, generator: "Visual Studio 16 2019", cxxstd: '17', build-type: 'Release' }
19-
- { toolset: msvc-14.3, os: windows-2022, generator: "Visual Studio 17 2022", cxxstd: '20', build-type: 'Debug' }
20-
- { toolset: msvc-14.3, os: windows-2022, generator: "Visual Studio 17 2022", cxxstd: '20', build-type: 'Release' }
24+
- { toolset: msvc-14.2, os: windows-2019, generator: "Visual Studio 16 2019", cxxstd: '17', build-type: 'Debug', build-shared-libs: 1 }
25+
- { toolset: msvc-14.2, os: windows-2019, generator: "Visual Studio 16 2019", cxxstd: '17', build-type: 'Release', build-shared-libs: 0 }
26+
- { toolset: msvc-14.3, os: windows-2022, generator: "Visual Studio 17 2022", cxxstd: '20', build-type: 'Debug', build-shared-libs: 0 }
27+
- { toolset: msvc-14.3, os: windows-2022, generator: "Visual Studio 17 2022", cxxstd: '20', build-type: 'Release', build-shared-libs: 1 }
28+
env:
29+
CMAKE_BUILD_PARALLEL_LEVEL: 4
2130
steps:
2231
- name: Checkout
2332
uses: actions/checkout@v3
@@ -39,15 +48,17 @@ jobs:
3948
--build-type ${{ matrix.build-type }} \
4049
--cxxstd ${{ matrix.cxxstd }} \
4150
--toolset ${{ matrix.toolset }} \
42-
--generator "${{ matrix.generator }}"
51+
--generator "${{ matrix.generator }}" \
52+
--build-shared-libs ${{ matrix.build-shared-libs }}
4353
4454
- name: Build the project tests
4555
run: |
4656
python3 tools/ci.py build-cmake-standalone-tests \
4757
--build-type ${{ matrix.build-type }} \
4858
--cxxstd ${{ matrix.cxxstd }} \
4959
--toolset ${{ matrix.toolset }} \
50-
--generator "${{ matrix.generator }}"
60+
--generator "${{ matrix.generator }}" \
61+
--build-shared-libs ${{ matrix.build-shared-libs }}
5162
5263
# # TODO: re-enable this when a Redis server is available for this job
5364
# - name: Run the project tests
@@ -61,23 +72,26 @@ jobs:
6172
--build-type ${{ matrix.build-type }} \
6273
--cxxstd ${{ matrix.cxxstd }} \
6374
--toolset ${{ matrix.toolset }} \
64-
--generator "${{ matrix.generator }}"
75+
--generator "${{ matrix.generator }}" \
76+
--build-shared-libs ${{ matrix.build-shared-libs }}
6577
6678
- name: Run find_package tests with the built cmake distribution
6779
run: |
6880
python3 tools/ci.py run-cmake-find-package-tests \
6981
--build-type ${{ matrix.build-type }} \
7082
--cxxstd ${{ matrix.cxxstd }} \
7183
--toolset ${{ matrix.toolset }} \
72-
--generator "${{ matrix.generator }}"
84+
--generator "${{ matrix.generator }}" \
85+
--build-shared-libs ${{ matrix.build-shared-libs }}
7386
7487
- name: Run find_package tests with the built b2 distribution
7588
run: |
7689
python3 tools/ci.py run-cmake-b2-find-package-tests \
7790
--build-type ${{ matrix.build-type }} \
7891
--cxxstd ${{ matrix.cxxstd }} \
7992
--toolset ${{ matrix.toolset }} \
80-
--generator "${{ matrix.generator }}"
93+
--generator "${{ matrix.generator }}" \
94+
--build-shared-libs ${{ matrix.build-shared-libs }}
8195
8296
windows-b2:
8397
name: "B2 ${{matrix.toolset}}"
@@ -135,6 +149,7 @@ jobs:
135149
env:
136150
CXXFLAGS: ${{matrix.cxxflags}} -Wall -Wextra
137151
LDFLAGS: ${{matrix.ldflags}}
152+
CMAKE_BUILD_PARALLEL_LEVEL: 4
138153
steps:
139154
- name: Checkout
140155
uses: actions/checkout@v3

tools/ci.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/python3
22

3+
# Contains commands that are invoked by the CI scripts.
4+
# Having this as a Python file makes it platform-independent.
5+
36
from pathlib import Path
47
from typing import List, Union
58
import subprocess
@@ -9,6 +12,7 @@
912
import argparse
1013

1114

15+
# Variables
1216
_is_windows = os.name == 'nt'
1317
_home = Path(os.path.expanduser('~'))
1418
_boost_root = _home.joinpath('boost-root')
@@ -17,6 +21,7 @@
1721
_b2_command = str(_boost_root.joinpath('b2'))
1822

1923

24+
# Utilities
2025
def _run(args: List[str]) -> None:
2126
print('+ ', args, flush=True)
2227
subprocess.run(args, check=True)
@@ -36,10 +41,7 @@ def _remove_readonly(func, path, _):
3641
func(path)
3742

3843

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)
4345
def _str2bool(v: Union[bool, str]) -> bool:
4446
if isinstance(v, bool):
4547
return v
@@ -51,6 +53,8 @@ def _str2bool(v: Union[bool, str]) -> bool:
5153
raise argparse.ArgumentTypeError('Boolean value expected.')
5254

5355

56+
# Transforms a b2-like toolset into a compiler command suitable
57+
# to be passed to CMAKE_CXX_COMPILER
5458
def _compiler_from_toolset(toolset: str) -> str:
5559
if toolset.startswith('gcc'):
5660
return toolset.replace('gcc', 'g++')
@@ -62,6 +66,8 @@ def _compiler_from_toolset(toolset: str) -> str:
6266
return toolset
6367

6468

69+
# If we're on the master branch, we should use the Boost superproject master branch.
70+
# Otherwise, use the superproject develop branch.
6571
def _deduce_boost_branch() -> str:
6672
# Are we in GitHub Actions?
6773
if os.environ.get('GITHUB_ACTIONS') is not None:
@@ -181,7 +187,7 @@ def _build_cmake_standalone_tests(
181187
'cmake',
182188
'-DBUILD_TESTING=ON',
183189
'-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),
185191
'-DCMAKE_BUILD_TYPE={}'.format(build_type),
186192
'-DBUILD_SHARED_LIBS={}'.format(_cmake_bool(build_shared_libs)),
187193
'-DCMAKE_CXX_STANDARD={}'.format(cxxstd),
@@ -245,7 +251,7 @@ def _run_cmake_find_package_tests(
245251
'-DCMAKE_BUILD_TYPE={}'.format(build_type),
246252
'-DBUILD_SHARED_LIBS={}'.format(_cmake_bool(build_shared_libs)),
247253
'-DCMAKE_CXX_STANDARD={}'.format(cxxstd),
248-
'-DCMAKE_PREFIX_PATH={}'.format(_build_prefix_path(_cmake_distro)),
254+
'-DCMAKE_PREFIX_PATH={}'.format(_cmake_distro),
249255
'..'
250256
])
251257
_run(['cmake', '--build', '.', '--config', build_type])
@@ -267,7 +273,7 @@ def _run_cmake_b2_find_package_tests(
267273
generator,
268274
'-DCMAKE_CXX_COMPILER={}'.format(_compiler_from_toolset(toolset)),
269275
'-DBUILD_TESTING=ON',
270-
'-DCMAKE_PREFIX_PATH={}'.format(_build_prefix_path(_b2_distro)),
276+
'-DCMAKE_PREFIX_PATH={}'.format(_b2_distro),
271277
'-DCMAKE_BUILD_TYPE={}'.format(build_type),
272278
'-DBUILD_SHARED_LIBS={}'.format(_cmake_bool(build_shared_libs)),
273279
'-DCMAKE_CXX_STANDARD={}'.format(cxxstd),
@@ -297,6 +303,7 @@ def _run_b2_tests(
297303

298304

299305
def main():
306+
# Command line parsing
300307
parser = argparse.ArgumentParser()
301308
subparsers = parser.add_subparsers()
302309

@@ -358,10 +365,13 @@ def main():
358365
subp.add_argument('--toolset', default='gcc')
359366
subp.set_defaults(func=_run_b2_tests)
360367

368+
# Actually parse the arguments
361369
args = parser.parse_args()
362370

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
365375
args.func(**{k: v for k, v in vars(args).items() if k != 'func'})
366376

367377

0 commit comments

Comments
 (0)