strip-binaries.py 1.8 KB

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