From 9323aa3ae3df5c9d2cae14cde6230bcc899c3b99 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 7 Jun 2013 23:39:09 +0300 Subject: Made symbol extractor work on OSX. --- symbolextractor.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'symbolextractor.py') diff --git a/symbolextractor.py b/symbolextractor.py index ef08cf3..f4fddf7 100755 --- a/symbolextractor.py +++ b/symbolextractor.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 -tt +#!/usr/bin/env python3 # Copyright 2013 Jussi Pakkanen @@ -49,12 +49,32 @@ def linux_syms(libfilename, outfilename): output = pnm.communicate()[0].decode() if pnm.returncode != 0: raise RuntimeError('nm does not work.') - result += [x.split()[0] for x in output.split('\n') if len(x) > 0] + result += [' '.join(x.split()[0:2]) for x in output.split('\n') if len(x) > 0] + write_if_changed('\n'.join(result) + '\n', outfilename) + +def osx_syms(libfilename, outfilename): + pe = subprocess.Popen(['otool', '-l', libfilename], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + output = pe.communicate()[0].decode() + if pe.returncode != 0: + raise RuntimeError('Otool does not work.') + arr = output.split('\n') + for (i, val) in enumerate(arr): + if 'LC_ID_DYLIB' in val: + match = i + break + result = [arr[match+2], arr[match+5]] # Libreoffice stores all 5 lines but the others seem irrelevant. + pnm = subprocess.Popen(['nm', '-g', '-P', libfilename], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + output = pnm.communicate()[0].decode() + if pnm.returncode != 0: + raise RuntimeError('nm does not work.') + result += [' '.join(x.split()[0:2]) for x in output.split('\n') if len(x) > 0 and not x.endswith('U')] write_if_changed('\n'.join(result) + '\n', outfilename) def gen_symbols(libfilename, outfilename): if platform.system() == 'Linux': linux_syms(libfilename, outfilename) + if platform.system() == 'Darwin': + osx_syms(libfilename, outfilename) else: dummy_syms(outfilename) -- cgit v1.1