Changeset 391 for python/trunk/Lib/distutils/command/config.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/distutils/command/config.py
r2 r391 10 10 """ 11 11 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 14 import os 15 import re 16 18 17 from distutils.core import Command 19 18 from distutils.errors import DistutilsExecError … … 21 20 from distutils import log 22 21 23 LANG_EXT = {'c': '.c', 24 'c++': '.cxx'} 25 26 class config (Command): 22 LANG_EXT = {'c': '.c', 'c++': '.cxx'} 23 24 class config(Command): 27 25 28 26 description = "prepare to build" … … 54 52 # does nothing by default, these are empty. 55 53 56 def initialize_options 54 def initialize_options(self): 57 55 self.compiler = None 58 56 self.cc = None 59 57 self.include_dirs = None 60 #self.define = None61 #self.undef = None62 58 self.libraries = None 63 59 self.library_dirs = None … … 71 67 self.temp_files = [] 72 68 73 def finalize_options 69 def finalize_options(self): 74 70 if self.include_dirs is None: 75 71 self.include_dirs = self.distribution.include_dirs or [] 76 elif type(self.include_dirs) is StringType:77 self.include_dirs = s tring.split(self.include_dirs,os.pathsep)72 elif isinstance(self.include_dirs, str): 73 self.include_dirs = self.include_dirs.split(os.pathsep) 78 74 79 75 if self.libraries is None: 80 76 self.libraries = [] 81 elif type(self.libraries) is StringType:77 elif isinstance(self.libraries, str): 82 78 self.libraries = [self.libraries] 83 79 84 80 if self.library_dirs is None: 85 81 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): 91 86 pass 92 87 … … 96 91 # may use these freely. 97 92 98 def _check_compiler 93 def _check_compiler(self): 99 94 """Check that 'self.compiler' really is a CCompiler object; 100 95 if not, make it one. … … 115 110 116 111 117 def _gen_temp_sourcefile 112 def _gen_temp_sourcefile(self, body, headers, lang): 118 113 filename = "_configtest" + LANG_EXT[lang] 119 114 file = open(filename, "w") … … 128 123 return filename 129 124 130 def _preprocess 125 def _preprocess(self, body, headers, include_dirs, lang): 131 126 src = self._gen_temp_sourcefile(body, headers, lang) 132 127 out = "_configtest.i" … … 135 130 return (src, out) 136 131 137 def _compile 132 def _compile(self, body, headers, include_dirs, lang): 138 133 src = self._gen_temp_sourcefile(body, headers, lang) 139 134 if self.dump_source: … … 144 139 return (src, obj) 145 140 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): 149 143 (src, obj) = self._compile(body, headers, include_dirs, lang) 150 144 prog = os.path.splitext(os.path.basename(src))[0] … … 160 154 return (src, obj, prog) 161 155 162 def _clean 156 def _clean(self, *filenames): 163 157 if not filenames: 164 158 filenames = self.temp_files 165 159 self.temp_files = [] 166 log.info("removing: %s", string.join(filenames))160 log.info("removing: %s", ' '.join(filenames)) 167 161 for filename in filenames: 168 162 try: … … 182 176 # XXX need access to the header search path and maybe default macros. 183 177 184 def try_cpp 178 def try_cpp(self, body=None, headers=None, include_dirs=None, lang="c"): 185 179 """Construct a source file from 'body' (a string containing lines 186 180 of C/C++ code) and 'headers' (a list of header files to include) … … 200 194 return ok 201 195 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"): 204 198 """Construct a source file (just like 'try_cpp()'), run it through 205 199 the preprocessor, and return true if any line of the output matches … … 209 203 symbols the preprocessor and compiler set by default. 210 204 """ 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): 216 209 pattern = re.compile(pattern) 217 210 … … 230 223 return match 231 224 232 def try_compile 225 def try_compile(self, body, headers=None, include_dirs=None, lang="c"): 233 226 """Try to compile a source file built from 'body' and 'headers'. 234 227 Return true on success, false otherwise. … … 246 239 return ok 247 240 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"): 252 243 """Try to compile and link a source file, built from 'body' and 253 244 'headers', to executable form. Return true on success, false … … 267 258 return ok 268 259 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"): 273 262 """Try to compile, link to an executable, and run a program 274 263 built from 'body' and 'headers'. Return true on success, false … … 294 283 # when implementing a real-world config command!) 295 284 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): 300 287 301 288 """Determine if function 'func' is available by constructing a … … 323 310 body.append(" %s;" % func) 324 311 body.append("}") 325 body = string.join(body, "\n") + "\n"312 body = "\n".join(body) + "\n" 326 313 327 314 return self.try_link(body, headers, include_dirs, … … 330 317 # check_func () 331 318 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=[]): 334 321 """Determine if 'library' is available to be linked against, 335 322 without actually checking that any particular symbols are provided … … 345 332 [library]+other_libraries, library_dirs) 346 333 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"): 349 336 """Determine if the system header file named by 'header_file' 350 337 exists and can be found by the preprocessor; return true if so, … … 355 342 356 343 357 # class config 358 359 360 def dump_file (filename, head=None): 344 def 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 """ 361 349 if head is None: 362 print filename + ":"350 log.info('%s' % filename) 363 351 else: 364 print head 365 352 log.info(head) 366 353 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.