Changeset 460
- Timestamp:
- Wed May 14 13:13:47 2008
- Files:
-
- branches/crypt/bindepend.py (modified) (diff)
- branches/crypt/buildtests/test10.py (modified) (diff)
- branches/crypt/buildtests/test12.py (added)
- branches/crypt/buildtests/test12.spec (added)
- branches/crypt/buildtests/test14.py (added)
- branches/crypt/buildtests/test16.py (added)
- branches/crypt/buildtests/test14.spec (added)
- branches/crypt/buildtests/test16.spec (added)
- branches/crypt/buildtests/test4i.py (added)
- branches/crypt/buildtests/test4i.spec (added)
- branches/crypt/buildtests/test11.py (modified) (diff)
- branches/crypt/buildtests/test13.py (added)
- branches/crypt/buildtests/test13.spec (added)
- branches/crypt/buildtests/test15.spec (added)
- branches/crypt/buildtests/runtests.py (modified) (diff)
- branches/crypt/buildtests/test4.py (deleted)
- branches/crypt/buildtests/test4.spec (deleted)
- branches/crypt/hooks/hook-_elementtree.py (added)
- branches/crypt/make-linux.sh (added)
- branches/crypt/Build.py (modified) (diff)
- branches/crypt/mf.py (modified) (diff)
- branches/crypt/source/linux/getpath.h (added)
- branches/crypt/source/linux/Make.py (modified) (diff)
- branches/crypt/source/linux/main.c (modified) (diff)
- branches/crypt/source/linux/getpath.c (modified) (diff)
- branches/crypt/source/common/launch.h (modified) (diff)
- branches/crypt/source/common/launch.c (modified) (diff)
- branches/crypt/source/windows/dllmain.c (modified) (diff)
- branches/crypt/iu.py (modified) (diff)
- branches/crypt/archive.py (modified) (diff)
- branches/crypt/Configure.py (modified) (diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
branches/crypt/bindepend.py
r455 r460 35 35 import sys 36 36 import re 37 from glob import glob 37 38 38 39 seen = {} … … 74 75 'MSVCP80.DLL':1, 75 76 'MSVCR80.DLL':1, 77 # regex excludes 76 78 '^/usr/lib':1, 77 79 '^/lib':1, … … 266 268 #print "I: analyzing", pth 267 269 seen[string.upper(nm)] = 1 270 for lib, npth in selectImports(pth): 271 if seen.get(string.upper(lib),0): 272 continue 273 lTOC.append((lib, npth, 'BINARY')) 274 275 return lTOC 276 277 def selectImports(pth): 278 """Return the dependencies of a binary that should be included. 279 280 Return a list of pairs (name, fullpath) 281 """ 282 rv = [] 268 283 dlls = getImports(pth) 269 284 for lib in dlls: 270 #print "I: found", lib271 285 if not iswin and not cygwin: 286 # plain win case 272 287 npth = lib 273 288 dir, lib = os.path.split(lib) … … 275 290 continue 276 291 else: 292 # all other platforms 277 293 npth = getfullnameof(lib, os.path.dirname(pth)) 294 295 # now npth is a candidate lib 296 # check again for excludes but with regex FIXME: split the list 278 297 if excludesRe.search(npth): 279 continue 280 if seen.get(string.upper(lib),0): 281 continue 298 if 'libpython' not in npth and 'Python.framework' not in npth: 299 # skip libs not containing (libpython or Python.framework) 300 #print "I: skipping %20s <- %s" % (npth, pth) 301 continue 302 else: 303 #print "I: inserting %20s <- %s" % (npth, pth) 304 pass 305 282 306 if npth: 283 lTOC.append((lib, npth, 'BINARY'))307 rv.append((lib, npth)) 283 307 else: 284 308 print "E: lib not found:", lib, "dependency of", pth 285 return lTOC 309 310 return rv 286 311 287 312 def _getImports_ldd(pth): … … 354 379 return _bpath 355 380 381 def fixOsxPaths(moduleName): 382 for name, lib in selectImports(moduleName): 383 dest = os.path.join("@executable_path", name) 384 cmd = "install_name_tool -change %s %s %s" % (lib, dest, moduleName) 385 os.system(cmd) 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 356 436 if __name__ == "__main__": 357 if len(sys.argv) < 2: 358 print "Usage: python %s BINARYFILE" % sys.argv[0] 359 sys.exit(0) 360 print getImports(sys.argv[1]) 437 if len(sys.argv) < 2: 438 print "Usage: python %s BINARYFILE" % sys.argv[0] 439 sys.exit(0) 440 print getImports(sys.argv[1]) 441 -
branches/crypt/buildtests/test10.py
r316 r460 1 1 # Verify packagin of PIL.Image. Specifically, the hidden import of FixTk 2 2 # importing tkinter is causing some problems. 3 from Image import fromstring 3 try: 4 from Image import fromstring 5 except ImportError: 6 fromstring = "PIL missing!! Install PIL before running this test!" 4 7 print fromstring -
branches/crypt/buildtests/test11.py
r316 r460 1 1 # Verify packagin of PIL.Image. Specifically, the hidden import of FixTk 2 2 # importing tkinter is causing some problems. 3 from PIL.Image import fromstring 3 try: 4 from PIL.Image import fromstring 5 except ImportError: 6 fromstring = "PIL missing!! Install PIL before running this test!" 4 7 print fromstring -
branches/crypt/buildtests/runtests.py
r457 r460 24 24 import os, sys, glob, string 25 25 import shutil 26 26 27 try: 27 28 here=os.path.dirname(__file__) … … 54 55 print e 55 56 56 def runtests( sources=None):57 def runtests(alltests, filters=None): 56 57 info = "Executing PyInstaller tests in: %s" % os.getcwd() 57 58 print "*"*len(info) 58 59 print info 59 60 print "*"*len(info) 60 alltests = glob.glob('test*[0-9].py') 61 if not sources: 61 build_python = open("python_exe.build", "w") 62 build_python.write(sys.executable) 63 build_python.close() 64 if not filters: 62 65 tests = alltests 63 66 else: 64 67 tests = [] 65 for part in sources:68 for part in filters: 65 68 tests += [t for t in alltests if part in t and t not in tests] 66 69 tests.sort(key=lambda x: (len(x), x)) # test1 < test10 67 70 path = os.environ["PATH"] 71 counter = dict(passed=[],failed=[]) 68 72 for src in tests: 69 73 print … … 81 85 res = os.system('dist%s%s%s.exe' % (test, os.sep, test)) 82 86 os.environ["PATH"] = path 83 assert res == 0, "%s Test error!" % src 84 print "################## FINISHING TEST %s ################################" % src 87 if res == 0: 88 counter["passed"].append(src) 89 print "################## FINISHING TEST %s ################################" % src 90 else: 91 counter["failed"].append(src) 92 print "#################### TEST %s FAILED #################################" % src 93 print counter 85 94 86 95 if __name__ == '__main__': 87 if len(sys.argv) == 1: 88 clean() 89 runtests() 90 if '--clean' in sys.argv: 91 clean() 92 if '--run' in sys.argv: 93 runtests(sys.argv[2:]) 96 normal_tests = glob.glob('test*[0-9].py') 97 interactive_tests = glob.glob('test*[0-9]i.py') 98 args = sys.argv[1:] 99 100 if "-i" in args: 101 print "Running interactive tests" 102 tests = interactive_tests 103 else: 104 print "Running normal tests (-i for interactive tests)" 105 tests = normal_tests 106 107 clean() 108 runtests(tests) 109 -
branches/crypt/Build.py
r457 r460 87 87 if not os.path.exists(BUILDPATH): 88 88 os.mkdir(BUILDPATH) 89 exec open(spec, 'r').read()+'\n'89 execfile(spec) 89 89 90 90 def mtime(fnm): … … 95 95 return 0 96 96 97 def absnormpath(apath): 98 return os.path.abspath(os.path.normpath(apath)) 99 97 100 class Target: 98 101 invcnum = 0 99 102 def __init__(self): 100 103 self.invcnum = Target.invcnum 101 Target.invcnum = Target.invcnum + 1 102 self.out = os.path.join(BUILDPATH, 'out%d.toc' % self.invcnum) 104 Target.invcnum += 1 105 self.out = os.path.join(BUILDPATH, 'out%s%d.toc' % (self.__class__.__name__, 106 self.invcnum)) 103 107 self.dependencies = TOC() 104 108 def __postinit__(self): … … 117 121 if pathex: 118 122 for path in pathex: 119 self.pathex.append( os.path.abspath(os.path.normpath(path)))123 self.pathex.append(absnormpath(path)) 119 123 self.hookspath = hookspath 120 124 self.excludes = excludes … … 128 132 if last_build == 0: 129 133 print "building %s because %s non existent" % (self.__class__.__name__, outnm) 130 return 1134 return True 130 134 for fnm in self.inputs: 131 135 if mtime(fnm) > last_build: 132 136 print "building because %s changed" % fnm 133 return 1137 return True 133 137 try: 134 138 inputs, pathex, hookspath, excludes, scripts, pure, binaries = eval(open(self.out, 'r').read()) 135 139 except: 136 140 print "building because %s disappeared" % outnm 137 return 1141 return True 137 141 if inputs != self.inputs: 138 142 print "building %s because inputs changed" % outnm 139 return 1143 return True 139 143 if pathex != self.pathex: 140 144 print "building %s because pathex changed" % outnm 141 return 1145 return True 141 145 if hookspath != self.hookspath: 142 146 print "building %s because hookspath changed" % outnm 143 return 1147 return True 143 147 if excludes != self.excludes: 144 148 print "building %s because excludes changed" % outnm 145 return 1149 return True 145 149 for (nm, fnm, typ) in scripts: 146 150 if mtime(fnm) > last_build: 147 151 print "building because %s changed" % fnm 148 return 1152 return True 148 152 for (nm, fnm, typ) in pure: 149 153 if mtime(fnm) > last_build: 150 154 print "building because %s changed" % fnm 151 return 1155 return True 151 155 elif mtime(fnm[:-1]) > last_build: 152 156 print "building because %s changed" % fnm[:-1] 153 return 1157 return True 153 157 for (nm, fnm, typ) in binaries: 154 158 if mtime(fnm) > last_build: 155 159 print "building because %s changed" % fnm 156 return 1160 return True 156 160 self.scripts = TOC(scripts) 157 161 self.pure = TOC(pure) 158 162 self.binaries = TOC(binaries) 159 return 0163 return False 159 163 def assemble(self): 160 164 print "running Analysis", os.path.basename(self.out) 161 165 paths = self.pathex 162 166 for i in range(len(paths)): 163 paths[i] = os.path.abspath(os.path.normpath(paths[i])) 164 dirs = {} 165 pynms = [] 167 # FIXME: isn't self.pathex already norm-abs-pathed? 168 paths[i] = absnormpath(paths[i]) 169 ################################################### 170 # Scan inputs and prepare: 171 dirs = {} # input directories 172 pynms = [] # python filenames with no extension 166 173 for script in self.inputs: 167 174 if not os.path.exists(script): … … 183 190 if not d: 184 191 d = os.getcwd() 185 d = os.path.abspath(os.path.normpath(d))192 d = absnormpath(d) 185 192 pynm, ext = os.path.splitext(base) 186 193 dirs[d] = 1 187 194 pynms.append(pynm) 195 ################################################### 196 # Initialize analyzer and analyze scripts 188 197 analyzer = mf.ImportTracker(dirs.keys()+paths, self.hookspath, self.excludes) 189 198 #print analyzer.path 190 scripts = [] 199 scripts = [] # will contain scripts to bundle 190 199 for i in range(len(self.inputs)): 191 200 script = self.inputs[i] … … 195 204 analyzer.analyze_script(script) 196 205 scripts.append((pynms[i], script, 'PYSOURCE')) 197 pure = [] 198 binaries = [] 199 rthooks = [] 206 ################################################### 207 # Fills pure, binaries and rthookcs lists to TOC 208 pure = [] # pure python modules 209 binaries = [] # binaries to bundle 210 rthooks = [] # rthooks if needed 200 211 for modnm, mod in analyzer.modules.items(): 212 # FIXME: why can we have a mod == None here? 201 213 if mod is not None: 202 214 hooks = findRTHook(modnm) #XXX … … 214 226 pure.append((modnm, fnm, 'PYMODULE')) 215 227 binaries.extend(bindepend.Dependencies(binaries)) 228 self.fixMissingPythonLib(binaries) 216 229 scripts[1:1] = rthooks 217 230 self.scripts = TOC(scripts) 218 231 self.pure = TOC(pure) 219 232 self.binaries = TOC(binaries) 220 try: 233 try: # read .toc 220 233 oldstuff = eval(open(self.out, 'r').read()) 221 234 except: … … 237 250 return 0 238 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 239 274 def findRTHook(modnm): 240 275 hooklist = rthooks.get(modnm) … … 319 354 return digest 320 355 321 def checkCache(fnm, strip, upx): 322 if not strip and not upx: 356 def checkCache(fnm, strip, upx, fix_paths=1): 357 # On darwin a cache is required anyway to keep the libaries 358 # with relative install names 359 if not strip and not upx and sys.platform != 'darwin': 323 360 return fnm 324 361 if strip: … … 345 382 digest = cacheDigest(fnm) 346 383 cachedfile = os.path.join(cachedir, basenm) 384 cmd = None 347 385 if cache_index.has_key(basenm): 348 386 if digest != cache_index[basenm]: … … 352 390 if upx: 353 391 if strip: 354 fnm = checkCache(fnm, 1, 0) 392 fnm = checkCache(fnm, 1, 0, fix_paths=0) 354 392 cmd = "upx --best -q \"%s\"" % cachedfile 355 393 else: 356 cmd = "strip \"%s\"" % cachedfile 394 if strip: 395 cmd = "strip \"%s\"" % cachedfile 357 396 shutil.copy2(fnm, cachedfile) 358 397 os.chmod(cachedfile, 0755) 359 os.system(cmd) 398 if cmd: os.system(cmd) 399 400 if sys.platform == 'darwin' and fix_paths: 401 bindepend.fixOsxPaths(cachedfile) 360 402 361 403 # update cache index -
branches/crypt/mf.py
r459 r460 38 38 return True 39 39 40 def pyco(): 41 """ 42 Returns correct extension ending: 'c' or 'o' 43 """ 44 if __debug__: 45 return 'c' 46 else: 47 return 'o' 40 48 41 49 class Owner: … … 65 73 try: 66 74 st = os.stat(attempt) 67 except: 75 except Exception, e: 76 #print "DirOwner", e 68 77 pass 69 78 else: … … 72 81 continue 73 82 if typ == imp.C_EXTENSION: 83 #print "DirOwner.getmod -> ExtensionModule(%s, %s)" % (nm, attempt) 74 84 return ExtensionModule(nm, attempt) 75 85 elif typ == imp.PY_SOURCE: … … 80 90 break 81 91 if py is None and pyc is None: 92 #print "DirOwner.getmod -> (py == pyc == None)" 82 93 return None 83 94 while 1: 95 # If we have no pyc or py is newer 84 96 if pyc is None or py and pyc[1][8] < py[1][8]: 85 97 try: 86 98 stuff = open(py[0], 'r').read()+'\n' 87 99 co = compile(string.replace(stuff, "\r\n", "\n"), py[0], 'exec') 88 &nb
