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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 distro.id() == 'alpine':
  39. # Alpine Linux cannot use the full audit mode, as asan and ubsan do not
  40. # work with musl
  41. return paths.TOOLS_DIR / 'gcc-9-test.jsonc'
  42. if sys.platform == 'win32':
  43. return paths.TOOLS_DIR / 'msvc-audit.jsonc'
  44. if sys.platform == 'linux':
  45. return paths.TOOLS_DIR / 'gcc-9-audit.jsonc'
  46. if sys.platform == 'darwin':
  47. return paths.TOOLS_DIR / 'gcc-9-audit-macos.jsonc'
  48. raise RuntimeError(f'Unable to determine the default toolchain (sys.platform is {sys.platform!r})')
  49. def get_default_test_toolchain() -> Path:
  50. """
  51. Get the default toolchain that should be used by tests that need a toolchain
  52. to use for executing dds.
  53. """
  54. if sys.platform == 'win32':
  55. return paths.TESTS_DIR / 'msvc.tc.jsonc'
  56. if sys.platform in ('linux', 'darwin'):
  57. return paths.TESTS_DIR / 'gcc-9.tc.jsonc'
  58. raise RuntimeError(f'Unable to determine the default toolchain (sys.platform is {sys.platform!r})')
  59. def get_default_toolchain() -> Path:
  60. """
  61. Get the default toolchain that should be used to generate the release executable
  62. based on the host platform.
  63. """
  64. if sys.platform == 'win32':
  65. return paths.TOOLS_DIR / 'msvc-rel.jsonc'
  66. if sys.platform == 'linux':
  67. return paths.TOOLS_DIR / 'gcc-9-rel.jsonc'
  68. if sys.platform == 'darwin':
  69. return paths.TOOLS_DIR / 'gcc-9-rel-macos.jsonc'
  70. raise RuntimeError(f'Unable to determine the default toolchain (sys.platform is {sys.platform!r})')