diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-29 19:28:09 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-29 19:28:09 +0100 |
| commit | 67b2fae1fa8b033045a44c1355d9dfd8f83e0d9b (patch) | |
| tree | 1ecd818f4bcf7d12622d43dc92c4d4bb9b746d0f /contrib/catch2/tests/TestScripts/ConfigureTestsCommon.py | |
| parent | a8b0ea58e60bb0326b7f7c8f3c736d89ce9ef1df (diff) | |
| parent | bc524d70253a4ab2fe40c3ca3e5666e267c0a4d1 (diff) | |
| download | nihil-67b2fae1fa8b033045a44c1355d9dfd8f83e0d9b.tar.gz nihil-67b2fae1fa8b033045a44c1355d9dfd8f83e0d9b.tar.bz2 | |
Add 'contrib/catch2/' from commit 'bc524d70253a4ab2fe40c3ca3e5666e267c0a4d1'
git-subtree-dir: contrib/catch2
git-subtree-mainline: a8b0ea58e60bb0326b7f7c8f3c736d89ce9ef1df
git-subtree-split: bc524d70253a4ab2fe40c3ca3e5666e267c0a4d1
Diffstat (limited to 'contrib/catch2/tests/TestScripts/ConfigureTestsCommon.py')
| -rw-r--r-- | contrib/catch2/tests/TestScripts/ConfigureTestsCommon.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/contrib/catch2/tests/TestScripts/ConfigureTestsCommon.py b/contrib/catch2/tests/TestScripts/ConfigureTestsCommon.py new file mode 100644 index 0000000..13b1d92 --- /dev/null +++ b/contrib/catch2/tests/TestScripts/ConfigureTestsCommon.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 + +# Copyright Catch2 Authors +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# SPDX-License-Identifier: BSL-1.0 + +from typing import List, Tuple + +import os +import subprocess + +def configure_and_build(source_path: str, project_path: str, options: List[Tuple[str, str]]): + base_configure_cmd = ['cmake', + '-B{}'.format(project_path), + '-H{}'.format(source_path), + '-DCMAKE_BUILD_TYPE=Debug', + '-DCATCH_DEVELOPMENT_BUILD=ON'] + for option, value in options: + base_configure_cmd.append('-D{}={}'.format(option, value)) + try: + subprocess.run(base_configure_cmd, + stdout = subprocess.PIPE, + stderr = subprocess.STDOUT, + check = True) + except subprocess.SubprocessError as ex: + print("Could not configure build to '{}' from '{}'".format(project_path, source_path)) + print("Return code: {}".format(ex.returncode)) + print("output: {}".format(ex.output)) + raise + print('Configuring {} finished'.format(project_path)) + + build_cmd = ['cmake', + '--build', '{}'.format(project_path), + # For now we assume that we only need Debug config + '--config', 'Debug'] + try: + subprocess.run(build_cmd, + stdout = subprocess.PIPE, + stderr = subprocess.STDOUT, + check = True) + except subprocess.SubprocessError as ex: + print("Could not build project in '{}'".format(project_path)) + print("Return code: {}".format(ex.returncode)) + print("output: {}".format(ex.output)) + raise + print('Building {} finished'.format(project_path)) + +def run_and_return_output(base_path: str, binary_name: str, other_options: List[str]) -> Tuple[str, str]: + # For now we assume that Windows builds are done using MSBuild under + # Debug configuration. This means that we need to add "Debug" folder + # to the path when constructing it. On Linux, we don't add anything. + config_path = "Debug" if os.name == 'nt' else "" + full_path = os.path.join(base_path, config_path, binary_name) + + base_cmd = [full_path] + base_cmd.extend(other_options) + + try: + ret = subprocess.run(base_cmd, + stdout = subprocess.PIPE, + stderr = subprocess.PIPE, + check = True, + universal_newlines = True) + except subprocess.SubprocessError as ex: + print('Could not run "{}"'.format(base_cmd)) + print('Args: "{}"'.format(other_options)) + print('Return code: {}'.format(ex.returncode)) + print('stdout: {}'.format(ex.stdout)) + print('stderr: {}'.format(ex.stdout)) + raise + + return (ret.stdout, ret.stderr) |
