Credit Nir Aides for r77288
[python.git] / Lib / distutils / command / build.py
blobd394e4b1da13684da70f5d1938e6a469778a87e9
1 """distutils.command.build
3 Implements the Distutils 'build' command."""
5 __revision__ = "$Id$"
7 import sys, os
8 from distutils.core import Command
9 from distutils.errors import DistutilsOptionError
10 from distutils.util import get_platform
12 def show_compilers():
13 from distutils.ccompiler import show_compilers
14 show_compilers()
16 class build(Command):
18 description = "build everything needed to install"
20 user_options = [
21 ('build-base=', 'b',
22 "base directory for build library"),
23 ('build-purelib=', None,
24 "build directory for platform-neutral distributions"),
25 ('build-platlib=', None,
26 "build directory for platform-specific distributions"),
27 ('build-lib=', None,
28 "build directory for all distribution (defaults to either " +
29 "build-purelib or build-platlib"),
30 ('build-scripts=', None,
31 "build directory for scripts"),
32 ('build-temp=', 't',
33 "temporary build directory"),
34 ('plat-name=', 'p',
35 "platform name to build for, if supported "
36 "(default: %s)" % get_platform()),
37 ('compiler=', 'c',
38 "specify the compiler type"),
39 ('debug', 'g',
40 "compile extensions and libraries with debugging information"),
41 ('force', 'f',
42 "forcibly build everything (ignore file timestamps)"),
43 ('executable=', 'e',
44 "specify final destination interpreter path (build.py)"),
47 boolean_options = ['debug', 'force']
49 help_options = [
50 ('help-compiler', None,
51 "list available compilers", show_compilers),
54 def initialize_options(self):
55 self.build_base = 'build'
56 # these are decided only after 'build_base' has its final value
57 # (unless overridden by the user or client)
58 self.build_purelib = None
59 self.build_platlib = None
60 self.build_lib = None
61 self.build_temp = None
62 self.build_scripts = None
63 self.compiler = None
64 self.plat_name = None
65 self.debug = None
66 self.force = 0
67 self.executable = None
69 def finalize_options(self):
70 if self.plat_name is None:
71 self.plat_name = get_platform()
72 else:
73 # plat-name only supported for windows (other platforms are
74 # supported via ./configure flags, if at all). Avoid misleading
75 # other platforms.
76 if os.name != 'nt':
77 raise DistutilsOptionError(
78 "--plat-name only supported on Windows (try "
79 "using './configure --help' on your platform)")
81 plat_specifier = ".%s-%s" % (self.plat_name, sys.version[0:3])
83 # Make it so Python 2.x and Python 2.x with --with-pydebug don't
84 # share the same build directories. Doing so confuses the build
85 # process for C modules
86 if hasattr(sys, 'gettotalrefcount'):
87 plat_specifier += '-pydebug'
89 # 'build_purelib' and 'build_platlib' just default to 'lib' and
90 # 'lib.<plat>' under the base build directory. We only use one of
91 # them for a given distribution, though --
92 if self.build_purelib is None:
93 self.build_purelib = os.path.join(self.build_base, 'lib')
94 if self.build_platlib is None:
95 self.build_platlib = os.path.join(self.build_base,
96 'lib' + plat_specifier)
98 # 'build_lib' is the actual directory that we will use for this
99 # particular module distribution -- if user didn't supply it, pick
100 # one of 'build_purelib' or 'build_platlib'.
101 if self.build_lib is None:
102 if self.distribution.ext_modules:
103 self.build_lib = self.build_platlib
104 else:
105 self.build_lib = self.build_purelib
107 # 'build_temp' -- temporary directory for compiler turds,
108 # "build/temp.<plat>"
109 if self.build_temp is None:
110 self.build_temp = os.path.join(self.build_base,
111 'temp' + plat_specifier)
112 if self.build_scripts is None:
113 self.build_scripts = os.path.join(self.build_base,
114 'scripts-' + sys.version[0:3])
116 if self.executable is None:
117 self.executable = os.path.normpath(sys.executable)
119 def run(self):
120 # Run all relevant sub-commands. This will be some subset of:
121 # - build_py - pure Python modules
122 # - build_clib - standalone C libraries
123 # - build_ext - Python extensions
124 # - build_scripts - (Python) scripts
125 for cmd_name in self.get_sub_commands():
126 self.run_command(cmd_name)
128 # -- Predicates for the sub-command list ---------------------------
130 def has_pure_modules (self):
131 return self.distribution.has_pure_modules()
133 def has_c_libraries (self):
134 return self.distribution.has_c_libraries()
136 def has_ext_modules (self):
137 return self.distribution.has_ext_modules()
139 def has_scripts (self):
140 return self.distribution.has_scripts()
142 sub_commands = [('build_py', has_pure_modules),
143 ('build_clib', has_c_libraries),
144 ('build_ext', has_ext_modules),
145 ('build_scripts', has_scripts),