1 """distutils.command.build
3 Implements the Distutils 'build' command."""
9 from distutils
.util
import get_platform
10 from distutils
.core
import Command
11 from distutils
.errors
import DistutilsOptionError
14 from distutils
.ccompiler
import show_compilers
19 description
= "build everything needed to install"
23 "base directory for build library"),
24 ('build-purelib=', None,
25 "build directory for platform-neutral distributions"),
26 ('build-platlib=', None,
27 "build directory for platform-specific distributions"),
29 "build directory for all distribution (defaults to either " +
30 "build-purelib or build-platlib"),
31 ('build-scripts=', None,
32 "build directory for scripts"),
34 "temporary build directory"),
36 "platform name to build for, if supported "
37 "(default: %s)" % get_platform()),
39 "specify the compiler type"),
41 "compile extensions and libraries with debugging information"),
43 "forcibly build everything (ignore file timestamps)"),
45 "specify final destination interpreter path (build.py)"),
48 boolean_options
= ['debug', 'force']
51 ('help-compiler', None,
52 "list available compilers", show_compilers
),
55 def initialize_options(self
):
56 self
.build_base
= 'build'
57 # these are decided only after 'build_base' has its final value
58 # (unless overridden by the user or client)
59 self
.build_purelib
= None
60 self
.build_platlib
= None
62 self
.build_temp
= None
63 self
.build_scripts
= None
68 self
.executable
= None
70 def finalize_options(self
):
71 if self
.plat_name
is None:
72 self
.plat_name
= get_platform()
74 # plat-name only supported for windows (other platforms are
75 # supported via ./configure flags, if at all). Avoid misleading
78 raise DistutilsOptionError(
79 "--plat-name only supported on Windows (try "
80 "using './configure --help' on your platform)")
82 plat_specifier
= ".%s-%s" % (self
.plat_name
, sys
.version
[0:3])
84 # Make it so Python 2.x and Python 2.x with --with-pydebug don't
85 # share the same build directories. Doing so confuses the build
86 # process for C modules
87 if hasattr(sys
, 'gettotalrefcount'):
88 plat_specifier
+= '-pydebug'
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:
94 self
.build_purelib
= os
.path
.join(self
.build_base
, 'lib')
95 if self
.build_platlib
is None:
96 self
.build_platlib
= os
.path
.join(self
.build_base
,
97 'lib' + plat_specifier
)
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'.
102 if self
.build_lib
is None:
103 if self
.distribution
.ext_modules
:
104 self
.build_lib
= self
.build_platlib
106 self
.build_lib
= self
.build_purelib
108 # 'build_temp' -- temporary directory for compiler turds,
109 # "build/temp.<plat>"
110 if self
.build_temp
is None:
111 self
.build_temp
= os
.path
.join(self
.build_base
,
112 'temp' + plat_specifier
)
113 if self
.build_scripts
is None:
114 self
.build_scripts
= os
.path
.join(self
.build_base
,
115 'scripts-' + sys
.version
[0:3])
117 if self
.executable
is None:
118 self
.executable
= os
.path
.normpath(sys
.executable
)
121 # Run all relevant sub-commands. This will be some subset of:
122 # - build_py - pure Python modules
123 # - build_clib - standalone C libraries
124 # - build_ext - Python extensions
125 # - build_scripts - (Python) scripts
126 for cmd_name
in self
.get_sub_commands():
127 self
.run_command(cmd_name
)
129 # -- Predicates for the sub-command list ---------------------------
131 def has_pure_modules (self
):
132 return self
.distribution
.has_pure_modules()
134 def has_c_libraries (self
):
135 return self
.distribution
.has_c_libraries()
137 def has_ext_modules (self
):
138 return self
.distribution
.has_ext_modules()
140 def has_scripts (self
):
141 return self
.distribution
.has_scripts()
143 sub_commands
= [('build_py', has_pure_modules
),
144 ('build_clib', has_c_libraries
),
145 ('build_ext', has_ext_modules
),
146 ('build_scripts', has_scripts
),