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

ci.py 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. import shutil
  10. from self_build import self_build
  11. from dds_ci import paths, proc
  12. class CIOptions(NamedTuple):
  13. toolchain: str
  14. def _do_bootstrap_build(opts: CIOptions) -> None:
  15. print('Bootstrapping by a local build of prior versions...')
  16. subprocess.check_call([
  17. sys.executable,
  18. '-u',
  19. str(paths.TOOLS_DIR / 'bootstrap.py'),
  20. ])
  21. def _do_bootstrap_download() -> None:
  22. filename = {
  23. 'win32': 'dds-win-x64.exe',
  24. 'linux': 'dds-linux-x64',
  25. 'darwin': 'dds-macos-x64',
  26. }.get(sys.platform)
  27. if filename is None:
  28. raise RuntimeError(f'We do not have a prebuilt DDS binary for '
  29. f'the "{sys.platform}" platform')
  30. url = f'https://github.com/vector-of-bool/dds/releases/download/0.0.1/{filename}'
  31. print(f'Downloading prebuilt DDS executable: {url}')
  32. stream = urllib.request.urlopen(url)
  33. paths.PREBUILT_DDS.parent.mkdir(exist_ok=True, parents=True)
  34. with paths.PREBUILT_DDS.open('wb') as fd:
  35. while True:
  36. buf = stream.read(1024 * 4)
  37. if not buf:
  38. break
  39. fd.write(buf)
  40. if os.name != 'nt':
  41. # Mark the binary executable. By default it won't be
  42. mode = paths.PREBUILT_DDS.stat().st_mode
  43. mode |= 0b001_001_001
  44. paths.PREBUILT_DDS.chmod(mode)
  45. def main(argv: Sequence[str]) -> int:
  46. parser = argparse.ArgumentParser()
  47. parser.add_argument(
  48. '-B',
  49. '--bootstrap-with',
  50. help='How are we to obtain a bootstrapped DDS executable?',
  51. choices=('download', 'build', 'skip'),
  52. required=True,
  53. )
  54. parser.add_argument(
  55. '--toolchain',
  56. '-T',
  57. help='The toolchain to use for the CI process',
  58. required=True)
  59. args = parser.parse_args(argv)
  60. opts = CIOptions(toolchain=args.toolchain)
  61. if args.bootstrap_with == 'build':
  62. _do_bootstrap_build(opts)
  63. elif args.bootstrap_with == 'download':
  64. _do_bootstrap_download()
  65. elif args.bootstrap_with == 'skip':
  66. pass
  67. else:
  68. assert False, 'impossible'
  69. cat_path = paths.BUILD_DIR / 'catalog.db'
  70. if cat_path.is_file():
  71. cat_path.unlink()
  72. ci_repo_dir = paths.BUILD_DIR / '_ci-repo'
  73. if ci_repo_dir.exists():
  74. shutil.rmtree(ci_repo_dir)
  75. proc.check_run([
  76. paths.PREBUILT_DDS,
  77. 'catalog',
  78. 'import',
  79. ('--catalog', cat_path),
  80. ('--json', paths.PROJECT_ROOT / 'catalog.json'),
  81. ])
  82. self_build(
  83. paths.PREBUILT_DDS,
  84. toolchain=opts.toolchain,
  85. dds_flags=[
  86. ('--catalog', cat_path),
  87. ('--repo-dir', ci_repo_dir),
  88. ])
  89. print('Main build PASSED!')
  90. # Delete the catalog database, since there may be schema changes since the
  91. # bootstrap executable was built
  92. cat_path.unlink()
  93. proc.check_run([
  94. paths.CUR_BUILT_DDS,
  95. 'catalog',
  96. 'import',
  97. ('--catalog', cat_path),
  98. ('--json', paths.PROJECT_ROOT / 'catalog.json'),
  99. ])
  100. self_build(
  101. paths.CUR_BUILT_DDS,
  102. toolchain=opts.toolchain,
  103. dds_flags=[f'--repo-dir={ci_repo_dir}', f'--catalog={cat_path}'])
  104. print('Bootstrap test PASSED!')
  105. return pytest.main([
  106. '-v',
  107. '--durations=10',
  108. f'--basetemp={paths.BUILD_DIR / "_tmp"}',
  109. '-n4',
  110. 'tests/',
  111. ])
  112. if __name__ == "__main__":
  113. sys.exit(main(sys.argv[1:]))