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.

116 line
3.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 dds_ci import paths, proc
  13. class CIOptions(NamedTuple):
  14. cxx: Path
  15. toolchain: str
  16. def _do_bootstrap_build(opts: CIOptions) -> None:
  17. print('Bootstrapping by a local build of prior versions...')
  18. subprocess.check_call([
  19. sys.executable,
  20. '-u',
  21. str(paths.TOOLS_DIR / 'bootstrap.py'),
  22. f'--cxx={opts.cxx}',
  23. ])
  24. def _do_bootstrap_download() -> None:
  25. filename = {
  26. 'win32': 'dds-win-x64.exe',
  27. 'linux': 'dds-linux-x64',
  28. 'darwin': 'dds-macos-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/bootstrap-p2/{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. '--cxx',
  59. help='The name/path of the C++ compiler to use.',
  60. required=True)
  61. parser.add_argument(
  62. '--toolchain',
  63. '-T',
  64. help='The toolchain to use for the CI process',
  65. required=True)
  66. args = parser.parse_args(argv)
  67. opts = CIOptions(cxx=Path(args.cxx), toolchain=args.toolchain)
  68. if args.bootstrap_with == 'build':
  69. _do_bootstrap_build(opts)
  70. elif args.bootstrap_with == 'download':
  71. _do_bootstrap_download()
  72. elif args.bootstrap_with == 'skip':
  73. pass
  74. else:
  75. assert False, 'impossible'
  76. proc.check_run(
  77. paths.PREBUILT_DDS,
  78. 'deps',
  79. 'build',
  80. ('-T', opts.toolchain),
  81. ('--repo-dir', paths.EMBEDDED_REPO_DIR),
  82. )
  83. proc.check_run(
  84. paths.PREBUILT_DDS,
  85. 'build',
  86. '--full',
  87. ('-T', opts.toolchain),
  88. )
  89. self_build(paths.CUR_BUILT_DDS, opts.toolchain)
  90. if paths.SELF_TEST_REPO_DIR.exists():
  91. shutil.rmtree(paths.SELF_TEST_REPO_DIR)
  92. self_deps_get(paths.CUR_BUILT_DDS, paths.SELF_TEST_REPO_DIR)
  93. return pytest.main(['-v', '--durations=10'])
  94. if __name__ == "__main__":
  95. sys.exit(main(sys.argv[1:]))