run-toolchain 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python3
  2. import os
  3. import common
  4. from shell_helpers import LF
  5. class Main(common.LkmcCliFunction):
  6. def __init__(self):
  7. super().__init__(
  8. defaults = {
  9. 'show_time': False,
  10. },
  11. description='''\
  12. Manually run a ToolChain tool like gcc, readelf or objdump.
  13. https://cirosantilli.com/linux-kernel-module-cheat#run-toolchain
  14. ''',
  15. )
  16. self.add_argument(
  17. '--print-tool',
  18. default=False,
  19. help='''
  20. Just output print tool path to stdout but don't actually run it.
  21. Suitable for programmatic consumption by other shell programs.
  22. ''',
  23. )
  24. self.add_argument('tool', help='Which tool to run.')
  25. self.add_argument(
  26. 'extra_args',
  27. default=[],
  28. help='Extra arguments for the tool.',
  29. metavar='extra-args',
  30. nargs='*'
  31. )
  32. def timed_main(self):
  33. tool = self.get_toolchain_tool(self.env['tool'])
  34. if self.env['print_tool']:
  35. print(tool)
  36. return 0
  37. else:
  38. return self.sh.run_cmd(
  39. [tool, LF]
  40. + self.sh.add_newlines(self.env['extra_args']),
  41. cmd_file=os.path.join(self.env['run_dir'], 'run-toolchain.sh'),
  42. )
  43. if __name__ == '__main__':
  44. Main().cli()