Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

143 lines
3.8KB

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