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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from pathlib import Path
  2. import multiprocessing
  3. import shutil
  4. from . import proc
  5. from . import paths
  6. class DDSWrapper:
  7. """
  8. Wraps a 'dds' executable with some convenience APIs that invoke various
  9. 'dds' subcommands.
  10. """
  11. def __init__(self, path: Path) -> None:
  12. self.path = path
  13. self.repo_dir = paths.PREBUILT_DIR / 'ci-repo'
  14. self.catalog_path = paths.PREBUILT_DIR / 'ci-catalog.db'
  15. @property
  16. def catalog_path_arg(self):
  17. """The arguments for --catalog"""
  18. return f'--catalog={self.catalog_path}'
  19. @property
  20. def repo_dir_arg(self):
  21. """The arguments for --repo-dir"""
  22. return f'--repo-dir={self.repo_dir}'
  23. def clean(self, *, build_dir: Path = None, repo=True, catalog=True):
  24. """
  25. Clean out prior executable output, including repos, catalog, and
  26. the build results at 'build_dir', if given.
  27. """
  28. if build_dir and build_dir.exists():
  29. shutil.rmtree(build_dir)
  30. if repo and self.repo_dir.exists():
  31. shutil.rmtree(self.repo_dir)
  32. if catalog and self.catalog_path.exists():
  33. self.catalog_path.unlink()
  34. def run(self, args: proc.CommandLine) -> None:
  35. """Execute the 'dds' executable with the given arguments"""
  36. proc.check_run([self.path, args]) # type: ignore
  37. def catalog_json_import(self, path: Path) -> None:
  38. """Run 'catalog import' to import the given JSON. Only applicable to older 'dds'"""
  39. self.run(['catalog', 'import', self.catalog_path_arg, f'--json={path}'])
  40. def build(self, *, toolchain: Path, root: Path, build_root: Path = None, jobs: int = None) -> None:
  41. """
  42. Run 'dds build' with the given arguments.
  43. :param toolchain: The toolchain to use for the build.
  44. :param root: The root project directory.
  45. :param build_root: The root directory where the output will be written.
  46. :param jobs: The number of jobs to use. Default is CPU-count + 2
  47. """
  48. jobs = jobs or multiprocessing.cpu_count() + 2
  49. self.run([
  50. 'build',
  51. f'--toolchain={toolchain}',
  52. self.repo_dir_arg,
  53. self.catalog_path_arg,
  54. f'--jobs={jobs}',
  55. f'--project-dir={root}',
  56. f'--out={build_root}',
  57. ])