Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/nm2def.py @ 73323:dad02a080bbc
Improve byte-compilation in packaging to be independent of -O or -B.
The code I fixed to comply with PEP 3147 still had one bug: When run
under python -O, some paths for pyc files would be pyo, because I called
imp.cache_from_source without explicit debug_override argument in some
places, and under -O that would return .pyo (this is well explained in
the imp docs). Now all code (util.byte_compile, build_py, install_lib)
can create .pyo files according to options given by users,
without interference from the calling Python’s own optimize mode.
On a related topic, I also removed the code that prevented byte
compilation under python -B. The rationale is that packaging gives
control over the creation of pyc files to the user with its own explicit
option, and the behavior should not be changed if the calling Python
happens to run with -B for whatever reason. I will argue that this is a
bug fix and ask to be allowed to backport this change to distutils.
Finally, I moved one nugget of information about the --compile and
--optimize options from the source into the doc. It clears up a
misunderstanding that I (and maybe other people) had.
| author | Éric Araujo <merwok@netwok.org> |
|---|---|
| date | Thu, 03 Nov 2011 05:08:28 +0100 |
| parents | fcfe324663a6 |
| children |
| rev | line source |
|---|---|
|
59522
fcfe324663a6
convert shebang lines: python -> python3
Benjamin Peterson <benjamin@python.org>
parents:
47100
diff
changeset
|
1 #! /usr/bin/env python3 |
|
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 """ |
|
45471
7dd2c1746267
Merged revisions 60990-61002 via svnmerge from
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 |
|
47100
893a4dc17a91
Ran 2to3 over scripts directory.
Georg Brandl <georg@python.org>
parents:
45471
diff
changeset
|
87 for name in list(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() |
