Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/command/build.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | f9fd1795fcf7 |
| children |
| rev | line source |
|---|---|
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
1 """distutils.command.build |
|
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
2 |
|
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
3 Implements the Distutils 'build' command.""" |
|
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
4 |
|
11897
017e592c0fd2
Changed '__rcsid__' to '__revision__'.
Greg Ward <gward@python.net>
parents:
11885
diff
changeset
|
5 __revision__ = "$Id$" |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
6 |
| 11885 | 7 import sys, os |
|
58450
fa69e891edf4
taking sysconfig out of distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55188
diff
changeset
|
8 |
|
58503
f9fd1795fcf7
added local get_platform/set_platform APIs in distutils.sysconfig
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
58450
diff
changeset
|
9 from distutils.util import get_platform |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
10 from distutils.core import Command |
|
46331
a93d2919ea59
Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents:
44850
diff
changeset
|
11 from distutils.errors import DistutilsOptionError |
|
12999
7160b52ca74a
Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents:
12997
diff
changeset
|
12 |
|
55188
03b86606ce0a
cleaned up distutils.command.build
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51047
diff
changeset
|
13 def show_compilers(): |
|
12999
7160b52ca74a
Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents:
12997
diff
changeset
|
14 from distutils.ccompiler import show_compilers |
|
7160b52ca74a
Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents:
12997
diff
changeset
|
15 show_compilers() |
|
7160b52ca74a
Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents:
12997
diff
changeset
|
16 |
|
55188
03b86606ce0a
cleaned up distutils.command.build
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51047
diff
changeset
|
17 class build(Command): |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
18 |
|
11683
47f75a17b103
Added 'description' class attribute to every command class (to help the
Greg Ward <gward@python.net>
parents:
11338
diff
changeset
|
19 description = "build everything needed to install" |
|
47f75a17b103
Added 'description' class attribute to every command class (to help the
Greg Ward <gward@python.net>
parents:
11338
diff
changeset
|
20 |
|
11815
03902bc0214a
Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents:
11813
diff
changeset
|
21 user_options = [ |
|
03902bc0214a
Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents:
11813
diff
changeset
|
22 ('build-base=', 'b', |
|
03902bc0214a
Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents:
11813
diff
changeset
|
23 "base directory for build library"), |
| 11885 | 24 ('build-purelib=', None, |
| 25 "build directory for platform-neutral distributions"), | |
| 26 ('build-platlib=', None, | |
| 27 "build directory for platform-specific distributions"), | |
| 28 ('build-lib=', None, | |
| 29 "build directory for all distribution (defaults to either " + | |
| 30 "build-purelib or build-platlib"), | |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12743
diff
changeset
|
31 ('build-scripts=', None, |
|
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12743
diff
changeset
|
32 "build directory for scripts"), |
| 11885 | 33 ('build-temp=', 't', |
| 34 "temporary build directory"), | |
|
46331
a93d2919ea59
Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents:
44850
diff
changeset
|
35 ('plat-name=', 'p', |
|
a93d2919ea59
Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents:
44850
diff
changeset
|
36 "platform name to build for, if supported " |
|
a93d2919ea59
Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents:
44850
diff
changeset
|
37 "(default: %s)" % get_platform()), |
|
12670
2feb9790b404
Fix from Lyle Johnson: add the '--compiler' option.
Gregory P. Smith <greg@mad-scientist.com>
parents:
12318
diff
changeset
|
38 ('compiler=', 'c', |
|
2feb9790b404
Fix from Lyle Johnson: add the '--compiler' option.
Gregory P. Smith <greg@mad-scientist.com>
parents:
12318
diff
changeset
|
39 "specify the compiler type"), |
|
11815
03902bc0214a
Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents:
11813
diff
changeset
|
40 ('debug', 'g', |
|
03902bc0214a
Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents:
11813
diff
changeset
|
41 "compile extensions and libraries with debugging information"), |
|
12314
20a5cbf9fcc0
Added '--force' option -- very clear what it means for building (ignore
Greg Ward <gward@python.net>
parents:
12096
diff
changeset
|
42 ('force', 'f', |
|
12670
2feb9790b404
Fix from Lyle Johnson: add the '--compiler' option.
Gregory P. Smith <greg@mad-scientist.com>
parents:
12318
diff
changeset
|
43 "forcibly build everything (ignore file timestamps)"), |
|
33266
4e9ecbf47b6b
Patch #736857, #736859: Add -e option to build_scripts.
Martin v. Löwis <martin@v.loewis.de>
parents:
26285
diff
changeset
|
44 ('executable=', 'e', |
|
4e9ecbf47b6b
Patch #736857, #736859: Add -e option to build_scripts.
Martin v. Löwis <martin@v.loewis.de>
parents:
26285
diff
changeset
|
45 "specify final destination interpreter path (build.py)"), |
|
11815
03902bc0214a
Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents:
11813
diff
changeset
|
46 ] |
|
12997
27f3a18fd296
Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents:
12869
diff
changeset
|
47 |
|
14829
b1f220f636ed
Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents:
14615
diff
changeset
|
48 boolean_options = ['debug', 'force'] |
|
b1f220f636ed
Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents:
14615
diff
changeset
|
49 |
|
12869
88872791998a
Patch from Rene Liebscher: this adds "--help-foo" options to list the
Greg Ward <gward@python.net>
parents:
12783
diff
changeset
|
50 help_options = [ |
|
88872791998a
Patch from Rene Liebscher: this adds "--help-foo" options to list the
Greg Ward <gward@python.net>
parents:
12783
diff
changeset
|
51 ('help-compiler', None, |
|
12997
27f3a18fd296
Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents:
12869
diff
changeset
|
52 "list available compilers", show_compilers), |
| 15216 | 53 ] |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
54 |
|
55188
03b86606ce0a
cleaned up distutils.command.build
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51047
diff
changeset
|
55 def initialize_options(self): |
|
11338
42941e2eb9d8
Renamed many options to be consistent across commands.
Greg Ward <gward@python.net>
parents:
11301
diff
changeset
|
56 self.build_base = 'build' |
|
42941e2eb9d8
Renamed many options to be consistent across commands.
Greg Ward <gward@python.net>
parents:
11301
diff
changeset
|
57 # these are decided only after 'build_base' has its final value |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
58 # (unless overridden by the user or client) |
| 11885 | 59 self.build_purelib = None |
| 60 self.build_platlib = None | |
|
11338
42941e2eb9d8
Renamed many options to be consistent across commands.
Greg Ward <gward@python.net>
parents:
11301
diff
changeset
|
61 self.build_lib = None |
| 11885 | 62 self.build_temp = None |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12743
diff
changeset
|
63 self.build_scripts = None |
|
12670
2feb9790b404
Fix from Lyle Johnson: add the '--compiler' option.
Gregory P. Smith <greg@mad-scientist.com>
parents:
12318
diff
changeset
|
64 self.compiler = None |
|
46331
a93d2919ea59
Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents:
44850
diff
changeset
|
65 self.plat_name = None |
|
11731
72ebf91daa05
Added 'debug' option (just there for 'build_ext' and 'build_lib' commands
Greg Ward <gward@python.net>
parents:
11714
diff
changeset
|
66 self.debug = None |
|
12314
20a5cbf9fcc0
Added '--force' option -- very clear what it means for building (ignore
Greg Ward <gward@python.net>
parents:
12096
diff
changeset
|
67 self.force = 0 |
|
33266
4e9ecbf47b6b
Patch #736857, #736859: Add -e option to build_scripts.
Martin v. Löwis <martin@v.loewis.de>
parents:
26285
diff
changeset
|
68 self.executable = None |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
69 |
|
55188
03b86606ce0a
cleaned up distutils.command.build
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51047
diff
changeset
|
70 def finalize_options(self): |
|
46331
a93d2919ea59
Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents:
44850
diff
changeset
|
71 if self.plat_name is None: |
|
a93d2919ea59
Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents:
44850
diff
changeset
|
72 self.plat_name = get_platform() |
|
a93d2919ea59
Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents:
44850
diff
changeset
|
73 else: |
|
a93d2919ea59
Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents:
44850
diff
changeset
|
74 # plat-name only supported for windows (other platforms are |
|
a93d2919ea59
Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents:
44850
diff
changeset
|
75 # supported via ./configure flags, if at all). Avoid misleading |
|
a93d2919ea59
Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents:
44850
diff
changeset
|
76 # other platforms. |
|
a93d2919ea59
Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents:
44850
diff
changeset
|
77 if os.name != 'nt': |
|
a93d2919ea59
Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents:
44850
diff
changeset
|
78 raise DistutilsOptionError( |
|
a93d2919ea59
Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents:
44850
diff
changeset
|
79 "--plat-name only supported on Windows (try " |
|
a93d2919ea59
Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents:
44850
diff
changeset
|
80 "using './configure --help' on your platform)") |
|
a93d2919ea59
Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents:
44850
diff
changeset
|
81 |
|
a93d2919ea59
Issue #2513: enable 64bit cross compilation on windows.
Mark Hammond <mhammond@skippinet.com.au>
parents:
44850
diff
changeset
|
82 plat_specifier = ".%s-%s" % (self.plat_name, sys.version[0:3]) |
|
14613
5a512ec8a7ad
Include the Python version in the platform-specific build directories:
Greg Ward <gward@python.net>
parents:
12999
diff
changeset
|
83 |
|
44850
729495f7b221
#1530959: change distutils build dir for --with-pydebug python builds.
Georg Brandl <georg@python.org>
parents:
33965
diff
changeset
|
84 # Make it so Python 2.x and Python 2.x with --with-pydebug don't |
|
729495f7b221
#1530959: change distutils build dir for --with-pydebug python builds.
Georg Brandl <georg@python.org>
parents:
33965
diff
changeset
|
85 # share the same build directories. Doing so confuses the build |
|
729495f7b221
#1530959: change distutils build dir for --with-pydebug python builds.
Georg Brandl <georg@python.org>
parents:
33965
diff
changeset
|
86 # process for C modules |
|
729495f7b221
#1530959: change distutils build dir for --with-pydebug python builds.
Georg Brandl <georg@python.org>
parents:
33965
diff
changeset
|
87 if hasattr(sys, 'gettotalrefcount'): |
|
729495f7b221
#1530959: change distutils build dir for --with-pydebug python builds.
Georg Brandl <georg@python.org>
parents:
33965
diff
changeset
|
88 plat_specifier += '-pydebug' |
|
729495f7b221
#1530959: change distutils build dir for --with-pydebug python builds.
Georg Brandl <georg@python.org>
parents:
33965
diff
changeset
|
89 |
| 11885 | 90 # 'build_purelib' and 'build_platlib' just default to 'lib' and |
| 91 # 'lib.<plat>' under the base build directory. We only use one of | |
| 92 # them for a given distribution, though -- | |
| 93 if self.build_purelib is None: | |
|
14948
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14940
diff
changeset
|
94 self.build_purelib = os.path.join(self.build_base, 'lib') |
| 11885 | 95 if self.build_platlib is None: |
|
14948
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14940
diff
changeset
|
96 self.build_platlib = os.path.join(self.build_base, |
|
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14940
diff
changeset
|
97 'lib' + plat_specifier) |
| 11885 | 98 |
| 99 # 'build_lib' is the actual directory that we will use for this | |
| 100 # particular module distribution -- if user didn't supply it, pick | |
| 101 # one of 'build_purelib' or 'build_platlib'. | |
|
11338
42941e2eb9d8
Renamed many options to be consistent across commands.
Greg Ward <gward@python.net>
parents:
11301
diff
changeset
|
102 if self.build_lib is None: |
| 11885 | 103 if self.distribution.ext_modules: |
| 104 self.build_lib = self.build_platlib | |
| 105 else: | |
| 106 self.build_lib = self.build_purelib | |
| 107 | |
| 108 # 'build_temp' -- temporary directory for compiler turds, | |
| 109 # "build/temp.<plat>" | |
| 110 if self.build_temp is None: | |
|
14948
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14940
diff
changeset
|
111 self.build_temp = os.path.join(self.build_base, |
|
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14940
diff
changeset
|
112 'temp' + plat_specifier) |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12743
diff
changeset
|
113 if self.build_scripts is None: |
| 21326 | 114 self.build_scripts = os.path.join(self.build_base, |
| 115 'scripts-' + sys.version[0:3]) | |
|
14615
c4d05985c6f3
Tweaked the build temp dir names again.
Greg Ward <gward@python.net>
parents:
14613
diff
changeset
|
116 |
|
33266
4e9ecbf47b6b
Patch #736857, #736859: Add -e option to build_scripts.
Martin v. Löwis <martin@v.loewis.de>
parents:
26285
diff
changeset
|
117 if self.executable is None: |
|
4e9ecbf47b6b
Patch #736857, #736859: Add -e option to build_scripts.
Martin v. Löwis <martin@v.loewis.de>
parents:
26285
diff
changeset
|
118 self.executable = os.path.normpath(sys.executable) |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
119 |
|
55188
03b86606ce0a
cleaned up distutils.command.build
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51047
diff
changeset
|
120 def run(self): |
|
14940
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
121 # Run all relevant sub-commands. This will be some subset of: |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
122 # - build_py - pure Python modules |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
123 # - build_clib - standalone C libraries |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
124 # - build_ext - Python extensions |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
125 # - build_scripts - (Python) scripts |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
126 for cmd_name in self.get_sub_commands(): |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
127 self.run_command(cmd_name) |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
128 |
|
14940
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
129 # -- Predicates for the sub-command list --------------------------- |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
130 |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
131 def has_pure_modules (self): |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
132 return self.distribution.has_pure_modules() |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
133 |
|
14940
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
134 def has_c_libraries (self): |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
135 return self.distribution.has_c_libraries() |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
136 |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
137 def has_ext_modules (self): |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
138 return self.distribution.has_ext_modules() |
|
11714
b3223f03c9ea
Run the 'build_lib' command before building extensions, if necessary.
Greg Ward <gward@python.net>
parents:
11683
diff
changeset
|
139 |
|
14940
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
140 def has_scripts (self): |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
141 return self.distribution.has_scripts() |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
142 |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
143 sub_commands = [('build_py', has_pure_modules), |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
144 ('build_clib', has_c_libraries), |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
145 ('build_ext', has_ext_modules), |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
146 ('build_scripts', has_scripts), |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
147 ] |
