Changeset 440
- Timestamp:
- Thu Feb 28 13:21:15 2008
- Files:
-
- branches/python2.5/bindepend.py (modified) (diff)
- branches/python2.5/Build.py (modified) (diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
branches/python2.5/bindepend.py
r439 r440 35 35 import sys 36 36 import re 37 from glob import glob 37 38 38 39 seen = {} … … 384 385 os.system(cmd) 385 386 387 def findLibrary(name): 388 """Look for a library in the system. 389 390 Emulate the algorithm used by dlopen. 391 392 `name`must include the prefix, e.g. ``libpython2.4.so`` 393 """ 394 assert sys.platform == 'linux2', "Current implementation for Linux only" 395 396 lib = None 397 398 # Look in the LD_LIBRARY_PATH 399 lp = os.environ.get('LD_LIBRARY_PATH') 400 if lp: 401 for path in string.split(lp, os.pathsep): 402 libs = glob(os.path.join(path, name + '*')) 403 if libs: 404 lib = libs[0] 405 break 406 407 # Look in /etc/ld.so.cache 408 if lib is None: 409 expr = r'/[^\(\)\s]*%s\.[^\(\)\s]*' % re.escape(name) 410 m = re.search(expr, os.popen('/sbin/ldconfig -p 2>/dev/null').read()) 411 if m: 412 lib = m.group(0) 413 414 # Look in the known safe paths 415 if lib is None: 416 for path in ['/lib', '/usr/lib']: 417 libs = glob(os.path.join(path, name + '*')) 418 if libs: 419 lib = libs[0] 420 break 421 422 # give up :( 423 if lib is None: 424 return None 425 426 # Resolve the file name into the soname 427 dir, file = os.path.split(lib) 428 return os.path.join(dir, getSoname(lib)) 429 430 def getSoname(filename): 431 """Return the soname of a library.""" 432 cmd = "objdump -p -j .dynamic 2>/dev/null " + filename 433 m = re.search(r'\s+SONAME\s+([^\s]+)', os.popen(cmd).read()) 434 if m: return m.group(1) 435 386 436 if __name__ == "__main__": 387 437 if len(sys.argv) < 2: -
branches/python2.5/Build.py
r431 r440 226 226 pure.append((modnm, fnm, 'PYMODULE')) 227 227 binaries.extend(bindepend.Dependencies(binaries)) 228 self.fixMissingPythonLib(binaries) 228 229 scripts[1:1] = rthooks 229 230 self.scripts = TOC(scripts) … … 249 250 return 0 250 251 252 def fixMissingPythonLib(self, binaries): 253 """Add the Python library if missing from the binaries. 254 255 Some linux distributions (e.g. debian-based) statically build the 256 Python executable to the libpython, so bindepend doesn't include 257 it in its output. 258 """ 259 if sys.platform != 'linux2': return 260 261 name = 'libpython%d.%d.so' % sys.version_info[:2] 262 for (nm, fnm, typ) in binaries: 263 if typ == 'BINARY' and name in fnm: 264 # lib found 265 return 266 267 lib = bindepend.findLibrary(name) 268 if lib is None: 269 raise IOError("Python library not found!") 270 271 binaries.append((os.path.split(lib)[1], lib, 'BINARY')) 272 273 251 274 def findRTHook(modnm): 252 275 hooklist = rthooks.get(modnm)
