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.

136 lines
3.7KB

  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
  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 '
  32. f'the "{sys.platform}" platform')
  33. url = f'https://github.com/vector-of-bool/dds/releases/download/0.1.0-alpha.4/{filename}'
  34. print(f'Downloading prebuilt DDS executable: {url}')
  35. stream = urllib.request.urlopen(url)
  36. paths.PREBUILT_DDS.parent.mkdir(exist_ok=True, parents=True)
  37. with paths.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 = paths.PREBUILT_DDS.stat().st_mode
  46. mode |= 0b001_001_001
  47. paths.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. '--toolchain',
  59. '-T',
  60. help='The toolchain to use for the CI process',
  61. required=True,
  62. )
  63. parser.add_argument(
  64. '--build-only',
  65. action='store_true',
  66. help='Only build the `dds` executable. Skip second-phase and tests.')
  67. args = parser.parse_args(argv)
  68. opts = CIOptions(toolchain=args.toolchain)
  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. old_cat_path = paths.PREBUILT_DIR / 'catalog.db'
  78. if old_cat_path.is_file():
  79. old_cat_path.unlink()
  80. ci_repo_dir = paths.PREBUILT_DIR / 'ci-repo'
  81. if ci_repo_dir.exists():
  82. shutil.rmtree(ci_repo_dir)
  83. self_build(
  84. paths.PREBUILT_DDS,
  85. toolchain=opts.toolchain,
  86. cat_path=old_cat_path,
  87. cat_json_path=Path('catalog.json'),
  88. dds_flags=[('--repo-dir', ci_repo_dir)])
  89. print('Main build PASSED!')
  90. print(f'A `dds` executable has been generated: {paths.CUR_BUILT_DDS}')
  91. if args.build_only:
  92. print(
  93. f'`--build-only` was given, so second phase and tests will not execute'
  94. )
  95. return 0
  96. print('Bootstrapping myself:')
  97. new_cat_path = paths.BUILD_DIR / 'catalog.db'
  98. new_repo_dir = paths.BUILD_DIR / 'ci-repo'
  99. self_build(
  100. paths.CUR_BUILT_DDS,
  101. toolchain=opts.toolchain,
  102. cat_path=new_cat_path,
  103. dds_flags=[f'--repo-dir={new_repo_dir}'])
  104. print('Bootstrap test PASSED!')
  105. return pytest.main([
  106. '-v',
  107. '--durations=10',
  108. f'--basetemp={paths.BUILD_DIR / "_tmp"}',
  109. '-n',
  110. str(multiprocessing.cpu_count() + 2),
  111. 'tests/',
  112. ])
  113. if __name__ == "__main__":
  114. sys.exit(main(sys.argv[1:]))