8 # This list contains symbols that _might_ be exported for some platforms
22 def get_symbols(nm
, lib
):
24 List all the (non platform-specific) symbols exported by the library
27 platform_name
= platform
.system()
28 output
= subprocess
.check_output([nm
, '-gP', lib
],
29 stderr
=open(os
.devnull
, 'w')).decode("ascii")
30 for line
in output
.splitlines():
32 if len(fields
) == 2 or fields
[1] == 'U':
34 symbol_name
= fields
[0]
35 if platform_name
== 'Linux':
36 if symbol_name
in PLATFORM_SYMBOLS
:
38 elif platform_name
== 'Darwin':
39 assert symbol_name
[0] == '_'
40 symbol_name
= symbol_name
[1:]
41 symbols
.append(symbol_name
)
47 parser
= argparse
.ArgumentParser()
48 parser
.add_argument('--symbols-file',
51 help='path to file containing symbols')
52 parser
.add_argument('--lib',
55 help='path to library')
56 parser
.add_argument('--nm',
59 help='path to binary (or name in $PATH)')
60 args
= parser
.parse_args()
63 lib_symbols
= get_symbols(args
.nm
, args
.lib
)
65 # We can't run this test, but we haven't technically failed it either
66 # Return the GNU "skip" error code
68 mandatory_symbols
= []
70 with
open(args
.symbols_file
) as symbols_file
:
71 qualifier_optional
= '(optional)'
72 for line
in symbols_file
.readlines():
75 line
= line
.split('#')[0]
88 elif len(fields
) == 2:
92 print(args
.symbols_file
+ ': invalid format: ' + line
)
95 # The only supported qualifier is 'optional', which means the
96 # symbol doesn't have to be exported by the library
97 if qualifier
and not qualifier
== qualifier_optional
:
98 print(args
.symbols_file
+ ': invalid qualifier: ' + qualifier
)
101 if qualifier
== qualifier_optional
:
102 optional_symbols
.append(symbol
)
104 mandatory_symbols
.append(symbol
)
107 for symbol
in lib_symbols
:
108 if symbol
in mandatory_symbols
:
110 if symbol
in optional_symbols
:
112 unknown_symbols
.append(symbol
)
115 sym
for sym
in mandatory_symbols
if sym
not in lib_symbols
118 for symbol
in unknown_symbols
:
119 print(args
.lib
+ ': unknown symbol exported: ' + symbol
)
121 for symbol
in missing_symbols
:
122 print(args
.lib
+ ': missing symbol: ' + symbol
)
124 if unknown_symbols
or missing_symbols
:
129 if __name__
== '__main__':