Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

132 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. 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. if not opts.skip_deps:
  88. ci_repo_dir = paths.BUILD_DIR / '_ci-repo'
  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. self_build(
  100. paths.CUR_BUILT_DDS,
  101. toolchain=opts.toolchain,
  102. dds_flags=['--warnings', '--tests', '--apps'])
  103. print('Bootstrap test PASSED!')
  104. return pytest.main([
  105. '-v',
  106. '--durations=10',
  107. f'--basetemp={paths.BUILD_DIR / "_tmp"}',
  108. '-n4',
  109. 'tests/',
  110. ])
  111. if __name__ == "__main__":
  112. sys.exit(main(sys.argv[1:]))