build: refactor Linux binary stripping to align with upstream (#48197)
build: refactor Linux binary stripping to align with upstream (#47932) Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
This commit is contained in:
parent
6812b13161
commit
9eede35fc1
13 changed files with 245 additions and 263 deletions
|
@ -1,62 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
from lib.config import PLATFORM
|
||||
from lib.util import execute, get_linux_binaries, get_out_dir
|
||||
|
||||
def add_debug_link_into_binaries(directory, target_cpu, debug_dir):
|
||||
for binary in get_linux_binaries():
|
||||
binary_path = os.path.join(directory, binary)
|
||||
if os.path.isfile(binary_path):
|
||||
add_debug_link_into_binary(binary_path, target_cpu, debug_dir)
|
||||
|
||||
def add_debug_link_into_binary(binary_path, target_cpu, debug_dir):
|
||||
if PLATFORM == 'linux' and target_cpu in ('x86', 'arm', 'arm64'):
|
||||
# Skip because no objcopy binary on the given target.
|
||||
return
|
||||
|
||||
debug_name = get_debug_name(binary_path)
|
||||
# Make sure the path to the binary is not relative because of cwd param.
|
||||
real_binary_path = os.path.realpath(binary_path)
|
||||
cmd = ['objcopy', '--add-gnu-debuglink=' + debug_name, real_binary_path]
|
||||
execute(cmd, cwd=debug_dir)
|
||||
|
||||
def get_debug_name(binary_path):
|
||||
return os.path.basename(binary_path) + '.debug'
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
if args.file:
|
||||
add_debug_link_into_binary(args.file, args.target_cpu, args.debug_dir)
|
||||
else:
|
||||
add_debug_link_into_binaries(args.directory, args.target_cpu,
|
||||
args.debug_dir)
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(description='Add debug link to binaries')
|
||||
parser.add_argument('-d', '--directory',
|
||||
help='Path to the dir that contains files to add links',
|
||||
default=get_out_dir(),
|
||||
required=False)
|
||||
parser.add_argument('-f', '--file',
|
||||
help='Path to a specific file to add debug link',
|
||||
required=False)
|
||||
parser.add_argument('-s', '--debug-dir',
|
||||
help='Path to the dir that contain the debugs',
|
||||
default=None,
|
||||
required=True)
|
||||
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 add debug link')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
|
@ -1,69 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
from lib.config import PLATFORM
|
||||
from lib.util import execute, get_linux_binaries, get_out_dir, safe_mkdir
|
||||
|
||||
# It has to be done before stripping the binaries.
|
||||
def copy_debug_from_binaries(directory, out_dir, target_cpu, compress):
|
||||
for binary in get_linux_binaries():
|
||||
binary_path = os.path.join(directory, binary)
|
||||
if os.path.isfile(binary_path):
|
||||
copy_debug_from_binary(binary_path, out_dir, target_cpu, compress)
|
||||
|
||||
def copy_debug_from_binary(binary_path, out_dir, target_cpu, compress):
|
||||
if PLATFORM == 'linux' and target_cpu in ('x86', 'arm', 'arm64'):
|
||||
# Skip because no objcopy binary on the given target.
|
||||
return
|
||||
debug_name = get_debug_name(binary_path)
|
||||
cmd = ['objcopy', '--only-keep-debug']
|
||||
if compress:
|
||||
cmd.extend(['--compress-debug-sections'])
|
||||
cmd.extend([binary_path, os.path.join(out_dir, debug_name)])
|
||||
execute(cmd)
|
||||
|
||||
def get_debug_name(binary_path):
|
||||
return os.path.basename(binary_path) + '.debug'
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
safe_mkdir(args.out_dir)
|
||||
if args.file:
|
||||
copy_debug_from_binary(args.file, args.out_dir, args.target_cpu,
|
||||
args.compress)
|
||||
else:
|
||||
copy_debug_from_binaries(args.directory, args.out_dir, args.target_cpu,
|
||||
args.compress)
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(description='Copy debug from binaries')
|
||||
parser.add_argument('-d', '--directory',
|
||||
help='Path to the dir that contains files to copy',
|
||||
default=get_out_dir(),
|
||||
required=False)
|
||||
parser.add_argument('-f', '--file',
|
||||
help='Path to a specific file to copy debug symbols',
|
||||
required=False)
|
||||
parser.add_argument('-o', '--out-dir',
|
||||
help='Path to the dir that will contain the debugs',
|
||||
default=None,
|
||||
required=True)
|
||||
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 copy debug symbols')
|
||||
parser.add_argument('--compress',
|
||||
action='store_true',
|
||||
required=False,
|
||||
help='Compress the debug symbols')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
|
@ -207,14 +207,3 @@ def get_depot_tools_executable(name):
|
|||
if sys.platform == 'win32':
|
||||
path += '.bat'
|
||||
return path
|
||||
|
||||
def get_linux_binaries():
|
||||
return [
|
||||
'chrome-sandbox',
|
||||
'chrome_crashpad_handler',
|
||||
get_electron_branding()['project_name'],
|
||||
'libEGL.so',
|
||||
'libGLESv2.so',
|
||||
'libffmpeg.so',
|
||||
'libvk_swiftshader.so',
|
||||
]
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
from lib.config import set_verbose_mode, is_verbose_mode, verbose_mode_print
|
||||
from lib.util import execute, get_linux_binaries, get_out_dir
|
||||
|
||||
def get_size(path):
|
||||
size = os.path.getsize(path)
|
||||
units = ["bytes", "KB", "MB", "GB"]
|
||||
for unit in units:
|
||||
if size < 1024:
|
||||
return f"{size:.2f} {unit}"
|
||||
size /= 1024
|
||||
raise ValueError("File size is too large to be processed")
|
||||
|
||||
def strip_binaries(directory, target_cpu):
|
||||
if not os.path.isdir(directory):
|
||||
verbose_mode_print('Directory ' + directory + ' does not exist.')
|
||||
return
|
||||
|
||||
verbose_mode_print('Stripping binaries in ' + directory)
|
||||
for binary in get_linux_binaries():
|
||||
verbose_mode_print('\nStripping ' + binary)
|
||||
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'
|
||||
else:
|
||||
strip = 'strip'
|
||||
|
||||
strip_args = [strip,
|
||||
'--discard-all',
|
||||
'--strip-debug',
|
||||
'--preserve-dates',
|
||||
binary_path]
|
||||
if (is_verbose_mode()):
|
||||
strip_args.insert(1, '--verbose')
|
||||
verbose_mode_print('Binary size before stripping: ' +
|
||||
str(get_size(binary_path)))
|
||||
execute(strip_args)
|
||||
verbose_mode_print('Binary size after stripping: ' +
|
||||
str(get_size(binary_path)))
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
set_verbose_mode(args.verbose)
|
||||
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',
|
||||
default=False,
|
||||
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())
|
Loading…
Add table
Add a link
Reference in a new issue