You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ci.py 4.3KB

5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. toolchain_json5: 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. }.get(sys.platform)
  28. if filename is None:
  29. raise RuntimeError(f'We do not have a prebuilt DDS binary for '
  30. f'the "{sys.platform}" platform')
  31. url = f'https://github.com/vector-of-bool/dds/releases/download/0.0.1/{filename}'
  32. print(f'Downloading prebuilt DDS executable: {url}')
  33. stream = urllib.request.urlopen(url)
  34. paths.PREBUILT_DDS.parent.mkdir(exist_ok=True, parents=True)
  35. with paths.PREBUILT_DDS.open('wb') as fd:
  36. while True:
  37. buf = stream.read(1024 * 4)
  38. if not buf:
  39. break
  40. fd.write(buf)
  41. if os.name != 'nt':
  42. # Mark the binary executable. By default it won't be
  43. mode = paths.PREBUILT_DDS.stat().st_mode
  44. mode |= 0b001_001_001
  45. paths.PREBUILT_DDS.chmod(mode)
  46. def main(argv: Sequence[str]) -> int:
  47. parser = argparse.ArgumentParser()
  48. parser.add_argument(
  49. '-B',
  50. '--bootstrap-with',
  51. help='How are we to obtain a bootstrapped DDS executable?',
  52. choices=('download', 'build', 'skip'),
  53. required=True,
  54. )
  55. parser.add_argument(
  56. '--toolchain',
  57. '-T',
  58. help='The toolchain to use for the CI process',
  59. required=True)
  60. parser.add_argument(
  61. '--toolchain-json5',
  62. '-T2',
  63. help='The toolchain JSON to use with the bootstrapped executable',
  64. )
  65. parser.add_argument(
  66. '--build-only',
  67. action='store_true',
  68. help='Only build the `dds` executable. Skip second-phase and tests.')
  69. args = parser.parse_args(argv)
  70. if not args.build_only and not args.toolchain_json5:
  71. raise RuntimeError(
  72. 'The --toolchain-json5/-T2 argument is required (unless using --build-only)'
  73. )
  74. opts = CIOptions(
  75. toolchain=args.toolchain, toolchain_json5=args.toolchain_json5)
  76. if args.bootstrap_with == 'build':
  77. _do_bootstrap_build(opts)
  78. elif args.bootstrap_with == 'download':
  79. _do_bootstrap_download()
  80. elif args.bootstrap_with == 'skip':
  81. pass
  82. else:
  83. assert False, 'impossible'
  84. cat_path = paths.BUILD_DIR / 'catalog.db'
  85. if cat_path.is_file():
  86. cat_path.unlink()
  87. ci_repo_dir = paths.BUILD_DIR / '_ci-repo'
  88. if ci_repo_dir.exists():
  89. shutil.rmtree(ci_repo_dir)
  90. proc.check_run([
  91. paths.PREBUILT_DDS,
  92. 'catalog',
  93. 'import',
  94. ('--catalog', cat_path),
  95. ('--json', paths.PROJECT_ROOT / 'catalog.json'),
  96. ])
  97. self_build(
  98. paths.PREBUILT_DDS,
  99. toolchain=opts.toolchain,
  100. dds_flags=[
  101. ('--catalog', cat_path),
  102. ('--repo-dir', ci_repo_dir),
  103. ])
  104. print('Main build PASSED!')
  105. print(f'A `dds` executable has been generated: {paths.CUR_BUILT_DDS}')
  106. if args.build_only:
  107. print(
  108. f'`--build-only` was given, so second phase and tests will not execute'
  109. )
  110. return 0
  111. # Delete the catalog database, since there may be schema changes since the
  112. # bootstrap executable was built
  113. cat_path.unlink()
  114. proc.check_run([
  115. paths.CUR_BUILT_DDS,
  116. 'catalog',
  117. 'import',
  118. ('--catalog', cat_path),
  119. ('--json', paths.PROJECT_ROOT / 'catalog.json'),
  120. ])
  121. self_build(
  122. paths.CUR_BUILT_DDS,
  123. toolchain=opts.toolchain_json5,
  124. dds_flags=[f'--repo-dir={ci_repo_dir}', f'--catalog={cat_path}'])
  125. print('Bootstrap test PASSED!')
  126. return pytest.main([
  127. '-v',
  128. '--durations=10',
  129. f'--basetemp={paths.BUILD_DIR / "_tmp"}',
  130. '-n4',
  131. 'tests/',
  132. ])
  133. if __name__ == "__main__":
  134. sys.exit(main(sys.argv[1:]))