#! /usr/bin/env python """ Usage: done -suffix or: done -suffix /tmp/usession-12345/ [--force=REV] This copies the pypy-c executable to ./pypy-c-REV-suffix and the C source to ./c-REV-suffix/ Use '-' if you don't want any suffix. Use '--force' to allow copying a source-only directory. """ import os, sys CHECKFILE1 = 'nonfuncnodes_6.o' CHECKFILE2 = 'nonfuncnodes_6.gcmap' def do(cmd): print '*', cmd os.system(cmd) def done(suffix, usession=None, forcerev=None): if suffix == '-': suffix = '' if forcerev: assert forcerev.startswith('--force=') forcerev = int(forcerev[8:]) if usession is None: names = [s[9:] for s in os.listdir('/tmp') if s.startswith('usession-') and #s[9:].isdigit() and os.path.exists('/tmp/'+s) and # broken link? os.stat('/tmp/'+s).st_uid == os.getuid() and not os.path.islink('/tmp/'+s) and (os.path.exists( '/tmp/%s/testing_1/%s' % (s, CHECKFILE1)) or os.path.exists( '/tmp/%s/testing_1/%s' % (s, CHECKFILE2)))] if not names: raise Exception("no /tmp/usession-xxx found with the pypy-c built") elif len(names) > 1: names = [' /tmp/usession-%s' % n for n in names] raise Exception("multiple /tmp/usession-xxx found with the pypy-c " "built, pick one manually:\n%s" % '\n'.join(names)) usession = '/tmp/usession-%s' % names[0] elif usession.isdigit(): usession = '/tmp/usession-%s' % (usession,) filename = os.path.join(usession, 'testing_1', CHECKFILE1) if not forcerev and not os.path.exists(filename): filename2 = os.path.join(usession, 'testing_1', CHECKFILE2) if not os.path.exists(filename2): raise IOError("file not found (bad usession directory?): %r" % ( filename,)) binary = os.path.join(usession, 'testing_1', 'pypy-c') if not os.path.isfile(binary): binary = os.path.join(usession, 'testing_1', 'testing_1') assert os.path.isfile(binary) def queryrev(command): g = os.popen("%s -c 'import sys; print sys.pypy_version_info[-1]" " or sys._mercurial[-1]'" " < /dev/null" % (command,), 'r') data = g.readline().strip() g.close() return data if forcerev: data = forcerev else: data = queryrev(binary) if 'll_os.' in data: # sandboxed pypy from pypy.translator.sandbox import autopath data = queryrev('%s %s %s' % ( sys.executable, os.path.join(autopath.this_dir, 'pypy_interact.py'), binary)) rev = data print rev assert rev.rstrip('+').decode('hex') suffix = '%s%s' % (rev, suffix) if os.path.exists('c-%s' % suffix): raise Exception("already there!") if os.path.isfile(binary): do('mv %s pypy-c-%s' % (binary, suffix)) do('ln -sf pypy-c-%s pypy-c' % suffix) do('mv %s/testing_1 c-%s' % (usession, suffix)) if os.path.isdir('%s/module_cache' % (usession,)): do('cp %s/module_cache/*.c c-%s/' % (usession, suffix)) makefile = 'c-%s/Makefile' % (suffix,) f = open(makefile, 'r') text = f.read() f.close() text = text.replace('../module_cache/', '') text = text.replace(usession, '.') text = text.replace('version-script=../dynamic', 'version-script=dynamic') f = open(makefile, 'w') f.write(text) f.close() if os.path.isfile('%s/typeids.txt' % (usession,)): do('cp %s/typeids.txt c-%s/' % (usession, suffix)) if os.path.isdir('%s/jitcodes' % (usession,)): do('(cd %s; tar jc jitcodes) > c-%s/jitcodes.tar.bz2 &' % (usession, suffix)) do('cp %s/dynamic-symbols-* c-%s/' % (usession, suffix)) if os.path.isfile('%s/pypy_structs.c' % (usession,)): do('cp %s/pypy_structs.c c-%s/' % (usession, suffix)) if os.path.isfile('%s/pypy_decl.h' % (usession,)): do('cp %s/pypy_*.h c-%s/' % (usession, suffix)) do('make -C c-%s clean' % suffix) if __name__ == '__main__': if len(sys.argv) not in (2, 3, 4) or not sys.argv[1].startswith('-'): print __doc__ sys.exit(2) done(*sys.argv[1:])