Skip to content

Commit

Permalink
fix build_id logic for fuchsia symbols (flutter#16397)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield authored Feb 5, 2020
1 parent 036c370 commit c107969
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions tools/fuchsia/copy_debug_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

import argparse
import errno
import json
import os
import re
Expand All @@ -26,10 +27,16 @@ def Touch(fname):


def GetBuildIdParts(exec_path, read_elf):
file_out = subprocess.check_output(
[read_elf, '--hex-dump=.note.gnu.build-id', exec_path])
second_line = file_out.splitlines()[-1].split()
build_id = second_line[1] + second_line[2]
sha1_pattern = re.compile(r'[0-9a-fA-F\-]+')
file_out = subprocess.check_output([read_elf, '-n', exec_path])
build_id_line = file_out.splitlines()[-1].split()
if (build_id_line[0] != 'Build' or
build_id_line[1] != 'ID:' or not
sha1_pattern.match(build_id_line[-1]) or not
len(build_id_line[-1]) > 2):
raise Exception('Expected the last line of llvm-readelf to match "Build ID <Hex String>" Got: %s' % file_out)

build_id = build_id_line[-1]
return {
'build_id': build_id,
'prefix_dir': build_id[:2],
Expand Down Expand Up @@ -86,19 +93,15 @@ def main():
parts = GetBuildIdParts(args.exec_path, args.read_elf)
dbg_prefix_base = os.path.join(args.dest, parts['prefix_dir'])

success = False
for _ in range(3):
try:
if not os.path.exists(dbg_prefix_base):
os.makedirs(dbg_prefix_base)
success = True
break
except OSError as error:
print 'Failed to create dir %s, error: %s. sleeping...' % (
dbg_prefix_base, error)
time.sleep(3)

if not success:
# Multiple processes may be trying to create the same directory.
# TODO(dnfield): use exist_ok when we upgrade to python 3, rather than try
try:
os.makedirs(dbg_prefix_base)
except OSError as e:
if e.errno != errno.EEXIST:
raise

if not os.path.exists(dbg_prefix_base):
print 'Unable to create directory: %s.' % dbg_prefix_base
return 1

Expand Down

0 comments on commit c107969

Please sign in to comment.