strip-binaries.py 1.7 KB

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