Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/distutils/command/config.py

    r2 r391  
    1010"""
    1111
    12 # This module should be kept compatible with Python 2.1.
    13 
    14 __revision__ = "$Id: config.py 37828 2004-11-10 22:23:15Z loewis $"
    15 
    16 import sys, os, string, re
    17 from types import *
     12__revision__ = "$Id$"
     13
     14import os
     15import re
     16
    1817from distutils.core import Command
    1918from distutils.errors import DistutilsExecError
     
    2120from distutils import log
    2221
    23 LANG_EXT = {'c': '.c',
    24             'c++': '.cxx'}
    25 
    26 class config (Command):
     22LANG_EXT = {'c': '.c', 'c++': '.cxx'}
     23
     24class config(Command):
    2725
    2826    description = "prepare to build"
     
    5452    # does nothing by default, these are empty.
    5553
    56     def initialize_options (self):
     54    def initialize_options(self):
    5755        self.compiler = None
    5856        self.cc = None
    5957        self.include_dirs = None
    60         #self.define = None
    61         #self.undef = None
    6258        self.libraries = None
    6359        self.library_dirs = None
     
    7167        self.temp_files = []
    7268
    73     def finalize_options (self):
     69    def finalize_options(self):
    7470        if self.include_dirs is None:
    7571            self.include_dirs = self.distribution.include_dirs or []
    76         elif type(self.include_dirs) is StringType:
    77             self.include_dirs = string.split(self.include_dirs, os.pathsep)
     72        elif isinstance(self.include_dirs, str):
     73            self.include_dirs = self.include_dirs.split(os.pathsep)
    7874
    7975        if self.libraries is None:
    8076            self.libraries = []
    81         elif type(self.libraries) is StringType:
     77        elif isinstance(self.libraries, str):
    8278            self.libraries = [self.libraries]
    8379
    8480        if self.library_dirs is None:
    8581            self.library_dirs = []
    86         elif type(self.library_dirs) is StringType:
    87             self.library_dirs = string.split(self.library_dirs, os.pathsep)
    88 
    89 
    90     def run (self):
     82        elif isinstance(self.library_dirs, str):
     83            self.library_dirs = self.library_dirs.split(os.pathsep)
     84
     85    def run(self):
    9186        pass
    9287
     
    9691    # may use these freely.
    9792
    98     def _check_compiler (self):
     93    def _check_compiler(self):
    9994        """Check that 'self.compiler' really is a CCompiler object;
    10095        if not, make it one.
     
    115110
    116111
    117     def _gen_temp_sourcefile (self, body, headers, lang):
     112    def _gen_temp_sourcefile(self, body, headers, lang):
    118113        filename = "_configtest" + LANG_EXT[lang]
    119114        file = open(filename, "w")
     
    128123        return filename
    129124
    130     def _preprocess (self, body, headers, include_dirs, lang):
     125    def _preprocess(self, body, headers, include_dirs, lang):
    131126        src = self._gen_temp_sourcefile(body, headers, lang)
    132127        out = "_configtest.i"
     
    135130        return (src, out)
    136131
    137     def _compile (self, body, headers, include_dirs, lang):
     132    def _compile(self, body, headers, include_dirs, lang):
    138133        src = self._gen_temp_sourcefile(body, headers, lang)
    139134        if self.dump_source:
     
    144139        return (src, obj)
    145140
    146     def _link (self, body,
    147                headers, include_dirs,
    148                libraries, library_dirs, lang):
     141    def _link(self, body, headers, include_dirs, libraries, library_dirs,
     142              lang):
    149143        (src, obj) = self._compile(body, headers, include_dirs, lang)
    150144        prog = os.path.splitext(os.path.basename(src))[0]
     
    160154        return (src, obj, prog)
    161155
    162     def _clean (self, *filenames):
     156    def _clean(self, *filenames):
    163157        if not filenames:
    164158            filenames = self.temp_files
    165159            self.temp_files = []
    166         log.info("removing: %s", string.join(filenames))
     160        log.info("removing: %s", ' '.join(filenames))
    167161        for filename in filenames:
    168162            try:
     
    182176    # XXX need access to the header search path and maybe default macros.
    183177
    184     def try_cpp (self, body=None, headers=None, include_dirs=None, lang="c"):
     178    def try_cpp(self, body=None, headers=None, include_dirs=None, lang="c"):
    185179        """Construct a source file from 'body' (a string containing lines
    186180        of C/C++ code) and 'headers' (a list of header files to include)
     
    200194        return ok
    201195
    202     def search_cpp (self, pattern, body=None,
    203                     headers=None, include_dirs=None, lang="c"):
     196    def search_cpp(self, pattern, body=None, headers=None, include_dirs=None,
     197                   lang="c"):
    204198        """Construct a source file (just like 'try_cpp()'), run it through
    205199        the preprocessor, and return true if any line of the output matches
     
    209203        symbols the preprocessor and compiler set by default.
    210204        """
    211 
    212         self._check_compiler()
    213         (src, out) = self._preprocess(body, headers, include_dirs, lang)
    214 
    215         if type(pattern) is StringType:
     205        self._check_compiler()
     206        src, out = self._preprocess(body, headers, include_dirs, lang)
     207
     208        if isinstance(pattern, str):
    216209            pattern = re.compile(pattern)
    217210
     
    230223        return match
    231224
    232     def try_compile (self, body, headers=None, include_dirs=None, lang="c"):
     225    def try_compile(self, body, headers=None, include_dirs=None, lang="c"):
    233226        """Try to compile a source file built from 'body' and 'headers'.
    234227        Return true on success, false otherwise.
     
    246239        return ok
    247240
    248     def try_link (self, body,
    249                   headers=None, include_dirs=None,
    250                   libraries=None, library_dirs=None,
    251                   lang="c"):
     241    def try_link(self, body, headers=None, include_dirs=None, libraries=None,
     242                 library_dirs=None, lang="c"):
    252243        """Try to compile and link a source file, built from 'body' and
    253244        'headers', to executable form.  Return true on success, false
     
    267258        return ok
    268259
    269     def try_run (self, body,
    270                  headers=None, include_dirs=None,
    271                  libraries=None, library_dirs=None,
    272                  lang="c"):
     260    def try_run(self, body, headers=None, include_dirs=None, libraries=None,
     261                library_dirs=None, lang="c"):
    273262        """Try to compile, link to an executable, and run a program
    274263        built from 'body' and 'headers'.  Return true on success, false
     
    294283    # when implementing a real-world config command!)
    295284
    296     def check_func (self, func,
    297                     headers=None, include_dirs=None,
    298                     libraries=None, library_dirs=None,
    299                     decl=0, call=0):
     285    def check_func(self, func, headers=None, include_dirs=None,
     286                   libraries=None, library_dirs=None, decl=0, call=0):
    300287
    301288        """Determine if function 'func' is available by constructing a
     
    323310            body.append("  %s;" % func)
    324311        body.append("}")
    325         body = string.join(body, "\n") + "\n"
     312        body = "\n".join(body) + "\n"
    326313
    327314        return self.try_link(body, headers, include_dirs,
     
    330317    # check_func ()
    331318
    332     def check_lib (self, library, library_dirs=None,
    333                    headers=None, include_dirs=None, other_libraries=[]):
     319    def check_lib(self, library, library_dirs=None, headers=None,
     320                  include_dirs=None, other_libraries=[]):
    334321        """Determine if 'library' is available to be linked against,
    335322        without actually checking that any particular symbols are provided
     
    345332                             [library]+other_libraries, library_dirs)
    346333
    347     def check_header (self, header, include_dirs=None,
    348                       library_dirs=None, lang="c"):
     334    def check_header(self, header, include_dirs=None, library_dirs=None,
     335                     lang="c"):
    349336        """Determine if the system header file named by 'header_file'
    350337        exists and can be found by the preprocessor; return true if so,
     
    355342
    356343
    357 # class config
    358 
    359 
    360 def dump_file (filename, head=None):
     344def dump_file(filename, head=None):
     345    """Dumps a file content into log.info.
     346
     347    If head is not None, will be dumped before the file content.
     348    """
    361349    if head is None:
    362         print filename + ":"
     350        log.info('%s' % filename)
    363351    else:
    364         print head
    365 
     352        log.info(head)
    366353    file = open(filename)
    367     sys.stdout.write(file.read())
    368     file.close()
     354    try:
     355        log.info(file.read())
     356    finally:
     357        file.close()
Note: See TracChangeset for help on using the changeset viewer.