strip-binaries.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import argparse
  4. import os
  5. import sys
  6. from lib.config import LINUX_BINARIES, enable_verbose_mode
  7. from lib.util import execute, get_out_dir
  8. def strip_binaries(directory, target_cpu):
  9. for binary in LINUX_BINARIES:
  10. binary_path = os.path.join(directory, binary)
  11. if os.path.isfile(binary_path):
  12. strip_binary(binary_path, target_cpu)
  13. def strip_binary(binary_path, target_cpu):
  14. if target_cpu == 'arm':
  15. strip = 'arm-linux-gnueabihf-strip'
  16. elif target_cpu == 'arm64':
  17. strip = 'aarch64-linux-gnu-strip'
  18. elif target_cpu == 'mips64el':
  19. strip = 'mips64el-redhat-linux-strip'
  20. else:
  21. strip = 'strip'
  22. execute([strip, '--preserve-dates', binary_path])
  23. def main():
  24. args = parse_args()
  25. if args.verbose:
  26. enable_verbose_mode()
  27. if args.file:
  28. strip_binary(args.file, args.target_cpu)
  29. else:
  30. strip_binaries(args.directory, args.target_cpu)
  31. def parse_args():
  32. parser = argparse.ArgumentParser(description='Strip linux binaries')
  33. parser.add_argument('-d', '--directory',
  34. help='Path to the dir that contains files to strip.',
  35. default=get_out_dir(),
  36. required=False)
  37. parser.add_argument('-f', '--file',
  38. help='Path to a specific file to strip.',
  39. required=False)
  40. parser.add_argument('-v', '--verbose',
  41. action='store_true',
  42. help='Prints the output of the subprocesses')
  43. parser.add_argument('--target-cpu',
  44. default='',
  45. required=False,
  46. help='Target cpu of binaries to strip')
  47. return parser.parse_args()
  48. if __name__ == '__main__':
  49. sys.exit(main())