Back to index

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

List of all members.

Public Member Functions

def initialize_options
def finalize_options
def run
def check_library_list
def get_library_names
def get_source_files
def build_libraries

Public Attributes

 build_clib
 build_temp
 libraries
 include_dirs
 define
 undef
 debug
 force
 compiler

Static Public Attributes

string description = "build C/C++ libraries used by Python extensions"
list user_options
list boolean_options = ['debug', 'force']
list help_options

Detailed Description

Definition at line 28 of file build_clib.py.


Member Function Documentation

Definition at line 181 of file build_clib.py.

00181 
00182     def build_libraries(self, libraries):
00183         for (lib_name, build_info) in libraries:
00184             sources = build_info.get('sources')
00185             if sources is None or not isinstance(sources, (list, tuple)):
00186                 raise DistutilsSetupError(
00187                        "in 'libraries' option (library '%s'), "
00188                        "'sources' must be present and must be "
00189                        "a list of source filenames" % lib_name)
00190             sources = list(sources)
00191 
00192             log.info("building '%s' library", lib_name)
00193 
00194             # First, compile the source code to object files in the library
00195             # directory.  (This should probably change to putting object
00196             # files in a temporary build directory.)
00197             macros = build_info.get('macros')
00198             include_dirs = build_info.get('include_dirs')
00199             objects = self.compiler.compile(sources,
00200                                             output_dir=self.build_temp,
00201                                             macros=macros,
00202                                             include_dirs=include_dirs,
00203                                             debug=self.debug)
00204 
00205             # Now "link" the object files together into a static library.
00206             # (On Unix at least, this isn't really linking -- it just
00207             # builds an archive.  Whatever.)
00208             self.compiler.create_static_lib(objects, lib_name,
00209                                             output_dir=self.build_clib,
00210                                             debug=self.debug)

Here is the caller graph for this function:

Ensure that the list of libraries is valid.

`library` is presumably provided as a command option 'libraries'.
This method checks that it is a list of 2-tuples, where the tuples
are (library_name, build_info_dict).

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

Definition at line 118 of file build_clib.py.

00118 
00119     def check_library_list(self, libraries):
00120         """Ensure that the list of libraries is valid.
00121 
00122         `library` is presumably provided as a command option 'libraries'.
00123         This method checks that it is a list of 2-tuples, where the tuples
00124         are (library_name, build_info_dict).
00125 
00126         Raise DistutilsSetupError if the structure is invalid anywhere;
00127         just returns otherwise.
00128         """
00129         if not isinstance(libraries, list):
00130             raise DistutilsSetupError(
00131                   "'libraries' option must be a list of tuples")
00132 
00133         for lib in libraries:
00134             if not isinstance(lib, tuple) and len(lib) != 2:
00135                 raise DistutilsSetupError(
00136                       "each element of 'libraries' must a 2-tuple")
00137 
00138             name, build_info = lib
00139 
00140             if not isinstance(name, str):
00141                 raise DistutilsSetupError(
00142                       "first element of each tuple in 'libraries' "
00143                       "must be a string (the library name)")
00144 
00145             if '/' in name or (os.sep != '/' and os.sep in name):
00146                 raise DistutilsSetupError("bad library name '%s': "
00147                        "may not contain directory separators" % lib[0])
00148 
00149             if not isinstance(build_info, dict):
00150                 raise DistutilsSetupError(
00151                       "second element of each tuple in 'libraries' "
00152                       "must be a dictionary (build info)")
00153 

Here is the caller graph for this function:

Definition at line 68 of file build_clib.py.

00068 
00069     def finalize_options(self):
00070         # This might be confusing: both build-clib and build-temp default
00071         # to build-temp as defined by the "build" command.  This is because
00072         # I think that C libraries are really just temporary build
00073         # by-products, at least from the point of view of building Python
00074         # extensions -- but I want to keep my options open.
00075         self.set_undefined_options('build',
00076                                    ('build_temp', 'build_clib'),
00077                                    ('build_temp', 'build_temp'),
00078                                    ('compiler', 'compiler'),
00079                                    ('debug', 'debug'),
00080                                    ('force', 'force'))
00081 
00082         self.libraries = self.distribution.libraries
00083         if self.libraries:
00084             self.check_library_list(self.libraries)
00085 
00086         if self.include_dirs is None:
00087             self.include_dirs = self.distribution.include_dirs or []
00088         if isinstance(self.include_dirs, str):
00089             self.include_dirs = self.include_dirs.split(os.pathsep)
00090 
00091         # XXX same as for build_ext -- what about 'self.define' and
00092         # 'self.undef' ?
00093 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 154 of file build_clib.py.

00154 
00155     def get_library_names(self):
00156         # Assume the library list is valid -- 'check_library_list()' is
00157         # called from 'finalize_options()', so it should be!
00158         if not self.libraries:
00159             return None
00160 
00161         lib_names = []
00162         for (lib_name, build_info) in self.libraries:
00163             lib_names.append(lib_name)
00164         return lib_names
00165 

Definition at line 166 of file build_clib.py.

00166 
00167     def get_source_files(self):
00168         self.check_library_list(self.libraries)
00169         filenames = []
00170         for (lib_name, build_info) in self.libraries:
00171             sources = build_info.get('sources')
00172             if sources is None or not isinstance(sources, (list, tuple)):
00173                 raise DistutilsSetupError(
00174                        "in 'libraries' option (library '%s'), "
00175                        "'sources' must be present and must be "
00176                        "a list of source filenames" % lib_name)
00177 
00178             filenames.extend(sources)
00179         return filenames
00180 

Here is the call graph for this function:

Definition at line 52 of file build_clib.py.

00052 
00053     def initialize_options(self):
00054         self.build_clib = None
00055         self.build_temp = None
00056 
00057         # List of libraries to build
00058         self.libraries = None
00059 
00060         # Compilation options for all libraries
00061         self.include_dirs = None
00062         self.define = None
00063         self.undef = None
00064         self.debug = None
00065         self.force = 0
00066         self.compiler = None
00067 

Definition at line 94 of file build_clib.py.

00094 
00095     def run(self):
00096         if not self.libraries:
00097             return
00098 
00099         # Yech -- this is cut 'n pasted from build_ext.py!
00100         from distutils.ccompiler import new_compiler
00101         self.compiler = new_compiler(compiler=self.compiler,
00102                                      dry_run=self.dry_run,
00103                                      force=self.force)
00104         customize_compiler(self.compiler)
00105 
00106         if self.include_dirs is not None:
00107             self.compiler.set_include_dirs(self.include_dirs)
00108         if self.define is not None:
00109             # 'define' option is a list of (name,value) tuples
00110             for (name,value) in self.define:
00111                 self.compiler.define_macro(name, value)
00112         if self.undef is not None:
00113             for macro in self.undef:
00114                 self.compiler.undefine_macro(macro)
00115 
00116         self.build_libraries(self.libraries)
00117 

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 45 of file build_clib.py.

Definition at line 53 of file build_clib.py.

Definition at line 54 of file build_clib.py.

Definition at line 65 of file build_clib.py.

Definition at line 63 of file build_clib.py.

Definition at line 61 of file build_clib.py.

Definition at line 30 of file build_clib.py.

Definition at line 64 of file build_clib.py.

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

Definition at line 47 of file build_clib.py.

Definition at line 60 of file build_clib.py.

Definition at line 57 of file build_clib.py.

Definition at line 62 of file build_clib.py.

Initial value:
[
        ('build-clib=', 'b',
         "directory to build C/C++ libraries to"),
        ('build-temp=', 't',
         "directory to put temporary build by-products"),
        ('debug', 'g',
         "compile with debugging information"),
        ('force', 'f',
         "forcibly build everything (ignore file timestamps)"),
        ('compiler=', 'c',
         "specify the compiler type"),
        ]

Definition at line 32 of file build_clib.py.


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