Back to index

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

List of all members.

Public Member Functions

def initialize_options
def finalize_options
def run
def try_cpp
def search_cpp
def try_compile
def try_link
def try_run
def check_func
def check_lib
def check_header

Public Attributes

 compiler
 cc
 include_dirs
 libraries
 library_dirs
 noisy
 dump_source
 temp_files

Static Public Attributes

string description = "prepare to build"
list user_options

Private Member Functions

def _check_compiler
def _gen_temp_sourcefile
def _preprocess
def _compile
def _link
def _clean

Detailed Description

Definition at line 21 of file config.py.


Member Function Documentation

def distutils.command.config.config._check_compiler (   self) [private]
Check that 'self.compiler' really is a CCompiler object;
if not, make it one.

Definition at line 89 of file config.py.

00089 
00090     def _check_compiler(self):
00091         """Check that 'self.compiler' really is a CCompiler object;
00092         if not, make it one.
00093         """
00094         # We do this late, and only on-demand, because this is an expensive
00095         # import.
00096         from distutils.ccompiler import CCompiler, new_compiler
00097         if not isinstance(self.compiler, CCompiler):
00098             self.compiler = new_compiler(compiler=self.compiler,
00099                                          dry_run=self.dry_run, force=1)
00100             customize_compiler(self.compiler)
00101             if self.include_dirs:
00102                 self.compiler.set_include_dirs(self.include_dirs)
00103             if self.libraries:
00104                 self.compiler.set_libraries(self.libraries)
00105             if self.library_dirs:
00106                 self.compiler.set_library_dirs(self.library_dirs)

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.command.config.config._clean (   self,
  filenames 
) [private]

Definition at line 151 of file config.py.

00151 
00152     def _clean(self, *filenames):
00153         if not filenames:
00154             filenames = self.temp_files
00155             self.temp_files = []
00156         log.info("removing: %s", ' '.join(filenames))
00157         for filename in filenames:
00158             try:
00159                 os.remove(filename)
00160             except OSError:
00161                 pass
00162 

Here is the caller graph for this function:

def distutils.command.config.config._compile (   self,
  body,
  headers,
  include_dirs,
  lang 
) [private]

Definition at line 127 of file config.py.

00127 
00128     def _compile(self, body, headers, include_dirs, lang):
00129         src = self._gen_temp_sourcefile(body, headers, lang)
00130         if self.dump_source:
00131             dump_file(src, "compiling '%s':" % src)
00132         (obj,) = self.compiler.object_filenames([src])
00133         self.temp_files.extend([src, obj])
00134         self.compiler.compile([src], include_dirs=include_dirs)
00135         return (src, obj)

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.command.config.config._gen_temp_sourcefile (   self,
  body,
  headers,
  lang 
) [private]

Definition at line 107 of file config.py.

00107 
00108     def _gen_temp_sourcefile(self, body, headers, lang):
00109         filename = "_configtest" + LANG_EXT[lang]
00110         file = open(filename, "w")
00111         if headers:
00112             for header in headers:
00113                 file.write("#include <%s>\n" % header)
00114             file.write("\n")
00115         file.write(body)
00116         if body[-1] != "\n":
00117             file.write("\n")
00118         file.close()
00119         return filename

Here is the caller graph for this function:

def distutils.command.config.config._link (   self,
  body,
  headers,
  include_dirs,
  libraries,
  library_dirs,
  lang 
) [private]

Definition at line 137 of file config.py.

00137 
00138               lang):
00139         (src, obj) = self._compile(body, headers, include_dirs, lang)
00140         prog = os.path.splitext(os.path.basename(src))[0]
00141         self.compiler.link_executable([obj], prog,
00142                                       libraries=libraries,
00143                                       library_dirs=library_dirs,
00144                                       target_lang=lang)
00145 
00146         if self.compiler.exe_extension is not None:
00147             prog = prog + self.compiler.exe_extension
00148         self.temp_files.append(prog)
00149 
00150         return (src, obj, prog)

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.command.config.config._preprocess (   self,
  body,
  headers,
  include_dirs,
  lang 
) [private]

Definition at line 120 of file config.py.

00120 
00121     def _preprocess(self, body, headers, include_dirs, lang):
00122         src = self._gen_temp_sourcefile(body, headers, lang)
00123         out = "_configtest.i"
00124         self.temp_files.extend([src, out])
00125         self.compiler.preprocess(src, out, include_dirs=include_dirs)
00126         return (src, out)

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.command.config.config.check_func (   self,
  func,
  headers = None,
  include_dirs = None,
  libraries = None,
  library_dirs = None,
  decl = 0,
  call = 0 
)
Determine if function 'func' is available by constructing a
source file that refers to 'func', and compiles and links it.
If everything succeeds, returns true; otherwise returns false.

The constructed source file starts out by including the header
files listed in 'headers'.  If 'decl' is true, it then declares
'func' (as "int func()"); you probably shouldn't supply 'headers'
and set 'decl' true in the same call, or you might get errors about
a conflicting declarations for 'func'.  Finally, the constructed
'main()' function either references 'func' or (if 'call' is true)
calls it.  'libraries' and 'library_dirs' are used when
linking.

Definition at line 281 of file config.py.

00281 
00282                    libraries=None, library_dirs=None, decl=0, call=0):
00283         """Determine if function 'func' is available by constructing a
00284         source file that refers to 'func', and compiles and links it.
00285         If everything succeeds, returns true; otherwise returns false.
00286 
00287         The constructed source file starts out by including the header
00288         files listed in 'headers'.  If 'decl' is true, it then declares
00289         'func' (as "int func()"); you probably shouldn't supply 'headers'
00290         and set 'decl' true in the same call, or you might get errors about
00291         a conflicting declarations for 'func'.  Finally, the constructed
00292         'main()' function either references 'func' or (if 'call' is true)
00293         calls it.  'libraries' and 'library_dirs' are used when
00294         linking.
00295         """
00296         self._check_compiler()
00297         body = []
00298         if decl:
00299             body.append("int %s ();" % func)
00300         body.append("int main () {")
00301         if call:
00302             body.append("  %s();" % func)
00303         else:
00304             body.append("  %s;" % func)
00305         body.append("}")
00306         body = "\n".join(body) + "\n"
00307 
00308         return self.try_link(body, headers, include_dirs,
00309                              libraries, library_dirs)

Here is the call graph for this function:

def distutils.command.config.config.check_header (   self,
  header,
  include_dirs = None,
  library_dirs = None,
  lang = "c" 
)
Determine if the system header file named by 'header_file'
exists and can be found by the preprocessor; return true if so,
false otherwise.

Definition at line 325 of file config.py.

00325 
00326                      lang="c"):
00327         """Determine if the system header file named by 'header_file'
00328         exists and can be found by the preprocessor; return true if so,
00329         false otherwise.
00330         """
00331         return self.try_cpp(body="/* No body */", headers=[header],
00332                             include_dirs=include_dirs)
00333 

Here is the call graph for this function:

def distutils.command.config.config.check_lib (   self,
  library,
  library_dirs = None,
  headers = None,
  include_dirs = None,
  other_libraries = [] 
)
Determine if 'library' is available to be linked against,
without actually checking that any particular symbols are provided
by it.  'headers' will be used in constructing the source file to
be compiled, but the only effect of this is to check if all the
header files listed are available.  Any libraries listed in
'other_libraries' will be included in the link, in case 'library'
has symbols that depend on other libraries.

Definition at line 311 of file config.py.

00311 
00312                   include_dirs=None, other_libraries=[]):
00313         """Determine if 'library' is available to be linked against,
00314         without actually checking that any particular symbols are provided
00315         by it.  'headers' will be used in constructing the source file to
00316         be compiled, but the only effect of this is to check if all the
00317         header files listed are available.  Any libraries listed in
00318         'other_libraries' will be included in the link, in case 'library'
00319         has symbols that depend on other libraries.
00320         """
00321         self._check_compiler()
00322         return self.try_link("int main (void) { }", headers, include_dirs,
00323                              [library] + other_libraries, library_dirs)

Here is the call graph for this function:

def distutils.command.config.config.finalize_options (   self)

Definition at line 66 of file config.py.

00066 
00067     def finalize_options(self):
00068         if self.include_dirs is None:
00069             self.include_dirs = self.distribution.include_dirs or []
00070         elif isinstance(self.include_dirs, str):
00071             self.include_dirs = self.include_dirs.split(os.pathsep)
00072 
00073         if self.libraries is None:
00074             self.libraries = []
00075         elif isinstance(self.libraries, str):
00076             self.libraries = [self.libraries]
00077 
00078         if self.library_dirs is None:
00079             self.library_dirs = []
00080         elif isinstance(self.library_dirs, str):
00081             self.library_dirs = self.library_dirs.split(os.pathsep)

Here is the caller graph for this function:

def distutils.command.config.config.initialize_options (   self)

Definition at line 51 of file config.py.

00051 
00052     def initialize_options(self):
00053         self.compiler = None
00054         self.cc = None
00055         self.include_dirs = None
00056         self.libraries = None
00057         self.library_dirs = None
00058 
00059         # maximal output for now
00060         self.noisy = 1
00061         self.dump_source = 1
00062 
00063         # list of temporary files generated along-the-way that we have
00064         # to clean at some point
00065         self.temp_files = []

def distutils.command.config.config.run (   self)

Definition at line 82 of file config.py.

00082 
00083     def run(self):
00084         pass

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.command.config.config.search_cpp (   self,
  pattern,
  body = None,
  headers = None,
  include_dirs = None,
  lang = "c" 
)
Construct a source file (just like 'try_cpp()'), run it through
the preprocessor, and return true if any line of the output matches
'pattern'.  'pattern' should either be a compiled regex object or a
string containing a regex.  If both 'body' and 'headers' are None,
preprocesses an empty file -- which can be useful to determine the
symbols the preprocessor and compiler set by default.

Definition at line 192 of file config.py.

00192 
00193                    lang="c"):
00194         """Construct a source file (just like 'try_cpp()'), run it through
00195         the preprocessor, and return true if any line of the output matches
00196         'pattern'.  'pattern' should either be a compiled regex object or a
00197         string containing a regex.  If both 'body' and 'headers' are None,
00198         preprocesses an empty file -- which can be useful to determine the
00199         symbols the preprocessor and compiler set by default.
00200         """
00201         self._check_compiler()
00202         src, out = self._preprocess(body, headers, include_dirs, lang)
00203 
00204         if isinstance(pattern, str):
00205             pattern = re.compile(pattern)
00206 
00207         file = open(out)
00208         match = False
00209         while True:
00210             line = file.readline()
00211             if line == '':
00212                 break
00213             if pattern.search(line):
00214                 match = True
00215                 break
00216 
00217         file.close()
00218         self._clean()
00219         return match

Here is the call graph for this function:

def distutils.command.config.config.try_compile (   self,
  body,
  headers = None,
  include_dirs = None,
  lang = "c" 
)
Try to compile a source file built from 'body' and 'headers'.
Return true on success, false otherwise.

Definition at line 220 of file config.py.

00220 
00221     def try_compile(self, body, headers=None, include_dirs=None, lang="c"):
00222         """Try to compile a source file built from 'body' and 'headers'.
00223         Return true on success, false otherwise.
00224         """
00225         from distutils.ccompiler import CompileError
00226         self._check_compiler()
00227         try:
00228             self._compile(body, headers, include_dirs, lang)
00229             ok = True
00230         except CompileError:
00231             ok = False
00232 
00233         log.info(ok and "success!" or "failure.")
00234         self._clean()
00235         return ok

Here is the call graph for this function:

def distutils.command.config.config.try_cpp (   self,
  body = None,
  headers = None,
  include_dirs = None,
  lang = "c" 
)
Construct a source file from 'body' (a string containing lines
of C/C++ code) and 'headers' (a list of header files to include)
and run it through the preprocessor.  Return true if the
preprocessor succeeded, false if there were any errors.
('body' probably isn't of much use, but what the heck.)

Definition at line 173 of file config.py.

00173 
00174     def try_cpp(self, body=None, headers=None, include_dirs=None, lang="c"):
00175         """Construct a source file from 'body' (a string containing lines
00176         of C/C++ code) and 'headers' (a list of header files to include)
00177         and run it through the preprocessor.  Return true if the
00178         preprocessor succeeded, false if there were any errors.
00179         ('body' probably isn't of much use, but what the heck.)
00180         """
00181         from distutils.ccompiler import CompileError
00182         self._check_compiler()
00183         ok = True
00184         try:
00185             self._preprocess(body, headers, include_dirs, lang)
00186         except CompileError:
00187             ok = False
00188 
00189         self._clean()
00190         return ok

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.command.config.config.try_link (   self,
  body,
  headers = None,
  include_dirs = None,
  libraries = None,
  library_dirs = None,
  lang = "c" 
)
Try to compile and link a source file, built from 'body' and
'headers', to executable form.  Return true on success, false
otherwise.

Definition at line 237 of file config.py.

00237 
00238                  library_dirs=None, lang="c"):
00239         """Try to compile and link a source file, built from 'body' and
00240         'headers', to executable form.  Return true on success, false
00241         otherwise.
00242         """
00243         from distutils.ccompiler import CompileError, LinkError
00244         self._check_compiler()
00245         try:
00246             self._link(body, headers, include_dirs,
00247                        libraries, library_dirs, lang)
00248             ok = True
00249         except (CompileError, LinkError):
00250             ok = False
00251 
00252         log.info(ok and "success!" or "failure.")
00253         self._clean()
00254         return ok

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.command.config.config.try_run (   self,
  body,
  headers = None,
  include_dirs = None,
  libraries = None,
  library_dirs = None,
  lang = "c" 
)
Try to compile, link to an executable, and run a program
built from 'body' and 'headers'.  Return true on success, false
otherwise.

Definition at line 256 of file config.py.

00256 
00257                 library_dirs=None, lang="c"):
00258         """Try to compile, link to an executable, and run a program
00259         built from 'body' and 'headers'.  Return true on success, false
00260         otherwise.
00261         """
00262         from distutils.ccompiler import CompileError, LinkError
00263         self._check_compiler()
00264         try:
00265             src, obj, exe = self._link(body, headers, include_dirs,
00266                                        libraries, library_dirs, lang)
00267             self.spawn([exe])
00268             ok = True
00269         except (CompileError, LinkError, DistutilsExecError):
00270             ok = False
00271 
00272         log.info(ok and "success!" or "failure.")
00273         self._clean()
00274         return ok
00275 

Here is the call graph for this function:


Member Data Documentation

distutils.command.config.config.cc

Definition at line 53 of file config.py.

distutils.command.config.config.compiler

Definition at line 52 of file config.py.

string distutils.command.config.config.description = "prepare to build" [static]

Definition at line 23 of file config.py.

distutils.command.config.config.dump_source

Definition at line 60 of file config.py.

distutils.command.config.config.include_dirs

Definition at line 54 of file config.py.

distutils.command.config.config.libraries

Definition at line 55 of file config.py.

distutils.command.config.config.library_dirs

Definition at line 56 of file config.py.

distutils.command.config.config.noisy

Definition at line 59 of file config.py.

distutils.command.config.config.temp_files

Definition at line 64 of file config.py.

list distutils.command.config.config.user_options [static]
Initial value:
[
        ('compiler=', None,
         "specify the compiler type"),
        ('cc=', None,
         "specify the compiler executable"),
        ('include-dirs=', 'I',
         "list of directories to search for header files"),
        ('define=', 'D',
         "C preprocessor macros to define"),
        ('undef=', 'U',
         "C preprocessor macros to undefine"),
        ('libraries=', 'l',
         "external C libraries to link with"),
        ('library-dirs=', 'L',
         "directories to search for external C libraries"),

        ('noisy', None,
         "show every action (compile, link, run, ...) taken"),
        ('dump-source', None,
         "dump generated source files before attempting to compile them"),
        ]

Definition at line 25 of file config.py.


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