File: ConfigureTestsCommon.py

package info (click to toggle)
sfxr-qt 1.5.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,988 kB
  • sloc: cpp: 48,737; python: 1,885; sh: 385; makefile: 4
file content (75 lines) | stat: -rw-r--r-- 3,039 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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)