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ů.

77 lines
2.6KB

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