Fixed #1885: --formats=tar,gztar was not working properly in the sdist command
[python.git] / Lib / distutils / command / build.py
blob84e050204e145a35abb98d92c87c028c936d4fa7
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
13 def show_compilers ():
14 from distutils.ccompiler import show_compilers
15 show_compilers()
18 class build (Command):
20 description = "build everything needed to install"
22 user_options = [
23 ('build-base=', 'b',
24 "base directory for build library"),
25 ('build-purelib=', None,
26 "build directory for platform-neutral distributions"),
27 ('build-platlib=', None,
28 "build directory for platform-specific distributions"),
29 ('build-lib=', None,
30 "build directory for all distribution (defaults to either " +
31 "build-purelib or build-platlib"),
32 ('build-scripts=', None,
33 "build directory for scripts"),
34 ('build-temp=', 't',
35 "temporary build directory"),
36 ('plat-name=', 'p',
37 "platform name to build for, if supported "
38 "(default: %s)" % get_platform()),
39 ('compiler=', 'c',
40 "specify the compiler type"),
41 ('debug', 'g',
42 "compile extensions and libraries with debugging information"),
43 ('force', 'f',
44 "forcibly build everything (ignore file timestamps)"),
45 ('executable=', 'e',
46 "specify final destination interpreter path (build.py)"),
49 boolean_options = ['debug', 'force']
51 help_options = [
52 ('help-compiler', None,
53 "list available compilers", show_compilers),
56 def initialize_options (self):
57 self.build_base = 'build'
58 # these are decided only after 'build_base' has its final value
59 # (unless overridden by the user or client)
60 self.build_purelib = None
61 self.build_platlib = None
62 self.build_lib = None
63 self.build_temp = None
64 self.build_scripts = None
65 self.compiler = None
66 self.plat_name = None
67 self.debug = None
68 self.force = 0
69 self.executable = None
71 def finalize_options (self):
73 if self.plat_name is None:
74 self.plat_name = get_platform()
75 else:
76 # plat-name only supported for windows (other platforms are
77 # supported via ./configure flags, if at all). Avoid misleading
78 # other platforms.
79 if os.name != 'nt':
80 raise DistutilsOptionError(
81 "--plat-name only supported on Windows (try "
82 "using './configure --help' on your platform)")
84 plat_specifier = ".%s-%s" % (self.plat_name, sys.version[0:3])
86 # Make it so Python 2.x and Python 2.x with --with-pydebug don't
87 # share the same build directories. Doing so confuses the build
88 # process for C modules
89 if hasattr(sys, 'gettotalrefcount'):
90 plat_specifier += '-pydebug'
92 # 'build_purelib' and 'build_platlib' just default to 'lib' and
93 # 'lib.<plat>' under the base build directory. We only use one of
94 # them for a given distribution, though --
95 if self.build_purelib is None:
96 self.build_purelib = os.path.join(self.build_base, 'lib')
97 if self.build_platlib is None:
98 self.build_platlib = os.path.join(self.build_base,
99 'lib' + plat_specifier)
101 # 'build_lib' is the actual directory that we will use for this
102 # particular module distribution -- if user didn't supply it, pick
103 # one of 'build_purelib' or 'build_platlib'.
104 if self.build_lib is None:
105 if self.distribution.ext_modules:
106 self.build_lib = self.build_platlib
107 else:
108 self.build_lib = self.build_purelib
110 # 'build_temp' -- temporary directory for compiler turds,
111 # "build/temp.<plat>"
112 if self.build_temp is None:
113 self.build_temp = os.path.join(self.build_base,
114 'temp' + plat_specifier)
115 if self.build_scripts is None:
116 self.build_scripts = os.path.join(self.build_base,
117 'scripts-' + sys.version[0:3])
119 if self.executable is None:
120 self.executable = os.path.normpath(sys.executable)
121 # finalize_options ()
124 def run (self):
126 # Run all relevant sub-commands. This will be some subset of:
127 # - build_py - pure Python modules
128 # - build_clib - standalone C libraries
129 # - build_ext - Python extensions
130 # - build_scripts - (Python) scripts
131 for cmd_name in self.get_sub_commands():
132 self.run_command(cmd_name)
135 # -- Predicates for the sub-command list ---------------------------
137 def has_pure_modules (self):
138 return self.distribution.has_pure_modules()
140 def has_c_libraries (self):
141 return self.distribution.has_c_libraries()
143 def has_ext_modules (self):
144 return self.distribution.has_ext_modules()
146 def has_scripts (self):
147 return self.distribution.has_scripts()
150 sub_commands = [('build_py', has_pure_modules),
151 ('build_clib', has_c_libraries),
152 ('build_ext', has_ext_modules),
153 ('build_scripts', has_scripts),
156 # class build