You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.2KB

  1. #!/usr/bin/env python3
  2. import argparse
  3. from contextlib import contextmanager
  4. import os
  5. from pathlib import Path
  6. from typing import Sequence
  7. import subprocess
  8. import sys
  9. import shutil
  10. import tempfile
  11. from dds_ci import paths
  12. from self_build import self_build
  13. from self_deps_get import self_deps_get
  14. from self_deps_build import self_deps_build
  15. ROOT = Path(__file__).parent.parent.absolute()
  16. BUILD_DIR = ROOT / '_build'
  17. @contextmanager
  18. def _generate_toolchain(cxx: str):
  19. with tempfile.NamedTemporaryFile(
  20. suffix='-dds-toolchain.dds', mode='wb', delete=False) as f:
  21. comp_id = 'GNU'
  22. flags = ''
  23. link_flags = ''
  24. if cxx in ('cl', 'cl.exe'):
  25. comp_id = 'MSVC'
  26. flags += '/experimental:preprocessor '
  27. link_flags += 'rpcrt4.lib '
  28. else:
  29. flags += '-fconcepts'
  30. flags += ' -DSPDLOG_COMPILED_LIB'
  31. content = f'''
  32. Compiler-ID: {comp_id}
  33. C++-Compiler: {cxx}
  34. C++-Version: C++17
  35. Debug: True
  36. Flags: {flags}
  37. Link-Flags: {link_flags}
  38. '''
  39. print('Using generated toolchain file: ' + content)
  40. f.write(content.encode('utf-8'))
  41. f.close()
  42. yield Path(f.name)
  43. os.unlink(f.name)
  44. def main(argv: Sequence[str]) -> int:
  45. parser = argparse.ArgumentParser()
  46. parser.add_argument(
  47. '--cxx', help='Path/name of the C++ compiler to use.', required=True)
  48. args = parser.parse_args(argv)
  49. dds_bootstrap_env_key = 'DDS_BOOTSTRAP_PREV_EXE'
  50. if dds_bootstrap_env_key not in os.environ:
  51. raise RuntimeError('A previous-phase bootstrapped executable '
  52. 'must be available via $DDS_BOOTSTRAP_PREV_EXE')
  53. dds_exe = Path(os.environ[dds_bootstrap_env_key])
  54. if BUILD_DIR.exists():
  55. shutil.rmtree(BUILD_DIR)
  56. print(f'Using previously built DDS executable: {dds_exe}')
  57. self_deps_get(dds_exe, paths.SELF_TEST_REPO_DIR)
  58. with _generate_toolchain(args.cxx) as tc_fpath:
  59. self_deps_build(dds_exe, tc_fpath, paths.SELF_TEST_REPO_DIR,
  60. ROOT / 'remote.dds')
  61. self_build(dds_exe, toolchain=tc_fpath, dds_flags=['--apps'])
  62. return 0
  63. if __name__ == "__main__":
  64. sys.exit(main(sys.argv[1:]))