Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ci.py 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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.3/{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.old.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. self_build(
  99. paths.CUR_BUILT_DDS,
  100. toolchain=opts.toolchain,
  101. cat_path=new_cat_path,
  102. dds_flags=[f'--repo-dir={ci_repo_dir}'])
  103. print('Bootstrap test PASSED!')
  104. return pytest.main([
  105. '-v',
  106. '--durations=10',
  107. f'--basetemp={paths.BUILD_DIR / "_tmp"}',
  108. '-n',
  109. str(multiprocessing.cpu_count() + 2),
  110. 'tests/',
  111. ])
  112. if __name__ == "__main__":
  113. sys.exit(main(sys.argv[1:]))