ConfigureTestsCommon.py 3.0 KB

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