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.

msvs.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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')