electron/script/strip-binaries.py
John Kleinschmidt 5e49aafe55
build: preserve timestamps when stripping files (#22094)
* build: preserve timestamps when stripping files

Resolves an issue where the binaries in mksnapshot.zip were not getting stripped.

* Add missing comma

* Update script/strip-binaries.py

Co-Authored-By: Jeremy Apthorp <jeremya@chromium.org>

* Don't try to run strip on macOS

Co-authored-by: Jeremy Apthorp <nornagon@nornagon.net>
2020-02-07 17:05:04 -05:00

56 lines
1.7 KiB
Python
Executable file

#!/usr/bin/env python
from __future__ import print_function
import argparse
import os
import sys
from lib.config import LINUX_BINARIES, enable_verbose_mode
from lib.util import execute, get_out_dir
def strip_binaries(directory, target_cpu):
for binary in LINUX_BINARIES:
binary_path = os.path.join(directory, binary)
if os.path.isfile(binary_path):
strip_binary(binary_path, target_cpu)
def strip_binary(binary_path, target_cpu):
if target_cpu == 'arm':
strip = 'arm-linux-gnueabihf-strip'
elif target_cpu == 'arm64':
strip = 'aarch64-linux-gnu-strip'
elif target_cpu == 'mips64el':
strip = 'mips64el-redhat-linux-strip'
else:
strip = 'strip'
execute([strip, '--preserve-dates', binary_path])
def main():
args = parse_args()
if args.verbose:
enable_verbose_mode()
if args.file:
strip_binary(args.file, args.target_cpu)
else:
strip_binaries(args.directory, args.target_cpu)
def parse_args():
parser = argparse.ArgumentParser(description='Strip linux binaries')
parser.add_argument('-d', '--directory',
help='Path to the dir that contains files to strip.',
default=get_out_dir(),
required=False)
parser.add_argument('-f', '--file',
help='Path to a specific file to strip.',
required=False)
parser.add_argument('-v', '--verbose',
action='store_true',
help='Prints the output of the subprocesses')
parser.add_argument('--target-cpu',
default='',
required=False,
help='Target cpu of binaries to strip')
return parser.parse_args()
if __name__ == '__main__':
sys.exit(main())