選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

119 行
3.1KB

  1. import argparse
  2. import os
  3. import sys
  4. import pytest
  5. from pathlib import Path
  6. from typing import Sequence, NamedTuple
  7. import subprocess
  8. import urllib.request
  9. HERE = Path(__file__).parent.absolute()
  10. TOOLS_DIR = HERE
  11. PROJECT_ROOT = HERE.parent
  12. PREBUILT_DDS = PROJECT_ROOT / '_prebuilt/dds'
  13. class CIOptions(NamedTuple):
  14. cxx: Path
  15. toolchain: str
  16. def _do_bootstrap_build(opts: CIOptions) -> None:
  17. print('Bootstrapping by a local build of prior versions...')
  18. subprocess.check_call([
  19. sys.executable,
  20. '-u',
  21. str(TOOLS_DIR / 'bootstrap.py'),
  22. f'--cxx={opts.cxx}',
  23. ])
  24. def _do_bootstrap_download() -> None:
  25. filename = {
  26. 'win32': 'dds-win-x64.exe',
  27. 'linux': 'dds-linux-x64',
  28. 'darwin': 'dds-macos-x64',
  29. }.get(sys.platform)
  30. if filename is None:
  31. raise RuntimeError(f'We do not have a prebuilt DDS binary for '
  32. f'the "{sys.platform}" platform')
  33. url = f'https://github.com/vector-of-bool/dds/releases/download/bootstrap-p2/{filename}'
  34. print(f'Downloading prebuilt DDS executable: {url}')
  35. stream = urllib.request.urlopen(url)
  36. PREBUILT_DDS.parent.mkdir(exist_ok=True, parents=True)
  37. with PREBUILT_DDS.open('wb') as fd:
  38. while True:
  39. buf = stream.read(1024 * 4)
  40. if not buf:
  41. break
  42. fd.write(buf)
  43. if os.name != 'nt':
  44. # Mark the binary executable. By default it won't be
  45. mode = PREBUILT_DDS.stat().st_mode
  46. mode |= 0b001_001_001
  47. PREBUILT_DDS.chmod(mode)
  48. def main(argv: Sequence[str]) -> int:
  49. parser = argparse.ArgumentParser()
  50. parser.add_argument(
  51. '-B',
  52. '--bootstrap-with',
  53. help='How are we to obtain a bootstrapped DDS executable?',
  54. choices=('download', 'build', 'skip'),
  55. required=True,
  56. )
  57. parser.add_argument(
  58. '--cxx',
  59. help='The name/path of the C++ compiler to use.',
  60. required=True)
  61. parser.add_argument(
  62. '--toolchain',
  63. '-T',
  64. help='The toolchain to use for the CI process',
  65. required=True)
  66. args = parser.parse_args(argv)
  67. opts = CIOptions(cxx=Path(args.cxx), toolchain=args.toolchain)
  68. if args.bootstrap_with == 'build':
  69. _do_bootstrap_build(opts)
  70. elif args.bootstrap_with == 'download':
  71. _do_bootstrap_download()
  72. elif args.bootstrap_with == 'skip':
  73. pass
  74. else:
  75. assert False, 'impossible'
  76. subprocess.check_call([
  77. str(PREBUILT_DDS),
  78. 'deps',
  79. 'build',
  80. f'-T{opts.toolchain}',
  81. f'--repo-dir={PROJECT_ROOT / "external/repo"}',
  82. ])
  83. subprocess.check_call([
  84. str(PREBUILT_DDS),
  85. 'build',
  86. '--full',
  87. f'-T{opts.toolchain}',
  88. ])
  89. exe_suffix = '.exe' if os.name == 'nt' else ''
  90. subprocess.check_call([
  91. sys.executable,
  92. '-u',
  93. str(TOOLS_DIR / 'self-test.py'),
  94. f'--exe={PROJECT_ROOT / f"_build/dds{exe_suffix}"}',
  95. f'-T{opts.toolchain}',
  96. ])
  97. return pytest.main(['-v', '--durations=10'])
  98. if __name__ == "__main__":
  99. sys.exit(main(sys.argv[1:]))