Skip to content

Commit 92ff39c

Browse files
CapOMnornagon
authored andcommitted
ci: generate debug symbols on Linux (electron#18676)
1 parent 41f1569 commit 92ff39c

9 files changed

Lines changed: 192 additions & 17 deletions

File tree

.circleci/config.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,18 @@ step-maybe-electron-dist-strip: &step-maybe-electron-dist-strip
349349
run:
350350
name: Strip electron binaries
351351
command: |
352-
if [ "$STRIP_BINARIES" == "true" ] && [ "`uname`" != "Darwin" ]; then
352+
if [ "$STRIP_BINARIES" == "true" ] && [ "`uname`" == "Linux" ]; then
353+
if [ x"$TARGET_ARCH" == x ]; then
354+
target_cpu=x64
355+
elif [ "$TARGET_ARCH" == "ia32" ]; then
356+
target_cpu=x86
357+
else
358+
target_cpu="$TARGET_ARCH"
359+
fi
353360
cd src
354-
electron/script/strip-binaries.py --target-cpu="$TARGET_ARCH"
361+
electron/script/copy-debug-symbols.py --target-cpu="$target_cpu" --out-dir=out/Default/debug --compress
362+
electron/script/strip-binaries.py --target-cpu="$target_cpu"
363+
electron/script/add-debug-link.py --target-cpu="$target_cpu" --debug-dir=out/Default/debug
355364
fi
356365
357366
step-electron-dist-build: &step-electron-dist-build

script/add-debug-link.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python
2+
from __future__ import print_function
3+
import argparse
4+
import os
5+
import sys
6+
7+
from lib.config import LINUX_BINARIES, PLATFORM
8+
from lib.util import execute, get_objcopy_path, get_out_dir
9+
10+
def add_debug_link_into_binaries(directory, target_cpu, debug_dir):
11+
for binary in LINUX_BINARIES:
12+
binary_path = os.path.join(directory, binary)
13+
if os.path.isfile(binary_path):
14+
add_debug_link_into_binary(binary_path, target_cpu, debug_dir)
15+
16+
def add_debug_link_into_binary(binary_path, target_cpu, debug_dir):
17+
try:
18+
objcopy = get_objcopy_path(target_cpu)
19+
except:
20+
if PLATFORM == 'linux' and (target_cpu == 'x86' or target_cpu == 'arm' or
21+
target_cpu == 'arm64'):
22+
# Skip because no objcopy binary on the given target.
23+
return
24+
raise
25+
debug_name = get_debug_name(binary_path)
26+
# Make sure the path to the binary is not relative because of cwd param.
27+
real_binary_path = os.path.realpath(binary_path)
28+
cmd = [objcopy, '--add-gnu-debuglink=' + debug_name, real_binary_path]
29+
execute(cmd, cwd=debug_dir)
30+
31+
def get_debug_name(binary_path):
32+
return os.path.basename(binary_path) + '.debug'
33+
34+
def main():
35+
args = parse_args()
36+
if args.file:
37+
add_debug_link_into_binary(args.file, args.target_cpu, args.debug_dir)
38+
else:
39+
add_debug_link_into_binaries(args.directory, args.target_cpu,
40+
args.debug_dir)
41+
42+
def parse_args():
43+
parser = argparse.ArgumentParser(description='Add debug link to binaries')
44+
parser.add_argument('-d', '--directory',
45+
help='Path to the dir that contains files to add links',
46+
default=get_out_dir(),
47+
required=False)
48+
parser.add_argument('-f', '--file',
49+
help='Path to a specific file to add debug link',
50+
required=False)
51+
parser.add_argument('-s', '--debug-dir',
52+
help='Path to the dir that contain the debugs',
53+
default=None,
54+
required=True)
55+
parser.add_argument('-v', '--verbose',
56+
action='store_true',
57+
help='Prints the output of the subprocesses')
58+
parser.add_argument('--target-cpu',
59+
default='',
60+
required=False,
61+
help='Target cpu of binaries to add debug link')
62+
63+
return parser.parse_args()
64+
65+
if __name__ == '__main__':
66+
sys.exit(main())

script/copy-debug-symbols.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env python
2+
from __future__ import print_function
3+
import argparse
4+
import os
5+
import sys
6+
7+
from lib.config import LINUX_BINARIES, PLATFORM
8+
from lib.util import execute, get_objcopy_path, get_out_dir, safe_mkdir
9+
10+
# It has to be done before stripping the binaries.
11+
def copy_debug_from_binaries(directory, out_dir, target_cpu, compress):
12+
for binary in LINUX_BINARIES:
13+
binary_path = os.path.join(directory, binary)
14+
if os.path.isfile(binary_path):
15+
copy_debug_from_binary(binary_path, out_dir, target_cpu, compress)
16+
17+
def copy_debug_from_binary(binary_path, out_dir, target_cpu, compress):
18+
try:
19+
objcopy = get_objcopy_path(target_cpu)
20+
except:
21+
if PLATFORM == 'linux' and (target_cpu == 'x86' or target_cpu == 'arm' or
22+
target_cpu == 'arm64'):
23+
# Skip because no objcopy binary on the given target.
24+
return
25+
raise
26+
debug_name = get_debug_name(binary_path)
27+
cmd = [objcopy, '--only-keep-debug']
28+
if compress:
29+
cmd.extend(['--compress-debug-sections'])
30+
cmd.extend([binary_path, os.path.join(out_dir, debug_name)])
31+
execute(cmd)
32+
return debug_name
33+
34+
def get_debug_name(binary_path):
35+
return os.path.basename(binary_path) + '.debug'
36+
37+
def main():
38+
args = parse_args()
39+
safe_mkdir(args.out_dir)
40+
if args.file:
41+
copy_debug_from_binary(args.file, args.out_dir, args.target_cpu,
42+
args.compress)
43+
else:
44+
copy_debug_from_binaries(args.directory, args.out_dir, args.target_cpu,
45+
args.compress)
46+
47+
def parse_args():
48+
parser = argparse.ArgumentParser(description='Copy debug from binaries')
49+
parser.add_argument('-d', '--directory',
50+
help='Path to the dir that contains files to copy',
51+
default=get_out_dir(),
52+
required=False)
53+
parser.add_argument('-f', '--file',
54+
help='Path to a specific file to copy debug symbols',
55+
required=False)
56+
parser.add_argument('-o', '--out-dir',
57+
help='Path to the dir that will contain the debugs',
58+
default=None,
59+
required=True)
60+
parser.add_argument('-v', '--verbose',
61+
action='store_true',
62+
help='Prints the output of the subprocesses')
63+
parser.add_argument('--target-cpu',
64+
default='',
65+
required=False,
66+
help='Target cpu of binaries to copy debug symbols')
67+
parser.add_argument('--compress',
68+
action='store_true',
69+
required=False,
70+
help='Compress the debug symbols')
71+
72+
return parser.parse_args()
73+
74+
if __name__ == '__main__':
75+
sys.exit(main())

script/lib/config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@
2626
'win32': 'win32',
2727
}[sys.platform]
2828

29+
LINUX_BINARIES = [
30+
'electron',
31+
'chrome-sandbox',
32+
'crashpad_handler',
33+
'libffmpeg.so',
34+
'libGLESv2.so',
35+
'libEGL.so',
36+
'swiftshader/libGLESv2.so',
37+
'swiftshader/libEGL.so',
38+
'libvk_swiftshader.so'
39+
]
40+
2941
verbose_mode = False
3042

3143

script/lib/util.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ def make_zip(zip_file_path, files, dirs):
123123
files += dirs
124124
execute(['zip', '-r', '-y', zip_file_path] + files)
125125
else:
126-
zip_file = zipfile.ZipFile(zip_file_path, "w", zipfile.ZIP_DEFLATED)
126+
zip_file = zipfile.ZipFile(zip_file_path, "w", zipfile.ZIP_DEFLATED,
127+
allowZip64=True)
127128
for filename in files:
128129
zip_file.write(filename, filename)
129130
for dirname in dirs:
@@ -266,3 +267,14 @@ def get_buildtools_executable(name):
266267
if sys.platform == 'win32':
267268
path += '.exe'
268269
return path
270+
271+
def get_objcopy_path(target_cpu):
272+
if PLATFORM != 'linux':
273+
raise Exception(
274+
"get_objcopy_path: unexpected platform '{0}'".format(PLATFORM))
275+
276+
if target_cpu != 'x64':
277+
raise Exception(
278+
"get_objcopy_path: unexpected target cpu '{0}'".format(target_cpu))
279+
return os.path.join(SRC_DIR, 'third_party', 'binutils', 'Linux_x64',
280+
'Release', 'bin', 'objcopy')

script/release/release.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ function assetsForVersion (version, validatingRelease) {
114114
`electron-${version}-linux-armv7l.zip`,
115115
`electron-${version}-linux-ia32-symbols.zip`,
116116
`electron-${version}-linux-ia32.zip`,
117+
`electron-${version}-linux-x64-debug.zip`,
117118
`electron-${version}-linux-x64-symbols.zip`,
118119
`electron-${version}-linux-x64.zip`,
119120
`electron-${version}-mas-x64-dsym.zip`,

script/release/uploaders/upload.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
SYMBOLS_NAME = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, 'symbols')
3636
DSYM_NAME = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, 'dsym')
3737
PDB_NAME = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, 'pdb')
38+
DEBUG_NAME = get_zip_name(PROJECT_NAME, ELECTRON_VERSION, 'debug')
3839

3940

4041
def main():
@@ -83,6 +84,10 @@ def main():
8384
pdb_zip = os.path.join(OUT_DIR, PDB_NAME)
8485
shutil.copy2(os.path.join(OUT_DIR, 'pdb.zip'), pdb_zip)
8586
upload_electron(release, pdb_zip, args)
87+
elif PLATFORM == 'linux':
88+
debug_zip = os.path.join(OUT_DIR, DEBUG_NAME)
89+
shutil.copy2(os.path.join(OUT_DIR, 'debug.zip'), debug_zip)
90+
upload_electron(release, debug_zip, args)
8691

8792
# Upload free version of ffmpeg.
8893
ffmpeg = get_zip_name('ffmpeg', ELECTRON_VERSION)

script/strip-binaries.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,11 @@
44
import os
55
import sys
66

7+
from lib.config import LINUX_BINARIES
78
from lib.util import execute, get_out_dir
89

9-
LINUX_BINARIES_TO_STRIP = [
10-
'electron',
11-
'chrome-sandbox',
12-
'crashpad_handler',
13-
'libffmpeg.so',
14-
'libGLESv2.so',
15-
'libEGL.so',
16-
'swiftshader/libGLESv2.so',
17-
'swiftshader/libEGL.so',
18-
'libvk_swiftshader.so'
19-
]
20-
2110
def strip_binaries(directory, target_cpu):
22-
for binary in LINUX_BINARIES_TO_STRIP:
11+
for binary in LINUX_BINARIES:
2312
binary_path = os.path.join(directory, binary)
2413
if os.path.isfile(binary_path):
2514
strip_binary(binary_path, target_cpu)
@@ -37,7 +26,6 @@ def strip_binary(binary_path, target_cpu):
3726

3827
def main():
3928
args = parse_args()
40-
print(args)
4129
if args.file:
4230
strip_binary(args.file, args.target_cpu)
4331
else:

script/zip-symbols.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ def main():
4343
pdb_zip_file = os.path.join(args.build_dir, pdb_name)
4444
print('Making pdb zip: ' + pdb_zip_file)
4545
make_zip(pdb_zip_file, pdbs + licenses, [])
46+
elif PLATFORM == 'linux':
47+
debug_name = 'debug.zip'
48+
with scoped_cwd(args.build_dir):
49+
dirs = ['debug']
50+
debug_zip_file = os.path.join(args.build_dir, debug_name)
51+
print('Making debug zip: ' + debug_zip_file)
52+
make_zip(debug_zip_file, licenses, dirs)
4653

4754
def parse_args():
4855
parser = argparse.ArgumentParser(description='Zip symbols')

0 commit comments

Comments
 (0)