From 57d273b55baa1b153359fd9b27d223fe344aaae2 Mon Sep 17 00:00:00 2001 From: Yonggang Luo Date: Fri, 15 Dec 2023 17:42:38 +0800 Subject: [PATCH] meson: Getting symbols-check.py works for mingw Signed-off-by: Yonggang Luo Reviewed-by: Eric Engestrom Part-of: --- bin/symbols-check.py | 29 ++++++++++++++++++++++++++--- meson.build | 9 ++++++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/bin/symbols-check.py b/bin/symbols-check.py index 94b3d281b4b..fca8887ec89 100644 --- a/bin/symbols-check.py +++ b/bin/symbols-check.py @@ -121,6 +121,23 @@ def get_symbols_dumpbin(dumpbin, lib): symbols.append(symbol_name) return symbols +def get_symbols_gendef(gendef, lib): + ''' + List all the (non platform-specific) symbols exported by the library + using `gendef -` + ''' + symbols = [] + output = subprocess.check_output([gendef, '-', lib], + stderr=open(os.devnull, 'w')).decode("ascii") + ordinal_table_found = False + for line in output.splitlines(): + if not ordinal_table_found: + if line.strip() == 'EXPORTS': + ordinal_table_found = True + continue + + symbols.append(line.strip()) + return symbols def main(): parser = argparse.ArgumentParser() @@ -138,15 +155,21 @@ def main(): parser.add_argument('--dumpbin', action='store', help='path to binary (or name in $PATH)') + parser.add_argument('--gendef', + action='store', + help='path to binary (or name in $PATH)') parser.add_argument('--ignore-symbol', action='append', help='do not process this symbol') args = parser.parse_args() if platform.system() == 'Windows': - if not args.dumpbin: - parser.error('--dumpbin is mandatory') - lib_symbols = get_symbols_dumpbin(args.dumpbin, args.lib) + if args.dumpbin: + lib_symbols = get_symbols_dumpbin(args.dumpbin, args.lib) + elif args.gendef: + lib_symbols = get_symbols_gendef(args.gendef, args.lib) + else: + parser.error('--dumpbin is mandatory for msvc, --gendef is mandatory for mingw') else: if not args.nm: parser.error('--nm is mandatory') diff --git a/meson.build b/meson.build index 267625152c0..00d3969a0a5 100644 --- a/meson.build +++ b/meson.build @@ -2224,12 +2224,19 @@ endif pkg = import('pkgconfig') -if host_machine.system() == 'windows' +if host_machine.system() == 'windows' and cc.get_argument_syntax() == 'msvc' prog_dumpbin = find_program('dumpbin', required : false) with_symbols_check = prog_dumpbin.found() and with_tests if with_symbols_check symbols_check_args = ['--dumpbin', prog_dumpbin.full_path()] endif +elif host_machine.system() == 'windows' and cc.get_argument_syntax() != 'msvc' + # mingw + prog_gendef = find_program('gendef', required : false) + with_symbols_check = prog_gendef.found() and with_tests + if with_symbols_check + symbols_check_args = ['--gendef', prog_gendef.full_path()] + endif else prog_nm = find_program('nm') with_symbols_check = prog_nm.found() and with_tests