您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

62 行
1.7KB

  1. import argparse
  2. import json
  3. import os
  4. from pathlib import Path
  5. from typing import Optional, Dict, Any
  6. from typing_extensions import Protocol
  7. from . import paths
  8. class Arguments(Protocol):
  9. out: Optional[Path]
  10. def gen_task_json_data() -> Dict[str, Any]:
  11. dds_ci_exe = paths.find_exe('dds-ci')
  12. assert dds_ci_exe, 'Unable to find the dds-ci executable. This command should be run in a Poetry'
  13. envs = {key: os.environ[key]
  14. for key in (
  15. 'CL',
  16. '_CL_',
  17. 'PATH',
  18. 'INCLUDE',
  19. 'LIBPATH',
  20. 'LIB',
  21. ) if key in os.environ}
  22. task = {
  23. 'label': 'MSVC Build',
  24. 'type': 'process',
  25. 'command': str(dds_ci_exe.resolve()),
  26. 'args': ['--rapid'],
  27. 'group': {
  28. 'kind': 'build',
  29. },
  30. 'options': {
  31. 'env': envs,
  32. },
  33. 'problemMatcher': '$msCompile',
  34. }
  35. return task
  36. def generate_vsc_task() -> None:
  37. parser = argparse.ArgumentParser()
  38. parser.add_argument('--out', '-o', help='File to write into', type=Path)
  39. args: Arguments = parser.parse_args()
  40. cl = paths.find_exe('cl')
  41. if cl is None:
  42. raise RuntimeError('There is not cl.exe on your PATH. You need to run '
  43. 'this command from within a Visual Studio environment.')
  44. data = gen_task_json_data()
  45. task_str = json.dumps(data, indent=4)
  46. if args.out:
  47. args.out.write_text(task_str)
  48. print(f'The task JSON has been written to {args.out}.')
  49. else:
  50. print(task_str)
  51. print('^^^ The task JSON has been written above ^^^')
  52. print('Add the JSON object to "tasks.json" to use it in VS Code')