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ů.

140 lines
4.0KB

  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. cxx: Path
  16. toolchain: str
  17. skip_deps: bool
  18. def _do_bootstrap_build(opts: CIOptions) -> None:
  19. print('Bootstrapping by a local build of prior versions...')
  20. subprocess.check_call([
  21. sys.executable,
  22. '-u',
  23. str(paths.TOOLS_DIR / 'bootstrap.py'),
  24. f'--cxx={opts.cxx}',
  25. ])
  26. def _do_bootstrap_download() -> None:
  27. filename = {
  28. 'win32': 'dds-win-x64.exe',
  29. 'linux': 'dds-linux-x64',
  30. 'darwin': 'dds-macos-x64',
  31. }.get(sys.platform)
  32. if filename is None:
  33. raise RuntimeError(f'We do not have a prebuilt DDS binary for '
  34. f'the "{sys.platform}" platform')
  35. url = f'https://github.com/vector-of-bool/dds/releases/download/bootstrap-p4/{filename}'
  36. print(f'Downloading prebuilt DDS executable: {url}')
  37. stream = urllib.request.urlopen(url)
  38. paths.PREBUILT_DDS.parent.mkdir(exist_ok=True, parents=True)
  39. with paths.PREBUILT_DDS.open('wb') as fd:
  40. while True:
  41. buf = stream.read(1024 * 4)
  42. if not buf:
  43. break
  44. fd.write(buf)
  45. if os.name != 'nt':
  46. # Mark the binary executable. By default it won't be
  47. mode = paths.PREBUILT_DDS.stat().st_mode
  48. mode |= 0b001_001_001
  49. paths.PREBUILT_DDS.chmod(mode)
  50. def main(argv: Sequence[str]) -> int:
  51. parser = argparse.ArgumentParser()
  52. parser.add_argument(
  53. '-B',
  54. '--bootstrap-with',
  55. help='How are we to obtain a bootstrapped DDS executable?',
  56. choices=('download', 'build', 'skip'),
  57. required=True,
  58. )
  59. parser.add_argument(
  60. '--cxx', help='The name/path of the C++ compiler to use.')
  61. parser.add_argument(
  62. '--toolchain',
  63. '-T',
  64. help='The toolchain to use for the CI process',
  65. required=True)
  66. parser.add_argument(
  67. '--skip-deps',
  68. action='store_true',
  69. help='If specified, will skip getting and building '
  70. 'dependencies. (They must already be present)')
  71. args = parser.parse_args(argv)
  72. opts = CIOptions(
  73. cxx=Path(args.cxx or 'unspecified'),
  74. toolchain=args.toolchain,
  75. skip_deps=args.skip_deps)
  76. if args.bootstrap_with == 'build':
  77. if args.cxx is None:
  78. raise RuntimeError(
  79. '`--cxx` must be given when using `--bootstrap-with=build`')
  80. _do_bootstrap_build(opts)
  81. elif args.bootstrap_with == 'download':
  82. _do_bootstrap_download()
  83. elif args.bootstrap_with == 'skip':
  84. pass
  85. else:
  86. assert False, 'impossible'
  87. ci_repo_dir = paths.BUILD_DIR / '_ci-repo'
  88. if not opts.skip_deps:
  89. if ci_repo_dir.exists():
  90. shutil.rmtree(ci_repo_dir)
  91. self_deps_get(paths.PREBUILT_DDS, ci_repo_dir)
  92. self_deps_build(paths.PREBUILT_DDS, opts.toolchain, ci_repo_dir,
  93. paths.PROJECT_ROOT / 'remote.dds')
  94. self_build(
  95. paths.PREBUILT_DDS,
  96. toolchain=opts.toolchain,
  97. dds_flags=['--warnings', '--tests', '--apps'])
  98. print('Main build PASSED!')
  99. cat_path = paths.BUILD_DIR / 'catalog.db'
  100. proc.check_run([
  101. paths.CUR_BUILT_DDS,
  102. 'catalog',
  103. 'import',
  104. ('--catalog', cat_path),
  105. ('--json', paths.PROJECT_ROOT / 'catalog.json'),
  106. ])
  107. self_build(
  108. paths.CUR_BUILT_DDS,
  109. toolchain=opts.toolchain,
  110. dds_flags=[f'--repo-dir={ci_repo_dir}', f'--catalog={cat_path}'])
  111. print('Bootstrap test PASSED!')
  112. return pytest.main([
  113. '-v',
  114. '--durations=10',
  115. f'--basetemp={paths.BUILD_DIR / "_tmp"}',
  116. '-n4',
  117. 'tests/',
  118. ])
  119. if __name__ == "__main__":
  120. sys.exit(main(sys.argv[1:]))