Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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 subprocess
  8. import urllib.request
  9. import shutil
  10. from self_build import self_build
  11. from self_deps_get import self_deps_get
  12. from self_deps_build import self_deps_build
  13. from dds_ci import paths, proc
  14. class CIOptions(NamedTuple):
  15. toolchain: str
  16. skip_deps: bool
  17. def _do_bootstrap_build(opts: CIOptions) -> None:
  18. print('Bootstrapping by a local build of prior versions...')
  19. subprocess.check_call([
  20. sys.executable,
  21. '-u',
  22. str(paths.TOOLS_DIR / 'bootstrap.py'),
  23. ])
  24. def _do_bootstrap_download() -> None:
  25. filename = {
  26. 'win32': 'dds-win-x64.exe',
  27. 'linux': 'dds-linux-x64',
  28. 'darwin': 'dds-macos-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/bootstrap-p4/{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. parser.add_argument(
  63. '--skip-deps',
  64. action='store_true',
  65. help='If specified, will skip getting and building '
  66. 'dependencies. (They must already be present)')
  67. args = parser.parse_args(argv)
  68. opts = CIOptions(toolchain=args.toolchain, skip_deps=args.skip_deps)
  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. ci_repo_dir = paths.BUILD_DIR / '_ci-repo'
  79. if ci_repo_dir.exists():
  80. shutil.rmtree(ci_repo_dir)
  81. proc.check_run([
  82. paths.PREBUILT_DDS,
  83. 'catalog',
  84. 'import',
  85. ('--catalog', cat_path),
  86. ('--json', paths.PROJECT_ROOT / 'catalog.json'),
  87. ])
  88. self_build(
  89. paths.PREBUILT_DDS,
  90. toolchain=opts.toolchain,
  91. dds_flags=[
  92. ('--catalog', cat_path),
  93. ('--repo-dir', ci_repo_dir),
  94. ])
  95. print('Main build PASSED!')
  96. proc.check_run([
  97. paths.CUR_BUILT_DDS,
  98. 'catalog',
  99. 'import',
  100. ('--catalog', cat_path),
  101. ('--json', paths.PROJECT_ROOT / 'catalog.json'),
  102. ])
  103. self_build(
  104. paths.CUR_BUILT_DDS,
  105. toolchain=opts.toolchain,
  106. dds_flags=[f'--repo-dir={ci_repo_dir}', f'--catalog={cat_path}'])
  107. print('Bootstrap test PASSED!')
  108. return pytest.main([
  109. '-v',
  110. '--durations=10',
  111. f'--basetemp={paths.BUILD_DIR / "_tmp"}',
  112. '-n4',
  113. 'tests/',
  114. ])
  115. if __name__ == "__main__":
  116. sys.exit(main(sys.argv[1:]))