Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
distutils.command.build_ext.build_ext Class Reference
Inheritance diagram for distutils.command.build_ext.build_ext:
Inheritance graph
[legend]
Collaboration diagram for distutils.command.build_ext.build_ext:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def initialize_options
def finalize_options
def run
def check_extensions_list
def get_source_files
def get_outputs
def build_extensions
def build_extension
def swig_sources
def find_swig
def get_ext_fullpath
def get_ext_fullname
def get_ext_filename
def get_export_symbols
def get_libraries

Public Attributes

 extensions
 build_lib
 plat_name
 build_temp
 inplace
 package
 include_dirs
 define
 undef
 libraries
 library_dirs
 rpath
 link_objects
 debug
 force
 compiler
 swig
 swig_cpp
 swig_opts
 user

Static Public Attributes

string description = "build C/C++ extensions (compile/link to build directory)"
string sep_by = " (separated by '%s')"
list user_options
list boolean_options = ['inplace', 'debug', 'force', 'swig-cpp']
list help_options

Private Attributes

 _built_objects

Detailed Description

Definition at line 39 of file build_ext.py.


Member Function Documentation

Reimplemented in setup.PyBuildExt.

Definition at line 461 of file build_ext.py.

00461 
00462     def build_extension(self, ext):
00463         sources = ext.sources
00464         if sources is None or not isinstance(sources, (list, tuple)):
00465             raise DistutilsSetupError(
00466                   "in 'ext_modules' option (extension '%s'), "
00467                   "'sources' must be present and must be "
00468                   "a list of source filenames" % ext.name)
00469         sources = list(sources)
00470 
00471         ext_path = self.get_ext_fullpath(ext.name)
00472         depends = sources + ext.depends
00473         if not (self.force or newer_group(depends, ext_path, 'newer')):
00474             log.debug("skipping '%s' extension (up-to-date)", ext.name)
00475             return
00476         else:
00477             log.info("building '%s' extension", ext.name)
00478 
00479         # First, scan the sources for SWIG definition files (.i), run
00480         # SWIG on 'em to create .c files, and modify the sources list
00481         # accordingly.
00482         sources = self.swig_sources(sources, ext)
00483 
00484         # Next, compile the source code to object files.
00485 
00486         # XXX not honouring 'define_macros' or 'undef_macros' -- the
00487         # CCompiler API needs to change to accommodate this, and I
00488         # want to do one thing at a time!
00489 
00490         # Two possible sources for extra compiler arguments:
00491         #   - 'extra_compile_args' in Extension object
00492         #   - CFLAGS environment variable (not particularly
00493         #     elegant, but people seem to expect it and I
00494         #     guess it's useful)
00495         # The environment variable should take precedence, and
00496         # any sensible compiler will give precedence to later
00497         # command line args.  Hence we combine them in order:
00498         extra_args = ext.extra_compile_args or []
00499 
00500         macros = ext.define_macros[:]
00501         for undef in ext.undef_macros:
00502             macros.append((undef,))
00503 
00504         objects = self.compiler.compile(sources,
00505                                          output_dir=self.build_temp,
00506                                          macros=macros,
00507                                          include_dirs=ext.include_dirs,
00508                                          debug=self.debug,
00509                                          extra_postargs=extra_args,
00510                                          depends=ext.depends)
00511 
00512         # XXX -- this is a Vile HACK!
00513         #
00514         # The setup.py script for Python on Unix needs to be able to
00515         # get this list so it can perform all the clean up needed to
00516         # avoid keeping object files around when cleaning out a failed
00517         # build of an extension module.  Since Distutils does not
00518         # track dependencies, we have to get rid of intermediates to
00519         # ensure all the intermediates will be properly re-built.
00520         #
00521         self._built_objects = objects[:]
00522 
00523         # Now link the object files together into a "shared object" --
00524         # of course, first we have to figure out all the other things
00525         # that go into the mix.
00526         if ext.extra_objects:
00527             objects.extend(ext.extra_objects)
00528         extra_args = ext.extra_link_args or []
00529 
00530         # Detect target language, if not provided
00531         language = ext.language or self.compiler.detect_language(sources)
00532 
00533         self.compiler.link_shared_object(
00534             objects, ext_path,
00535             libraries=self.get_libraries(ext),
00536             library_dirs=ext.library_dirs,
00537             runtime_library_dirs=ext.runtime_library_dirs,
00538             extra_postargs=extra_args,
00539             export_symbols=self.get_export_symbols(ext),
00540             debug=self.debug,
00541             build_temp=self.build_temp,
00542             target_lang=language)

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented in setup.PyBuildExt.

Definition at line 448 of file build_ext.py.

00448 
00449     def build_extensions(self):
00450         # First, sanity-check the 'extensions' list
00451         self.check_extensions_list(self.extensions)
00452 
00453         for ext in self.extensions:
00454             try:
00455                 self.build_extension(ext)
00456             except (CCompilerError, DistutilsError, CompileError) as e:
00457                 if not ext.optional:
00458                     raise
00459                 self.warn('building extension "%s" failed: %s' %
00460                           (ext.name, e))

Here is the call graph for this function:

Here is the caller graph for this function:

Ensure that the list of extensions (presumably provided as a
command option 'extensions') is valid, i.e. it is a list of
Extension objects.  We also support the old-style list of 2-tuples,
where the tuples are (ext_name, build_info), which are converted to
Extension instances here.

Raise DistutilsSetupError if the structure is invalid anywhere;
just returns otherwise.

Definition at line 347 of file build_ext.py.

00347 
00348     def check_extensions_list(self, extensions):
00349         """Ensure that the list of extensions (presumably provided as a
00350         command option 'extensions') is valid, i.e. it is a list of
00351         Extension objects.  We also support the old-style list of 2-tuples,
00352         where the tuples are (ext_name, build_info), which are converted to
00353         Extension instances here.
00354 
00355         Raise DistutilsSetupError if the structure is invalid anywhere;
00356         just returns otherwise.
00357         """
00358         if not isinstance(extensions, list):
00359             raise DistutilsSetupError(
00360                   "'ext_modules' option must be a list of Extension instances")
00361 
00362         for i, ext in enumerate(extensions):
00363             if isinstance(ext, Extension):
00364                 continue                # OK! (assume type-checking done
00365                                         # by Extension constructor)
00366 
00367             if not isinstance(ext, tuple) or len(ext) != 2:
00368                 raise DistutilsSetupError(
00369                        "each element of 'ext_modules' option must be an "
00370                        "Extension instance or 2-tuple")
00371 
00372             ext_name, build_info = ext
00373 
00374             log.warn(("old-style (ext_name, build_info) tuple found in "
00375                       "ext_modules for extension '%s'"
00376                       "-- please convert to Extension instance" % ext_name))
00377 
00378             if not (isinstance(ext_name, str) and
00379                     extension_name_re.match(ext_name)):
00380                 raise DistutilsSetupError(
00381                        "first element of each tuple in 'ext_modules' "
00382                        "must be the extension name (a string)")
00383 
00384             if not isinstance(build_info, dict):
00385                 raise DistutilsSetupError(
00386                        "second element of each tuple in 'ext_modules' "
00387                        "must be a dictionary (build info)")
00388 
00389             # OK, the (ext_name, build_info) dict is type-safe: convert it
00390             # to an Extension instance.
00391             ext = Extension(ext_name, build_info['sources'])
00392 
00393             # Easy stuff: one-to-one mapping from dict elements to
00394             # instance attributes.
00395             for key in ('include_dirs', 'library_dirs', 'libraries',
00396                         'extra_objects', 'extra_compile_args',
00397                         'extra_link_args'):
00398                 val = build_info.get(key)
00399                 if val is not None:
00400                     setattr(ext, key, val)
00401 
00402             # Medium-easy stuff: same syntax/semantics, different names.
00403             ext.runtime_library_dirs = build_info.get('rpath')
00404             if 'def_file' in build_info:
00405                 log.warn("'def_file' element of build info dict "
00406                          "no longer supported")
00407 
00408             # Non-trivial stuff: 'macros' split into 'define_macros'
00409             # and 'undef_macros'.
00410             macros = build_info.get('macros')
00411             if macros:
00412                 ext.define_macros = []
00413                 ext.undef_macros = []
00414                 for macro in macros:
00415                     if not (isinstance(macro, tuple) and len(macro) in (1, 2)):
00416                         raise DistutilsSetupError(
00417                               "'macros' element of build info dict "
00418                               "must be 1- or 2-tuple")
00419                     if len(macro) == 1:
00420                         ext.undef_macros.append(macro[0])
00421                     elif len(macro) == 2:
00422                         ext.define_macros.append(macro)
00423 
00424             extensions[i] = ext

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 136 of file build_ext.py.

00136 
00137     def finalize_options(self):
00138         from distutils import sysconfig
00139 
00140         self.set_undefined_options('build',
00141                                    ('build_lib', 'build_lib'),
00142                                    ('build_temp', 'build_temp'),
00143                                    ('compiler', 'compiler'),
00144                                    ('debug', 'debug'),
00145                                    ('force', 'force'),
00146                                    ('plat_name', 'plat_name'),
00147                                    )
00148 
00149         if self.package is None:
00150             self.package = self.distribution.ext_package
00151 
00152         self.extensions = self.distribution.ext_modules
00153 
00154         # Make sure Python's include directories (for Python.h, pyconfig.h,
00155         # etc.) are in the include search path.
00156         py_include = sysconfig.get_python_inc()
00157         plat_py_include = sysconfig.get_python_inc(plat_specific=1)
00158         if self.include_dirs is None:
00159             self.include_dirs = self.distribution.include_dirs or []
00160         if isinstance(self.include_dirs, str):
00161             self.include_dirs = self.include_dirs.split(os.pathsep)
00162 
00163         # Put the Python "system" include dir at the end, so that
00164         # any local include dirs take precedence.
00165         self.include_dirs.append(py_include)
00166         if plat_py_include != py_include:
00167             self.include_dirs.append(plat_py_include)
00168 
00169         if isinstance(self.libraries, str):
00170             self.libraries = [self.libraries]
00171 
00172         # Life is easier if we're not forever checking for None, so
00173         # simplify these options to empty lists if unset
00174         if self.libraries is None:
00175             self.libraries = []
00176         if self.library_dirs is None:
00177             self.library_dirs = []
00178         elif isinstance(self.library_dirs, str):
00179             self.library_dirs = self.library_dirs.split(os.pathsep)
00180 
00181         if self.rpath is None:
00182             self.rpath = []
00183         elif isinstance(self.rpath, str):
00184             self.rpath = self.rpath.split(os.pathsep)
00185 
00186         # for extensions under windows use different directories
00187         # for Release and Debug builds.
00188         # also Python's library directory must be appended to library_dirs
00189         if os.name == 'nt':
00190             # the 'libs' directory is for binary installs - we assume that
00191             # must be the *native* platform.  But we don't really support
00192             # cross-compiling via a binary install anyway, so we let it go.
00193             self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs'))
00194             if self.debug:
00195                 self.build_temp = os.path.join(self.build_temp, "Debug")
00196             else:
00197                 self.build_temp = os.path.join(self.build_temp, "Release")
00198 
00199             # Append the source distribution include and library directories,
00200             # this allows distutils on windows to work in the source tree
00201             self.include_dirs.append(os.path.join(sys.exec_prefix, 'PC'))
00202             if MSVC_VERSION == 9:
00203                 # Use the .lib files for the correct architecture
00204                 if self.plat_name == 'win32':
00205                     suffix = ''
00206                 else:
00207                     # win-amd64 or win-ia64
00208                     suffix = self.plat_name[4:]
00209                 new_lib = os.path.join(sys.exec_prefix, 'PCbuild')
00210                 if suffix:
00211                     new_lib = os.path.join(new_lib, suffix)
00212                 self.library_dirs.append(new_lib)
00213 
00214             elif MSVC_VERSION == 8:
00215                 self.library_dirs.append(os.path.join(sys.exec_prefix,
00216                                          'PC', 'VS8.0'))
00217             elif MSVC_VERSION == 7:
00218                 self.library_dirs.append(os.path.join(sys.exec_prefix,
00219                                          'PC', 'VS7.1'))
00220             else:
00221                 self.library_dirs.append(os.path.join(sys.exec_prefix,
00222                                          'PC', 'VC6'))
00223 
00224         # OS/2 (EMX) doesn't support Debug vs Release builds, but has the
00225         # import libraries in its "Config" subdirectory
00226         if os.name == 'os2':
00227             self.library_dirs.append(os.path.join(sys.exec_prefix, 'Config'))
00228 
00229         # for extensions under Cygwin and AtheOS Python's library directory must be
00230         # appended to library_dirs
00231         if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos':
00232             if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
00233                 # building third party extensions
00234                 self.library_dirs.append(os.path.join(sys.prefix, "lib",
00235                                                       "python" + get_python_version(),
00236                                                       "config"))
00237             else:
00238                 # building python standard extensions
00239                 self.library_dirs.append('.')
00240 
00241         # for extensions under Linux or Solaris with a shared Python library,
00242         # Python's library directory must be appended to library_dirs
00243         sysconfig.get_config_var('Py_ENABLE_SHARED')
00244         if ((sys.platform.startswith('linux') or sys.platform.startswith('gnu')
00245              or sys.platform.startswith('sunos'))
00246             and sysconfig.get_config_var('Py_ENABLE_SHARED')):
00247             if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
00248                 # building third party extensions
00249                 self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
00250             else:
00251                 # building python standard extensions
00252                 self.library_dirs.append('.')
00253 
00254         # The argument parsing will result in self.define being a string, but
00255         # it has to be a list of 2-tuples.  All the preprocessor symbols
00256         # specified by the 'define' option will be set to '1'.  Multiple
00257         # symbols can be separated with commas.
00258 
00259         if self.define:
00260             defines = self.define.split(',')
00261             self.define = [(symbol, '1') for symbol in defines]
00262 
00263         # The option for macros to undefine is also a string from the
00264         # option parsing, but has to be a list.  Multiple symbols can also
00265         # be separated with commas here.
00266         if self.undef:
00267             self.undef = self.undef.split(',')
00268 
00269         if self.swig_opts is None:
00270             self.swig_opts = []
00271         else:
00272             self.swig_opts = self.swig_opts.split(' ')
00273 
00274         # Finally add the user include and library directories if requested
00275         if self.user:
00276             user_include = os.path.join(USER_BASE, "include")
00277             user_lib = os.path.join(USER_BASE, "lib")
00278             if os.path.isdir(user_include):
00279                 self.include_dirs.append(user_include)
00280             if os.path.isdir(user_lib):
00281                 self.library_dirs.append(user_lib)
00282                 self.rpath.append(user_lib)

Here is the call graph for this function:

Here is the caller graph for this function:

Return the name of the SWIG executable.  On Unix, this is
just "swig" -- it should be in the PATH.  Tries a bit harder on
Windows.

Definition at line 597 of file build_ext.py.

00597 
00598     def find_swig(self):
00599         """Return the name of the SWIG executable.  On Unix, this is
00600         just "swig" -- it should be in the PATH.  Tries a bit harder on
00601         Windows.
00602         """
00603         if os.name == "posix":
00604             return "swig"
00605         elif os.name == "nt":
00606             # Look for SWIG in its standard installation directory on
00607             # Windows (or so I presume!).  If we find it there, great;
00608             # if not, act like Unix and assume it's in the PATH.
00609             for vers in ("1.3", "1.2", "1.1"):
00610                 fn = os.path.join("c:\\swig%s" % vers, "swig.exe")
00611                 if os.path.isfile(fn):
00612                     return fn
00613             else:
00614                 return "swig.exe"
00615         elif os.name == "os2":
00616             # assume swig available in the PATH.
00617             return "swig.exe"
00618         else:
00619             raise DistutilsPlatformError(
00620                   "I don't know how to find (much less run) SWIG "
00621                   "on platform '%s'" % os.name)

Here is the caller graph for this function:

Return the list of symbols that a shared extension has to
export.  This either uses 'ext.export_symbols' or, if it's not
provided, "PyInit_" + module_name.  Only relevant on Windows, where
the .pyd file (DLL) must export the module "PyInit_" function.

Definition at line 676 of file build_ext.py.

00676 
00677     def get_export_symbols(self, ext):
00678         """Return the list of symbols that a shared extension has to
00679         export.  This either uses 'ext.export_symbols' or, if it's not
00680         provided, "PyInit_" + module_name.  Only relevant on Windows, where
00681         the .pyd file (DLL) must export the module "PyInit_" function.
00682         """
00683         initfunc_name = "PyInit_" + ext.name.split('.')[-1]
00684         if initfunc_name not in ext.export_symbols:
00685             ext.export_symbols.append(initfunc_name)
00686         return ext.export_symbols

Definition at line 660 of file build_ext.py.

00660 
00661     def get_ext_filename(self, ext_name):
00662         r"""Convert the name of an extension (eg. "foo.bar") into the name
00663         of the file from which it will be loaded (eg. "foo/bar.so", or
00664         "foo\bar.pyd").
00665         """
00666         from distutils.sysconfig import get_config_var
00667         ext_path = ext_name.split('.')
00668         # OS/2 has an 8 character module (extension) limit :-(
00669         if os.name == "os2":
00670             ext_path[len(ext_path) - 1] = ext_path[len(ext_path) - 1][:8]
00671         # extensions in debug_mode are named 'module_d.pyd' under windows
00672         so_ext = get_config_var('SO')
00673         if os.name == 'nt' and self.debug:
00674             return os.path.join(*ext_path) + '_d' + so_ext
00675         return os.path.join(*ext_path) + so_ext

Here is the call graph for this function:

Here is the caller graph for this function:

Returns the fullname of a given extension name.

Adds the `package.` prefix

Definition at line 651 of file build_ext.py.

00651 
00652     def get_ext_fullname(self, ext_name):
00653         """Returns the fullname of a given extension name.
00654 
00655         Adds the `package.` prefix"""
00656         if self.package is None:
00657             return ext_name
00658         else:
00659             return self.package + '.' + ext_name

Here is the caller graph for this function:

Returns the path of the filename for a given extension.

The file is located in `build_lib` or directly in the package
(inplace option).

Definition at line 624 of file build_ext.py.

00624 
00625     def get_ext_fullpath(self, ext_name):
00626         """Returns the path of the filename for a given extension.
00627 
00628         The file is located in `build_lib` or directly in the package
00629         (inplace option).
00630         """
00631         fullname = self.get_ext_fullname(ext_name)
00632         modpath = fullname.split('.')
00633         filename = self.get_ext_filename(modpath[-1])
00634 
00635         if not self.inplace:
00636             # no further work needed
00637             # returning :
00638             #   build_dir/package/path/filename
00639             filename = os.path.join(*modpath[:-1]+[filename])
00640             return os.path.join(self.build_lib, filename)
00641 
00642         # the inplace option requires to find the package directory
00643         # using the build_py command for that
00644         package = '.'.join(modpath[0:-1])
00645         build_py = self.get_finalized_command('build_py')
00646         package_dir = os.path.abspath(build_py.get_package_dir(package))
00647 
00648         # returning
00649         #   package_dir/filename
00650         return os.path.join(package_dir, filename)

Here is the call graph for this function:

Here is the caller graph for this function:

Return the list of libraries to link against when building a
shared extension.  On most platforms, this is just 'ext.libraries';
on Windows and OS/2, we add the Python library (eg. python20.dll).

Definition at line 687 of file build_ext.py.

00687 
00688     def get_libraries(self, ext):
00689         """Return the list of libraries to link against when building a
00690         shared extension.  On most platforms, this is just 'ext.libraries';
00691         on Windows and OS/2, we add the Python library (eg. python20.dll).
00692         """
00693         # The python library is always needed on Windows.  For MSVC, this
00694         # is redundant, since the library is mentioned in a pragma in
00695         # pyconfig.h that MSVC groks.  The other Windows compilers all seem
00696         # to need it mentioned explicitly, though, so that's what we do.
00697         # Append '_d' to the python import library on debug builds.
00698         if sys.platform == "win32":
00699             from distutils.msvccompiler import MSVCCompiler
00700             if not isinstance(self.compiler, MSVCCompiler):
00701                 template = "python%d%d"
00702                 if self.debug:
00703                     template = template + '_d'
00704                 pythonlib = (template %
00705                        (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
00706                 # don't extend ext.libraries, it may be shared with other
00707                 # extensions, it is a reference to the original list
00708                 return ext.libraries + [pythonlib]
00709             else:
00710                 return ext.libraries
00711         elif sys.platform == "os2emx":
00712             # EMX/GCC requires the python library explicitly, and I
00713             # believe VACPP does as well (though not confirmed) - AIM Apr01
00714             template = "python%d%d"
00715             # debug versions of the main DLL aren't supported, at least
00716             # not at this time - AIM Apr01
00717             #if self.debug:
00718             #    template = template + '_d'
00719             pythonlib = (template %
00720                    (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
00721             # don't extend ext.libraries, it may be shared with other
00722             # extensions, it is a reference to the original list
00723             return ext.libraries + [pythonlib]
00724         elif sys.platform[:6] == "cygwin":
00725             template = "python%d.%d"
00726             pythonlib = (template %
00727                    (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
00728             # don't extend ext.libraries, it may be shared with other
00729             # extensions, it is a reference to the original list
00730             return ext.libraries + [pythonlib]
00731         elif sys.platform[:6] == "atheos":
00732             from distutils import sysconfig
00733 
00734             template = "python%d.%d"
00735             pythonlib = (template %
00736                    (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
00737             # Get SHLIBS from Makefile
00738             extra = []
00739             for lib in sysconfig.get_config_var('SHLIBS').split():
00740                 if lib.startswith('-l'):
00741                     extra.append(lib[2:])
00742                 else:
00743                     extra.append(lib)
00744             # don't extend ext.libraries, it may be shared with other
00745             # extensions, it is a reference to the original list
00746             return ext.libraries + [pythonlib, "m"] + extra
00747         elif sys.platform == 'darwin':
00748             # Don't use the default code below
00749             return ext.libraries
00750         elif sys.platform[:3] == 'aix':
00751             # Don't use the default code below
00752             return ext.libraries
00753         else:
00754             from distutils import sysconfig
00755             if sysconfig.get_config_var('Py_ENABLE_SHARED'):
00756                 pythonlib = 'python{}.{}{}'.format(
00757                     sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff,
00758                     sys.abiflags)
00759                 return ext.libraries + [pythonlib]
00760             else:
00761                 return ext.libraries

Here is the call graph for this function:

Definition at line 434 of file build_ext.py.

00434 
00435     def get_outputs(self):
00436         # Sanity check the 'extensions' list -- can't assume this is being
00437         # done in the same run as a 'build_extensions()' call (in fact, we
00438         # can probably assume that it *isn't*!).
00439         self.check_extensions_list(self.extensions)
00440 
00441         # And build the list of output (built) filenames.  Note that this
00442         # ignores the 'inplace' flag, and assumes everything goes in the
00443         # "build" tree.
00444         outputs = []
00445         for ext in self.extensions:
00446             outputs.append(self.get_ext_fullpath(ext.name))
00447         return outputs

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 425 of file build_ext.py.

00425 
00426     def get_source_files(self):
00427         self.check_extensions_list(self.extensions)
00428         filenames = []
00429 
00430         # Wouldn't it be neat if we knew the names of header files too...
00431         for ext in self.extensions:
00432             filenames.extend(ext.sources)
00433         return filenames

Here is the call graph for this function:

Definition at line 113 of file build_ext.py.

00113 
00114     def initialize_options(self):
00115         self.extensions = None
00116         self.build_lib = None
00117         self.plat_name = None
00118         self.build_temp = None
00119         self.inplace = 0
00120         self.package = None
00121 
00122         self.include_dirs = None
00123         self.define = None
00124         self.undef = None
00125         self.libraries = None
00126         self.library_dirs = None
00127         self.rpath = None
00128         self.link_objects = None
00129         self.debug = None
00130         self.force = None
00131         self.compiler = None
00132         self.swig = None
00133         self.swig_cpp = None
00134         self.swig_opts = None
00135         self.user = None

Definition at line 283 of file build_ext.py.

00283 
00284     def run(self):
00285         from distutils.ccompiler import new_compiler
00286 
00287         # 'self.extensions', as supplied by setup.py, is a list of
00288         # Extension instances.  See the documentation for Extension (in
00289         # distutils.extension) for details.
00290         #
00291         # For backwards compatibility with Distutils 0.8.2 and earlier, we
00292         # also allow the 'extensions' list to be a list of tuples:
00293         #    (ext_name, build_info)
00294         # where build_info is a dictionary containing everything that
00295         # Extension instances do except the name, with a few things being
00296         # differently named.  We convert these 2-tuples to Extension
00297         # instances as needed.
00298 
00299         if not self.extensions:
00300             return
00301 
00302         # If we were asked to build any C/C++ libraries, make sure that the
00303         # directory where we put them is in the library search path for
00304         # linking extensions.
00305         if self.distribution.has_c_libraries():
00306             build_clib = self.get_finalized_command('build_clib')
00307             self.libraries.extend(build_clib.get_library_names() or [])
00308             self.library_dirs.append(build_clib.build_clib)
00309 
00310         # Setup the CCompiler object that we'll use to do all the
00311         # compiling and linking
00312         self.compiler = new_compiler(compiler=self.compiler,
00313                                      verbose=self.verbose,
00314                                      dry_run=self.dry_run,
00315                                      force=self.force)
00316         customize_compiler(self.compiler)
00317         # If we are cross-compiling, init the compiler now (if we are not
00318         # cross-compiling, init would not hurt, but people may rely on
00319         # late initialization of compiler even if they shouldn't...)
00320         if os.name == 'nt' and self.plat_name != get_platform():
00321             self.compiler.initialize(self.plat_name)
00322 
00323         # And make sure that any compile/link-related options (which might
00324         # come from the command-line or from the setup script) are set in
00325         # that CCompiler object -- that way, they automatically apply to
00326         # all compiling and linking done here.
00327         if self.include_dirs is not None:
00328             self.compiler.set_include_dirs(self.include_dirs)
00329         if self.define is not None:
00330             # 'define' option is a list of (name,value) tuples
00331             for (name, value) in self.define:
00332                 self.compiler.define_macro(name, value)
00333         if self.undef is not None:
00334             for macro in self.undef:
00335                 self.compiler.undefine_macro(macro)
00336         if self.libraries is not None:
00337             self.compiler.set_libraries(self.libraries)
00338         if self.library_dirs is not None:
00339             self.compiler.set_library_dirs(self.library_dirs)
00340         if self.rpath is not None:
00341             self.compiler.set_runtime_library_dirs(self.rpath)
00342         if self.link_objects is not None:
00343             self.compiler.set_link_objects(self.link_objects)
00344 
00345         # Now actually compile and link everything.
00346         self.build_extensions()

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.command.build_ext.build_ext.swig_sources (   self,
  sources,
  extension 
)
Walk the list of source files in 'sources', looking for SWIG
interface (.i) files.  Run SWIG on all that are found, and
return a modified 'sources' list with SWIG source files replaced
by the generated C (or C++) files.

Definition at line 543 of file build_ext.py.

00543 
00544     def swig_sources(self, sources, extension):
00545         """Walk the list of source files in 'sources', looking for SWIG
00546         interface (.i) files.  Run SWIG on all that are found, and
00547         return a modified 'sources' list with SWIG source files replaced
00548         by the generated C (or C++) files.
00549         """
00550         new_sources = []
00551         swig_sources = []
00552         swig_targets = {}
00553 
00554         # XXX this drops generated C/C++ files into the source tree, which
00555         # is fine for developers who want to distribute the generated
00556         # source -- but there should be an option to put SWIG output in
00557         # the temp dir.
00558 
00559         if self.swig_cpp:
00560             log.warn("--swig-cpp is deprecated - use --swig-opts=-c++")
00561 
00562         if self.swig_cpp or ('-c++' in self.swig_opts) or \
00563            ('-c++' in extension.swig_opts):
00564             target_ext = '.cpp'
00565         else:
00566             target_ext = '.c'
00567 
00568         for source in sources:
00569             (base, ext) = os.path.splitext(source)
00570             if ext == ".i":             # SWIG interface file
00571                 new_sources.append(base + '_wrap' + target_ext)
00572                 swig_sources.append(source)
00573                 swig_targets[source] = new_sources[-1]
00574             else:
00575                 new_sources.append(source)
00576 
00577         if not swig_sources:
00578             return new_sources
00579 
00580         swig = self.swig or self.find_swig()
00581         swig_cmd = [swig, "-python"]
00582         swig_cmd.extend(self.swig_opts)
00583         if self.swig_cpp:
00584             swig_cmd.append("-c++")
00585 
00586         # Do not override commandline arguments
00587         if not self.swig_opts:
00588             for o in extension.swig_opts:
00589                 swig_cmd.append(o)
00590 
00591         for source in swig_sources:
00592             target = swig_targets[source]
00593             log.info("swigging %s to %s", source, target)
00594             self.spawn(swig_cmd + ["-o", target, source])
00595 
00596         return new_sources

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 520 of file build_ext.py.

Definition at line 101 of file build_ext.py.

Definition at line 115 of file build_ext.py.

Definition at line 117 of file build_ext.py.

Definition at line 130 of file build_ext.py.

Definition at line 128 of file build_ext.py.

Definition at line 122 of file build_ext.py.

string distutils.command.build_ext.build_ext.description = "build C/C++ extensions (compile/link to build directory)" [static]

Definition at line 41 of file build_ext.py.

Reimplemented in setup.PyBuildExt.

Definition at line 114 of file build_ext.py.

Definition at line 129 of file build_ext.py.

Initial value:
[
        ('help-compiler', None,
         "list available compilers", show_compilers),
        ]

Definition at line 108 of file build_ext.py.

Definition at line 121 of file build_ext.py.

Definition at line 118 of file build_ext.py.

Definition at line 124 of file build_ext.py.

Definition at line 125 of file build_ext.py.

Definition at line 127 of file build_ext.py.

Definition at line 119 of file build_ext.py.

Definition at line 116 of file build_ext.py.

Definition at line 126 of file build_ext.py.

string distutils.command.build_ext.build_ext.sep_by = " (separated by '%s')" [static]

Definition at line 61 of file build_ext.py.

Definition at line 131 of file build_ext.py.

Definition at line 132 of file build_ext.py.

Definition at line 133 of file build_ext.py.

Definition at line 123 of file build_ext.py.

Definition at line 134 of file build_ext.py.

Definition at line 62 of file build_ext.py.


The documentation for this class was generated from the following file: