Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

144 lines
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 multiprocessing
  8. import subprocess
  9. import urllib.request
  10. import shutil
  11. from self_build import self_build, dds_build
  12. from dds_ci import paths, proc
  13. class CIOptions(NamedTuple):
  14. toolchain: 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. 'freebsd11': 'dds-freebsd-x64',
  28. 'freebsd12': 'dds-freebsd-x64',
  29. }.get(sys.platform)
  30. if filename is None:
  31. raise RuntimeError(f'We do not have a prebuilt DDS binary for the "{sys.platform}" platform')
  32. url = f'https://github.com/vector-of-bool/dds/releases/download/0.1.0-alpha.4/{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', action='store_true', help='Only build the `dds` executable. Skip second-phase and tests.')
  64. parser.add_argument(
  65. '--no-clean',
  66. action='store_false',
  67. dest='clean',
  68. help='Don\'t remove prior build/deps results',
  69. )
  70. args = parser.parse_args(argv)
  71. opts = CIOptions(toolchain=args.toolchain)
  72. if args.bootstrap_with == 'build':
  73. _do_bootstrap_build(opts)
  74. elif args.bootstrap_with == 'download':
  75. _do_bootstrap_download()
  76. elif args.bootstrap_with == 'skip':
  77. pass
  78. else:
  79. assert False, 'impossible'
  80. old_cat_path = paths.PREBUILT_DIR / 'catalog.db'
  81. if old_cat_path.is_file() and args.clean:
  82. old_cat_path.unlink()
  83. ci_repo_dir = paths.PREBUILT_DIR / 'ci-repo'
  84. if ci_repo_dir.exists() and args.clean:
  85. shutil.rmtree(ci_repo_dir)
  86. self_build(
  87. paths.PREBUILT_DDS,
  88. toolchain=opts.toolchain,
  89. cat_path=old_cat_path,
  90. cat_json_path=Path('old-catalog.json'),
  91. dds_flags=[('--repo-dir', ci_repo_dir)])
  92. print('Main build PASSED!')
  93. print(f'A `dds` executable has been generated: {paths.CUR_BUILT_DDS}')
  94. if args.build_only:
  95. print('`--build-only` was given, so second phase and tests will not execute')
  96. return 0
  97. print('Bootstrapping myself:')
  98. new_cat_path = paths.BUILD_DIR / 'catalog.db'
  99. new_repo_dir = paths.BUILD_DIR / 'ci-repo-2'
  100. if new_cat_path.is_file():
  101. new_cat_path.unlink()
  102. if new_repo_dir.is_dir():
  103. shutil.rmtree(new_repo_dir)
  104. dds_build(
  105. paths.CUR_BUILT_DDS,
  106. toolchain=opts.toolchain,
  107. more_flags=[
  108. f'--repo-dir={new_repo_dir}',
  109. f'--catalog={new_cat_path}',
  110. '--add-repo=https://dds.pizza/repo',
  111. ])
  112. print('Bootstrap test PASSED!')
  113. return pytest.main([
  114. '-v',
  115. '--durations=10',
  116. f'--basetemp={paths.BUILD_DIR / "_tmp"}',
  117. '-n',
  118. str(multiprocessing.cpu_count() + 2),
  119. 'tests/',
  120. ])
  121. if __name__ == "__main__":
  122. sys.exit(main(sys.argv[1:]))