Debian Codegraph @

tests/TestScripts/ConfigureTestsCommon.py

raw
1 #!/usr/bin/env python3
2
3 # Copyright Catch2 Authors
4 # Distributed under the Boost Software License, Version 1.0.
5 # (See accompanying file LICENSE.txt or copy at
6 # https://www.boost.org/LICENSE_1_0.txt)
7
8 # SPDX-License-Identifier: BSL-1.0
9
10 from typing import List, Tuple
11
12 import os
13 import subprocess
14
15 def configure_and_build(source_path: str, project_path: str, options: List[Tuple[str, str]]):
16 base_configure_cmd = ['cmake',
17 '-B{}'.format(project_path),
18 '-H{}'.format(source_path),
19 '-DCMAKE_BUILD_TYPE=Debug',
20 '-DCATCH_DEVELOPMENT_BUILD=ON']
21 for option, value in options:
22 base_configure_cmd.append('-D{}={}'.format(option, value))
23 try:
24 subprocess.run(base_configure_cmd,
25 stdout = subprocess.PIPE,
26 stderr = subprocess.STDOUT,
27 check = True)
28 except subprocess.SubprocessError as ex:
29 print("Could not configure build to '{}' from '{}'".format(project_path, source_path))
30 print("Return code: {}".format(ex.returncode))
31 print("output: {}".format(ex.output))
32 raise
33 print('Configuring {} finished'.format(project_path))
34
35 build_cmd = ['cmake',
36 '--build', '{}'.format(project_path),
37 # For now we assume that we only need Debug config
38 '--config', 'Debug']
39 try:
40 subprocess.run(build_cmd,
41 stdout = subprocess.PIPE,
42 stderr = subprocess.STDOUT,
43 check = True)
44 except subprocess.SubprocessError as ex:
45 print("Could not build project in '{}'".format(project_path))
46 print("Return code: {}".format(ex.returncode))
47 print("output: {}".format(ex.output))
48 raise
49 print('Building {} finished'.format(project_path))
50
51 def run_and_return_output(base_path: str, binary_name: str, other_options: List[str]) -> Tuple[str, str]:
52 # For now we assume that Windows builds are done using MSBuild under
53 # Debug configuration. This means that we need to add "Debug" folder
54 # to the path when constructing it. On Linux, we don't add anything.
55 config_path = "Debug" if os.name == 'nt' else ""
56 full_path = os.path.join(base_path, config_path, binary_name)
57
58 base_cmd = [full_path]
59 base_cmd.extend(other_options)
60
61 try:
62 ret = subprocess.run(base_cmd,
63 stdout = subprocess.PIPE,
64 stderr = subprocess.PIPE,
65 check = True,
66 universal_newlines = True)
67 except subprocess.SubprocessError as ex:
68 print('Could not run "{}"'.format(base_cmd))
69 print('Args: "{}"'.format(other_options))
70 print('Return code: {}'.format(ex.returncode))
71 print('stdout: {}'.format(ex.stdout))
72 print('stderr: {}'.format(ex.stdout))
73 raise
74
75 return (ret.stdout, ret.stderr)