Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/nm2def.py @ 49955:878d40468c4e legacy-trunk
Issue #4384: Added logging integration with warnings module using captureWarnings(). This change includes a NullHandler which does nothing; it will be of use to library developers who want to avoid the "No handlers could be found for logger XXX" message which can appear if the library user doesn't configure logging.
| author | Vinay Sajip <vinay_sajip@yahoo.co.uk> |
|---|---|
| date | Wed, 03 Dec 2008 23:22:58 +0000 |
| parents | 1d84bf5f9478 |
| children | 893a4dc17a91 |
| rev | line source |
|---|---|
| 9281 | 1 #! /usr/bin/env python |
|
8908
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 """nm2def.py |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 Helpers to extract symbols from Unix libs and auto-generate |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 Windows definition files from them. Depends on nm(1). Tested |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 on Linux and Solaris only (-p option to nm is for Solaris only). |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 By Marc-Andre Lemburg, Aug 1998. |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 Additional notes: the output of nm is supposed to look like this: |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 acceler.o: |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 000001fd T PyGrammar_AddAccelerators |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 U PyGrammar_FindDFA |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 00000237 T PyGrammar_RemoveAccelerators |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 U _IO_stderr_ |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 U exit |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 U fprintf |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 U free |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 U malloc |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 U printf |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 grammar1.o: |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 00000000 T PyGrammar_FindDFA |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 00000034 T PyGrammar_LabelRepr |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 U _PyParser_TokenNames |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 U abort |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 U printf |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 U sprintf |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 ... |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 Even if this isn't the default output of your nm, there is generally an |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 option to produce this format (since it is the original v7 Unix format). |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 """ |
|
45468
1d84bf5f9478
Patch #2167 from calvin: Remove unused imports
Christian Heimes <christian@cheimes.de>
parents:
25219
diff
changeset
|
37 import os, sys |
|
8908
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 PYTHONLIB = 'libpython'+sys.version[:3]+'.a' |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 PC_PYTHONLIB = 'Python'+sys.version[0]+sys.version[2]+'.dll' |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 NM = 'nm -p -g %s' # For Linux, use "nm -g %s" |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 def symbols(lib=PYTHONLIB,types=('T','C','D')): |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 lines = os.popen(NM % lib).readlines() |
|
25219
8a7a2f1f88f0
Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents:
15930
diff
changeset
|
46 lines = [s.strip() for s in lines] |
|
8908
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 symbols = {} |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 for line in lines: |
| 9103 | 49 if len(line) == 0 or ':' in line: |
| 50 continue | |
|
25219
8a7a2f1f88f0
Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents:
15930
diff
changeset
|
51 items = line.split() |
| 9103 | 52 if len(items) != 3: |
| 53 continue | |
| 54 address, type, name = items | |
| 55 if type not in types: | |
| 56 continue | |
| 57 symbols[name] = address,type | |
|
8908
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 return symbols |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 def export_list(symbols): |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 data = [] |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 code = [] |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 for name,(addr,type) in symbols.items(): |
| 9103 | 65 if type in ('C','D'): |
| 66 data.append('\t'+name) | |
| 67 else: | |
| 68 code.append('\t'+name) | |
|
8908
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 data.sort() |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 data.append('') |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 code.sort() |
|
25219
8a7a2f1f88f0
Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents:
15930
diff
changeset
|
72 return ' DATA\n'.join(data)+'\n'+'\n'.join(code) |
|
8908
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 # Definition file template |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 DEF_TEMPLATE = """\ |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 EXPORTS |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 %s |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 """ |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 # Special symbols that have to be included even though they don't |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 # pass the filter |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 SPECIALS = ( |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 ) |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 def filter_Python(symbols,specials=SPECIALS): |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 for name in symbols.keys(): |
| 9103 | 88 if name[:2] == 'Py' or name[:3] == '_Py': |
| 89 pass | |
| 90 elif name not in specials: | |
| 91 del symbols[name] | |
|
8908
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 def main(): |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 s = symbols(PYTHONLIB) |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 filter_Python(s) |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 exports = export_list(s) |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 f = sys.stdout # open('PC/python_nt.def','w') |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 f.write(DEF_TEMPLATE % (exports)) |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 f.close() |
|
15930
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
9281
diff
changeset
|
101 |
|
8908
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 if __name__ == '__main__': |
|
7d6813521f61
A script by Mark-Andre Lemburg to produce the PC/python_nt.def file
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 main() |
