Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/command/build.py @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | c9adace3c823 |
| children | f465d6692bde |
| 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 |
|
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
5 # created 1999/03/08, Greg Ward |
|
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
6 |
|
11897
017e592c0fd2
Changed '__rcsid__' to '__revision__'.
Greg Ward <gward@python.net>
parents:
11885
diff
changeset
|
7 __revision__ = "$Id$" |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
8 |
| 11885 | 9 import sys, os |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
10 from distutils.core import Command |
| 11885 | 11 from distutils.util import get_platform |
|
12999
7160b52ca74a
Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents:
12997
diff
changeset
|
12 |
|
7160b52ca74a
Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents:
12997
diff
changeset
|
13 |
|
7160b52ca74a
Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents:
12997
diff
changeset
|
14 def 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 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
|
16 show_compilers() |
|
7160b52ca74a
Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents:
12997
diff
changeset
|
17 |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
18 |
|
11813
eaeda4621f7d
Renamed all command classes so they're exactly the same as the name of the
Greg Ward <gward@python.net>
parents:
11731
diff
changeset
|
19 class build (Command): |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
20 |
|
11683
47f75a17b103
Added 'description' class attribute to every command class (to help the
Greg Ward <gward@python.net>
parents:
11338
diff
changeset
|
21 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
|
22 |
|
11815
03902bc0214a
Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents:
11813
diff
changeset
|
23 user_options = [ |
|
03902bc0214a
Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents:
11813
diff
changeset
|
24 ('build-base=', 'b', |
|
03902bc0214a
Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents:
11813
diff
changeset
|
25 "base directory for build library"), |
| 11885 | 26 ('build-purelib=', None, |
| 27 "build directory for platform-neutral distributions"), | |
| 28 ('build-platlib=', None, | |
| 29 "build directory for platform-specific distributions"), | |
| 30 ('build-lib=', None, | |
| 31 "build directory for all distribution (defaults to either " + | |
| 32 "build-purelib or build-platlib"), | |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12743
diff
changeset
|
33 ('build-scripts=', None, |
|
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12743
diff
changeset
|
34 "build directory for scripts"), |
| 11885 | 35 ('build-temp=', 't', |
| 36 "temporary build directory"), | |
|
12670
2feb9790b404
Fix from Lyle Johnson: add the '--compiler' option.
Gregory P. Smith <greg@mad-scientist.com>
parents:
12318
diff
changeset
|
37 ('compiler=', 'c', |
|
2feb9790b404
Fix from Lyle Johnson: add the '--compiler' option.
Gregory P. Smith <greg@mad-scientist.com>
parents:
12318
diff
changeset
|
38 "specify the compiler type"), |
|
11815
03902bc0214a
Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents:
11813
diff
changeset
|
39 ('debug', 'g', |
|
03902bc0214a
Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents:
11813
diff
changeset
|
40 "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
|
41 ('force', 'f', |
|
12670
2feb9790b404
Fix from Lyle Johnson: add the '--compiler' option.
Gregory P. Smith <greg@mad-scientist.com>
parents:
12318
diff
changeset
|
42 "forcibly build everything (ignore file timestamps)"), |
|
11815
03902bc0214a
Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents:
11813
diff
changeset
|
43 ] |
|
12997
27f3a18fd296
Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents:
12869
diff
changeset
|
44 |
|
14829
b1f220f636ed
Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents:
14615
diff
changeset
|
45 boolean_options = ['debug', 'force'] |
|
b1f220f636ed
Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents:
14615
diff
changeset
|
46 |
|
12869
88872791998a
Patch from Rene Liebscher: this adds "--help-foo" options to list the
Greg Ward <gward@python.net>
parents:
12783
diff
changeset
|
47 help_options = [ |
|
88872791998a
Patch from Rene Liebscher: this adds "--help-foo" options to list the
Greg Ward <gward@python.net>
parents:
12783
diff
changeset
|
48 ('help-compiler', None, |
|
12997
27f3a18fd296
Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents:
12869
diff
changeset
|
49 "list available compilers", show_compilers), |
| 15216 | 50 ] |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
51 |
|
11817
476eaa38e2d6
Renamed 'set_default_options()' to 'initialize_options()', and
Greg Ward <gward@python.net>
parents:
11815
diff
changeset
|
52 def initialize_options (self): |
|
11338
42941e2eb9d8
Renamed many options to be consistent across commands.
Greg Ward <gward@python.net>
parents:
11301
diff
changeset
|
53 self.build_base = 'build' |
|
42941e2eb9d8
Renamed many options to be consistent across commands.
Greg Ward <gward@python.net>
parents:
11301
diff
changeset
|
54 # 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
|
55 # (unless overridden by the user or client) |
| 11885 | 56 self.build_purelib = None |
| 57 self.build_platlib = None | |
|
11338
42941e2eb9d8
Renamed many options to be consistent across commands.
Greg Ward <gward@python.net>
parents:
11301
diff
changeset
|
58 self.build_lib = None |
| 11885 | 59 self.build_temp = None |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12743
diff
changeset
|
60 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
|
61 self.compiler = None |
|
11731
72ebf91daa05
Added 'debug' option (just there for 'build_ext' and 'build_lib' commands
Greg Ward <gward@python.net>
parents:
11714
diff
changeset
|
62 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
|
63 self.force = 0 |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
64 |
|
11817
476eaa38e2d6
Renamed 'set_default_options()' to 'initialize_options()', and
Greg Ward <gward@python.net>
parents:
11815
diff
changeset
|
65 def finalize_options (self): |
| 11885 | 66 |
|
14615
c4d05985c6f3
Tweaked the build temp dir names again.
Greg Ward <gward@python.net>
parents:
14613
diff
changeset
|
67 plat_specifier = ".%s-%s" % (get_platform(), 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
|
68 |
| 11885 | 69 # 'build_purelib' and 'build_platlib' just default to 'lib' and |
| 70 # 'lib.<plat>' under the base build directory. We only use one of | |
| 71 # them for a given distribution, though -- | |
| 72 if self.build_purelib is None: | |
|
14948
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14940
diff
changeset
|
73 self.build_purelib = os.path.join(self.build_base, 'lib') |
| 11885 | 74 if self.build_platlib is None: |
|
14948
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14940
diff
changeset
|
75 self.build_platlib = os.path.join(self.build_base, |
|
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14940
diff
changeset
|
76 'lib' + plat_specifier) |
| 11885 | 77 |
| 78 # 'build_lib' is the actual directory that we will use for this | |
| 79 # particular module distribution -- if user didn't supply it, pick | |
| 80 # 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
|
81 if self.build_lib is None: |
| 11885 | 82 if self.distribution.ext_modules: |
| 83 self.build_lib = self.build_platlib | |
| 84 else: | |
| 85 self.build_lib = self.build_purelib | |
| 86 | |
| 87 # 'build_temp' -- temporary directory for compiler turds, | |
| 88 # "build/temp.<plat>" | |
| 89 if self.build_temp is None: | |
|
14948
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14940
diff
changeset
|
90 self.build_temp = os.path.join(self.build_base, |
|
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
14940
diff
changeset
|
91 'temp' + plat_specifier) |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12743
diff
changeset
|
92 if self.build_scripts is None: |
| 21326 | 93 self.build_scripts = os.path.join(self.build_base, |
| 94 'scripts-' + sys.version[0:3]) | |
|
14615
c4d05985c6f3
Tweaked the build temp dir names again.
Greg Ward <gward@python.net>
parents:
14613
diff
changeset
|
95 |
| 11885 | 96 # finalize_options () |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
97 |
|
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
98 |
|
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
99 def run (self): |
|
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
100 |
|
14940
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
101 # 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
|
102 # - build_py - pure Python modules |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
103 # - build_clib - standalone C libraries |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
104 # - build_ext - Python extensions |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
105 # - build_scripts - (Python) scripts |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
106 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
|
107 self.run_command(cmd_name) |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
108 |
|
14940
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
109 |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
110 # -- Predicates for the sub-command list --------------------------- |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
111 |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
112 def has_pure_modules (self): |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
113 return self.distribution.has_pure_modules() |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
114 |
|
14940
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
115 def has_c_libraries (self): |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
116 return self.distribution.has_c_libraries() |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
117 |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
118 def has_ext_modules (self): |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
119 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
|
120 |
|
14940
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
121 def has_scripts (self): |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
122 return self.distribution.has_scripts() |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
123 |
|
10437
3bc8f53041c0
First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
124 |
|
14940
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
125 sub_commands = [('build_py', has_pure_modules), |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
126 ('build_clib', has_c_libraries), |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
127 ('build_ext', has_ext_modules), |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
128 ('build_scripts', has_scripts), |
|
9cea4db41d9f
Changed to use the 'sub-commands' machinery:
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
129 ] |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12743
diff
changeset
|
130 |
|
12743
e878a647e06e
Normalized all the end-of-class lines.
Greg Ward <gward@python.net>
parents:
12670
diff
changeset
|
131 # class build |
