您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

148 行
4.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. 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. 'freebsd11': 'dds-freebsd-x64',
  27. 'freebsd12': 'dds-freebsd-x64',
  28. }.get(sys.platform)
  29. if filename is None:
  30. raise RuntimeError(f'We do not have a prebuilt DDS binary for '
  31. f'the "{sys.platform}" platform')
  32. url = f'https://github.com/vector-of-bool/dds/releases/download/0.1.0-alpha.3/{filename}'
  33. print(f'Downloading prebuilt DDS executable: {url}')
  34. stream = urllib.request.urlopen(url)
  35. paths.PREBUILT_DDS.parent.mkdir(exist_ok=True, parents=True)
  36. with paths.PREBUILT_DDS.open('wb') as fd:
  37. while True:
  38. buf = stream.read(1024 * 4)
  39. if not buf:
  40. break
  41. fd.write(buf)
  42. if os.name != 'nt':
  43. # Mark the binary executable. By default it won't be
  44. mode = paths.PREBUILT_DDS.stat().st_mode
  45. mode |= 0b001_001_001
  46. paths.PREBUILT_DDS.chmod(mode)
  47. def main(argv: Sequence[str]) -> int:
  48. parser = argparse.ArgumentParser()
  49. parser.add_argument(
  50. '-B',
  51. '--bootstrap-with',
  52. help='How are we to obtain a bootstrapped DDS executable?',
  53. choices=('download', 'build', 'skip'),
  54. required=True,
  55. )
  56. parser.add_argument(
  57. '--toolchain',
  58. '-T',
  59. help='The toolchain to use for the CI process',
  60. required=True,
  61. )
  62. parser.add_argument(
  63. '--build-only',
  64. action='store_true',
  65. help='Only build the `dds` executable. Skip second-phase and tests.')
  66. args = parser.parse_args(argv)
  67. opts = CIOptions(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. old_cat_path = paths.PREBUILT_DIR / 'catalog.db'
  77. if old_cat_path.is_file():
  78. old_cat_path.unlink()
  79. ci_repo_dir = paths.PREBUILT_DIR / '_ci-repo'
  80. if ci_repo_dir.exists():
  81. shutil.rmtree(ci_repo_dir)
  82. proc.check_run([
  83. paths.PREBUILT_DDS,
  84. 'catalog',
  85. 'import',
  86. ('--catalog', old_cat_path),
  87. ('--json', paths.PROJECT_ROOT / 'catalog.json'),
  88. ])
  89. self_build(paths.PREBUILT_DDS,
  90. toolchain=opts.toolchain,
  91. cat_path=old_cat_path,
  92. dds_flags=[('--repo-dir', ci_repo_dir)])
  93. print('Main build PASSED!')
  94. print(f'A `dds` executable has been generated: {paths.CUR_BUILT_DDS}')
  95. if args.build_only:
  96. print(
  97. f'`--build-only` was given, so second phase and tests will not execute'
  98. )
  99. return 0
  100. # Delete the catalog database, since there may be schema changes since the
  101. # bootstrap executable was built
  102. new_cat_path = paths.BUILD_DIR / 'catalog.db'
  103. if new_cat_path.exists():
  104. new_cat_path.unlink()
  105. proc.check_run([
  106. paths.CUR_BUILT_DDS,
  107. 'catalog',
  108. 'import',
  109. ('--catalog', new_cat_path),
  110. ('--json', paths.PROJECT_ROOT / 'catalog.json'),
  111. ])
  112. self_build(paths.CUR_BUILT_DDS,
  113. toolchain=opts.toolchain,
  114. cat_path=new_cat_path,
  115. dds_flags=[f'--repo-dir={ci_repo_dir}'])
  116. print('Bootstrap test PASSED!')
  117. return pytest.main([
  118. '-v',
  119. '--durations=10',
  120. f'--basetemp={paths.BUILD_DIR / "_tmp"}',
  121. '-n4',
  122. 'tests/',
  123. ])
  124. if __name__ == "__main__":
  125. sys.exit(main(sys.argv[1:]))