No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. ci_repo_dir = paths.BUILD_DIR / '_ci-repo'
  71. if ci_repo_dir.exists():
  72. shutil.rmtree(ci_repo_dir)
  73. proc.check_run([
  74. paths.PREBUILT_DDS,
  75. 'catalog',
  76. 'import',
  77. ('--catalog', cat_path),
  78. ('--json', paths.PROJECT_ROOT / 'catalog.json'),
  79. ])
  80. self_build(
  81. paths.PREBUILT_DDS,
  82. toolchain=opts.toolchain,
  83. dds_flags=[
  84. ('--catalog', cat_path),
  85. ('--repo-dir', ci_repo_dir),
  86. ])
  87. print('Main build PASSED!')
  88. proc.check_run([
  89. paths.CUR_BUILT_DDS,
  90. 'catalog',
  91. 'import',
  92. ('--catalog', cat_path),
  93. ('--json', paths.PROJECT_ROOT / 'catalog.json'),
  94. ])
  95. self_build(
  96. paths.CUR_BUILT_DDS,
  97. toolchain=opts.toolchain,
  98. dds_flags=[f'--repo-dir={ci_repo_dir}', f'--catalog={cat_path}'])
  99. print('Bootstrap test PASSED!')
  100. return pytest.main([
  101. '-v',
  102. '--durations=10',
  103. f'--basetemp={paths.BUILD_DIR / "_tmp"}',
  104. '-n4',
  105. 'tests/',
  106. ])
  107. if __name__ == "__main__":
  108. sys.exit(main(sys.argv[1:]))