Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

75 lines
2.0KB

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