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.

142 satır
3.9KB

  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. parser.add_argument(
  68. '--no-clean',
  69. action='store_false',
  70. dest='clean',
  71. help='Don\'t remove prior build/deps results',
  72. )
  73. args = parser.parse_args(argv)
  74. opts = CIOptions(toolchain=args.toolchain)
  75. if args.bootstrap_with == 'build':
  76. _do_bootstrap_build(opts)
  77. elif args.bootstrap_with == 'download':
  78. _do_bootstrap_download()
  79. elif args.bootstrap_with == 'skip':
  80. pass
  81. else:
  82. assert False, 'impossible'
  83. old_cat_path = paths.PREBUILT_DIR / 'catalog.db'
  84. if old_cat_path.is_file() and args.clean:
  85. old_cat_path.unlink()
  86. ci_repo_dir = paths.PREBUILT_DIR / 'ci-repo'
  87. if ci_repo_dir.exists() and args.clean:
  88. shutil.rmtree(ci_repo_dir)
  89. self_build(
  90. paths.PREBUILT_DDS,
  91. toolchain=opts.toolchain,
  92. cat_path=old_cat_path,
  93. cat_json_path=Path('catalog.json'),
  94. dds_flags=[('--repo-dir', ci_repo_dir)])
  95. print('Main build PASSED!')
  96. print(f'A `dds` executable has been generated: {paths.CUR_BUILT_DDS}')
  97. if args.build_only:
  98. print(
  99. f'`--build-only` was given, so second phase and tests will not execute'
  100. )
  101. return 0
  102. print('Bootstrapping myself:')
  103. new_cat_path = paths.BUILD_DIR / 'catalog.db'
  104. new_repo_dir = paths.BUILD_DIR / 'ci-repo'
  105. self_build(
  106. paths.CUR_BUILT_DDS,
  107. toolchain=opts.toolchain,
  108. cat_path=new_cat_path,
  109. dds_flags=[f'--repo-dir={new_repo_dir}'])
  110. print('Bootstrap test PASSED!')
  111. return pytest.main([
  112. '-v',
  113. '--durations=10',
  114. f'--basetemp={paths.BUILD_DIR / "_tmp"}',
  115. '-n',
  116. str(multiprocessing.cpu_count() + 2),
  117. 'tests/',
  118. ])
  119. if __name__ == "__main__":
  120. sys.exit(main(sys.argv[1:]))