Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

62 lines
2.1KB

  1. import json
  2. import sys
  3. from contextlib import contextmanager
  4. from pathlib import Path
  5. from typing import Iterator
  6. import json5
  7. from . import paths
  8. @contextmanager
  9. def fixup_toolchain(json_file: Path) -> Iterator[Path]:
  10. """
  11. Augment the toolchain at the given path by adding 'ccache' or -fuse-ld=lld,
  12. if those tools are available on the system. Yields a new toolchain file
  13. based on 'json_file'
  14. """
  15. data = json5.loads(json_file.read_text())
  16. # Check if we can add ccache
  17. ccache = paths.find_exe('ccache')
  18. if ccache:
  19. print('Found ccache:', ccache)
  20. data['compiler_launcher'] = [str(ccache)]
  21. # Check for lld for use with GCC/Clang
  22. if paths.find_exe('ld.lld') and data.get('compiler_id') in ('gnu', 'clang'):
  23. print('Linking with `-fuse-ld=lld`')
  24. data.setdefault('link_flags', []).append('-fuse-ld=lld')
  25. # Save the new toolchain data
  26. with paths.new_tempdir() as tdir:
  27. new_json = tdir / json_file.name
  28. new_json.write_text(json.dumps(data))
  29. yield new_json
  30. def get_default_test_toolchain() -> Path:
  31. """
  32. Get the default toolchain that should be used for dev and test based on the
  33. host platform.
  34. """
  35. if sys.platform == 'win32':
  36. return paths.TOOLS_DIR / 'msvc-audit.jsonc'
  37. if sys.platform in 'linux':
  38. return paths.TOOLS_DIR / 'gcc-9-audit.jsonc'
  39. if sys.platform == 'darwin':
  40. return paths.TOOLS_DIR / 'gcc-9-audit-macos.jsonc'
  41. raise RuntimeError(f'Unable to determine the default toolchain (sys.platform is {sys.platform!r})')
  42. def get_default_toolchain() -> Path:
  43. """
  44. Get the default toolchain that should be used to generate the release executable
  45. based on the host platform.
  46. """
  47. if sys.platform == 'win32':
  48. return paths.TOOLS_DIR / 'msvc-rel.jsonc'
  49. if sys.platform == 'linux':
  50. return paths.TOOLS_DIR / 'gcc-9-rel.jsonc'
  51. if sys.platform == 'darwin':
  52. return paths.TOOLS_DIR / 'gcc-9-rel-macos.jsonc'
  53. raise RuntimeError(f'Unable to determine the default toolchain (sys.platform is {sys.platform!r})')