2
0
mirror of https://github.com/boostorg/redis.git synced 2026-01-19 04:42:09 +00:00

subdir tests

This commit is contained in:
Ruben Perez
2023-10-04 12:29:59 +02:00
parent cb9fdba0a4
commit 221016f1c9
6 changed files with 164 additions and 79 deletions

97
tools/ci.py Normal file → Executable file
View File

@@ -10,7 +10,10 @@ import argparse
_is_windows = os.name == 'nt'
_boost_root = Path(os.path.expanduser('~')).joinpath('boost-root')
_home = Path(os.path.expanduser('~'))
_boost_root = _home.joinpath('boost-root')
_b2_distro = _home.joinpath('boost-b2-distro')
_cmake_distro = _home.joinpath('boost-cmake-distro')
_b2_command = str(_boost_root.joinpath('b2'))
@@ -68,7 +71,10 @@ def _deduce_boost_branch() -> str:
return res
def _install_boost(
# Gets Boost (develop or master, depending on the CI branch we're operating on),
# with the required dependencies, and leaves it at _boost_root. Places our library,
# located under source_dir, under $BOOST_ROOT/libs. Also runs the bootstrap script so b2 is usable.
def _setup_boost(
source_dir: Path
) -> None:
assert source_dir.is_absolute()
@@ -103,21 +109,22 @@ def _install_boost(
_run([_b2_command, 'headers'])
def _build_b2_distro(
install_prefix: Path
):
# Builds a Boost distribution using ./b2 install, and places it into _b2_distro.
# This emulates a regular Boost distribution, like the ones in releases
def _build_b2_distro():
os.chdir(str(_boost_root))
_run([
_b2_command,
'--prefix={}'.format(install_prefix),
'--prefix={}'.format(_b2_distro),
'--with-system',
'-d0',
'install'
])
# Builds a Boost distribution using cmake, and places it into _cmake_distro.
# It includes only our library and any dependency.
def _build_cmake_distro(
install_prefix: Path,
generator: str,
build_type: str,
cxxstd: str,
@@ -133,7 +140,7 @@ def _build_cmake_distro(
'-DCMAKE_CXX_STANDARD={}'.format(cxxstd),
'-DBOOST_INCLUDE_LIBRARIES=redis',
'-DBUILD_SHARED_LIBS={}'.format(_cmake_bool(build_shared_libs)),
'-DCMAKE_INSTALL_PREFIX={}'.format(install_prefix),
'-DCMAKE_INSTALL_PREFIX={}'.format(_cmake_distro),
'-DBUILD_TESTING=ON',
'-DBoost_VERBOSE=ON',
'-DCMAKE_INSTALL_MESSAGE=NEVER',
@@ -144,8 +151,10 @@ def _build_cmake_distro(
_run(['cmake', '--build', '.', '--target', 'install', '--config', build_type])
# Builds and runs our CMake tests as a standalone project
# (BOOST_REDIS_MAIN_PROJECT is ON) and we find_package Boost.
# This ensures that all our test suite is run.
def _run_cmake_standalone_tests(
b2_distro: Path,
generator: str,
build_type: str,
cxxstd: str,
@@ -155,7 +164,7 @@ def _run_cmake_standalone_tests(
_run([
'cmake',
'-DBUILD_TESTING=ON',
'-DCMAKE_PREFIX_PATH={}'.format(_build_prefix_path(b2_distro)),
'-DCMAKE_PREFIX_PATH={}'.format(_build_prefix_path(_b2_distro)),
'-DCMAKE_BUILD_TYPE={}'.format(build_type),
'-DBUILD_SHARED_LIBS={}'.format(_cmake_bool(build_shared_libs)),
'-DCMAKE_CXX_STANDARD={}'.format(cxxstd),
@@ -167,6 +176,7 @@ def _run_cmake_standalone_tests(
_run(['ctest', '--output-on-failure', '--build-config', build_type, '--no-tests=error'])
# Tests that the library can be consumed using add_subdirectory()
def _run_cmake_add_subdirectory_tests(
generator: str,
build_type: str,
@@ -188,8 +198,8 @@ def _run_cmake_add_subdirectory_tests(
_run(['ctest', '--output-on-failure', '--build-config', build_type, '--no-tests=error'])
# Tests that the library can be consumed using find_package on a distro built by cmake
def _run_cmake_find_package_tests(
cmake_distro: Path,
generator: str,
build_type: str,
build_shared_libs: bool = False
@@ -203,15 +213,15 @@ def _run_cmake_find_package_tests(
'-DBOOST_CI_INSTALL_TEST=ON',
'-DCMAKE_BUILD_TYPE={}'.format(build_type),
'-DBUILD_SHARED_LIBS={}'.format(_cmake_bool(build_shared_libs)),
'-DCMAKE_PREFIX_PATH={}'.format(_build_prefix_path(cmake_distro)),
'-DCMAKE_PREFIX_PATH={}'.format(_build_prefix_path(_cmake_distro)),
'..'
])
_run(['cmake', '--build', '.', '--config', build_type])
_run(['ctest', '--output-on-failure', '--build-config', build_type, '--no-tests=error'])
# Tests that the library can be consumed using find_package on a distro built by b2
def _run_cmake_b2_find_package_tests(
b2_distro: Path,
generator: str,
build_type: str,
build_shared_libs: bool = False
@@ -222,7 +232,7 @@ def _run_cmake_b2_find_package_tests(
'-G',
generator,
'-DBUILD_TESTING=ON',
'-DCMAKE_PREFIX_PATH={}'.format(_build_prefix_path(b2_distro)),
'-DCMAKE_PREFIX_PATH={}'.format(_build_prefix_path(_b2_distro)),
'-DCMAKE_BUILD_TYPE={}'.format(build_type),
'-DBUILD_SHARED_LIBS={}'.format(_cmake_bool(build_shared_libs)),
'-DBUILD_TESTING=ON',
@@ -232,60 +242,18 @@ def _run_cmake_b2_find_package_tests(
_run(['ctest', '--output-on-failure', '--build-config', build_type, '--no-tests=error'])
def _run_b2_tests(
toolset: str,
cxxstd: str,
variant: str,
stdlib: str = 'native',
address_model: str = '64',
address_sanitizer: bool = False,
undefined_sanitizer: bool = False,
):
os.chdir(str(_boost_root))
_run([
_b2_command,
'--abbreviate-paths',
'toolset={}'.format(toolset),
'cxxstd={}'.format(cxxstd),
'address-model={}'.format(address_model),
'variant={}'.format(variant),
'stdlib={}'.format(stdlib),
] + (['address-sanitizer=norecover'] if address_sanitizer else []) # can only be disabled by omitting the arg
+ (['undefined-sanitizer=norecover'] if undefined_sanitizer else []) # can only be disabled by omitting the arg
+ [
'warnings-as-errors=on',
'-j4',
'libs/redis/test',
'libs/redis/example'
])
# Get Boost
# Generate "pre-built" b2 distro
# Build the library, run the tests, and install, from the superproject
# Library tests, using the b2 Boost distribution generated before (this tests our normal dev workflow)
# Subdir tests, using add_subdirectory() (lib can be consumed using add_subdirectory)
# Subdir tests, using find_package with the library installed in the previous step
# (library can be consumed using find_package on a distro built by cmake)
# Subdir tests, using find_package with the b2 distribution
# (library can be consumed using find_package on a distro built by b2)
def main():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
subp = subparsers.add_parser('install-boost')
subp = subparsers.add_parser('setup-boost')
subp.add_argument('--source-dir', type=Path, required=True)
subp.set_defaults(func=_install_boost)
subp.set_defaults(func=_setup_boost)
subp = subparsers.add_parser('build-b2-distro')
subp.add_argument('--install-prefix', type=Path, required=True)
subp.set_defaults(func=_build_b2_distro)
subp = subparsers.add_parser('build-cmake-distro')
subp.add_argument('--install-prefix', type=Path, required=True)
subp.add_argument('--generator', default='Unix Makefiles')
subp.add_argument('--build-type', default='Debug')
subp.add_argument('--cxxstd', default='20')
@@ -293,7 +261,6 @@ def main():
subp.set_defaults(func=_build_cmake_distro)
subp = subparsers.add_parser('run-cmake-standalone-tests')
subp.add_argument('--b2-distro', type=Path, required=True)
subp.add_argument('--generator', default='Unix Makefiles')
subp.add_argument('--build-type', default='Debug')
subp.add_argument('--cxxstd', default='20')
@@ -307,29 +274,17 @@ def main():
subp.set_defaults(func=_run_cmake_add_subdirectory_tests)
subp = subparsers.add_parser('run-cmake-find-package-tests')
subp.add_argument('--cmake-distro', type=Path, required=True)
subp.add_argument('--generator', default='Unix Makefiles')
subp.add_argument('--build-type', default='Debug')
subp.add_argument('--build-shared-libs', type=_str2bool, default=False)
subp.set_defaults(func=_run_cmake_find_package_tests)
subp = subparsers.add_parser('run-cmake-b2-find-package-tests')
subp.add_argument('--cmake-distro', type=Path, required=True)
subp.add_argument('--generator', default='Unix Makefiles')
subp.add_argument('--build-type', default='Debug')
subp.add_argument('--build-shared-libs', type=_str2bool, default=False)
subp.set_defaults(func=_run_cmake_b2_find_package_tests)
subp = subparsers.add_parser('run-b2-tests')
subp.add_argument('--toolset', required=True)
subp.add_argument('--cxxstd', default='20')
subp.add_argument('--variant', default='debug,release')
subp.add_argument('--stdlib', default='native')
subp.add_argument('--address-model', default='64')
subp.add_argument('--address-sanitizer', type=_str2bool, default=False)
subp.add_argument('--undefined-sanitizer', type=_str2bool, default=False)
subp.set_defaults(func=_run_b2_tests)
args = parser.parse_args()
os.environ['CMAKE_BUILD_PARALLEL_LEVEL'] = '4'