run-toolchain 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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='''Run a Buildroot ToolChain tool like readelf or objdump.
  12. For example, to get some information about the arm vmlinux:
  13. ....
  14. ./%(prog)s readelf -- -e "$(./getvar vmlinux)"
  15. ....
  16. Get the list of available tools with:
  17. ....
  18. ls "$(./getvar -a arm buildroot_host_bin_dir)"
  19. ....
  20. ''',
  21. )
  22. self.add_argument(
  23. '--print-tool',
  24. default=False,
  25. help='''
  26. Just output print tool path to stdout but don't actually run it.
  27. Suitable for programmatic consumption by other shell programs.
  28. ''',
  29. )
  30. self.add_argument('tool', help='Which tool to run.')
  31. self.add_argument(
  32. 'extra_args',
  33. default=[],
  34. help='Extra arguments for the tool.',
  35. metavar='extra-args',
  36. nargs='*'
  37. )
  38. def timed_main(self):
  39. if self.env['baremetal'] is None:
  40. image = self.env['vmlinux']
  41. else:
  42. image = self.env['image']
  43. tool = self.get_toolchain_tool(self.env['tool'])
  44. if self.env['print_tool']:
  45. print(tool)
  46. return 0
  47. else:
  48. return self.sh.run_cmd(
  49. [tool, LF]
  50. + self.sh.add_newlines(self.env['extra_args']),
  51. cmd_file=os.path.join(self.env['run_dir'], 'run-toolchain.sh'),
  52. )
  53. if __name__ == '__main__':
  54. Main().cli()