Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. toolchain_2: 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. ])
  23. def _do_bootstrap_download() -> None:
  24. filename = {
  25. 'win32': 'dds-win-x64.exe',
  26. 'linux': 'dds-linux-x64',
  27. 'darwin': 'dds-macos-x64',
  28. 'freebsd11': 'dds-freebsd-x64',
  29. 'freebsd12': 'dds-freebsd-x64',
  30. }.get(sys.platform)
  31. if filename is None:
  32. raise RuntimeError(f'We do not have a prebuilt DDS binary for '
  33. f'the "{sys.platform}" platform')
  34. url = f'https://github.com/vector-of-bool/dds/releases/download/0.1.0-alpha.3/{filename}'
  35. print(f'Downloading prebuilt DDS executable: {url}')
  36. stream = urllib.request.urlopen(url)
  37. paths.PREBUILT_DDS.parent.mkdir(exist_ok=True, parents=True)
  38. with paths.PREBUILT_DDS.open('wb') as fd:
  39. while True:
  40. buf = stream.read(1024 * 4)
  41. if not buf:
  42. break
  43. fd.write(buf)
  44. if os.name != 'nt':
  45. # Mark the binary executable. By default it won't be
  46. mode = paths.PREBUILT_DDS.stat().st_mode
  47. mode |= 0b001_001_001
  48. paths.PREBUILT_DDS.chmod(mode)
  49. def main(argv: Sequence[str]) -> int:
  50. parser = argparse.ArgumentParser()
  51. parser.add_argument(
  52. '-B',
  53. '--bootstrap-with',
  54. help='How are we to obtain a bootstrapped DDS executable?',
  55. choices=('download', 'build', 'skip'),
  56. required=True,
  57. )
  58. parser.add_argument(
  59. '--toolchain',
  60. '-T',
  61. help='The toolchain to use for the CI process',
  62. required=True,
  63. )
  64. parser.add_argument(
  65. '--toolchain-2',
  66. '-T2',
  67. help='The toolchain to use for the self-build',
  68. required=True,
  69. )
  70. parser.add_argument(
  71. '--build-only',
  72. action='store_true',
  73. help='Only build the `dds` executable. Skip second-phase and tests.')
  74. args = parser.parse_args(argv)
  75. opts = CIOptions(toolchain=args.toolchain, toolchain_2=args.toolchain_2)
  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. old_cat_path = paths.PREBUILT_DIR / 'catalog.db'
  85. if old_cat_path.is_file():
  86. old_cat_path.unlink()
  87. ci_repo_dir = paths.PREBUILT_DIR / 'ci-repo'
  88. if ci_repo_dir.exists():
  89. shutil.rmtree(ci_repo_dir)
  90. self_build(
  91. paths.PREBUILT_DDS,
  92. toolchain=opts.toolchain,
  93. cat_path=old_cat_path,
  94. cat_json_path=Path('catalog.old.json'),
  95. dds_flags=[('--repo-dir', ci_repo_dir)])
  96. print('Main build PASSED!')
  97. print(f'A `dds` executable has been generated: {paths.CUR_BUILT_DDS}')
  98. if args.build_only:
  99. print(
  100. f'`--build-only` was given, so second phase and tests will not execute'
  101. )
  102. return 0
  103. print('Bootstrapping myself:')
  104. new_cat_path = paths.BUILD_DIR / 'catalog.db'
  105. new_repo_dir = paths.BUILD_DIR / 'ci-repo'
  106. self_build(
  107. paths.CUR_BUILT_DDS,
  108. toolchain=opts.toolchain_2,
  109. cat_path=new_cat_path,
  110. dds_flags=[f'--repo-dir={new_repo_dir}'])
  111. print('Bootstrap test PASSED!')
  112. return pytest.main([
  113. '-v',
  114. '--durations=10',
  115. f'--basetemp={paths.BUILD_DIR / "_tmp"}',
  116. '-n',
  117. str(multiprocessing.cpu_count() + 2),
  118. 'tests/',
  119. ])
  120. if __name__ == "__main__":
  121. sys.exit(main(sys.argv[1:]))