1# -*- mode:python -*- 2 3# Copyright (c) 2004-2005 The Regents of The University of Michigan 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are 8# met: redistributions of source code must retain the above copyright --- 47 unchanged lines hidden (view full) --- 56 _list = _list[:] 57 else: 58 _list = list(_list) 59 _list.sort() 60 return _list 61 62class PySourceFile(object): 63 invalid_sym_char = re.compile('[^A-z0-9_]') |
64 def __init__(self, package, tnode): 65 snode = tnode.srcnode() 66 filename = str(tnode) |
67 pyname = basename(filename) 68 assert pyname.endswith('.py') 69 name = pyname[:-3] 70 if package: 71 path = package.split('.') 72 else: 73 path = [] |
74 75 modpath = path[:] |
76 if name != '__init__': 77 modpath += [name] 78 modpath = '.'.join(modpath) 79 80 arcpath = path + [ pyname ] 81 arcname = joinpath(*arcpath) 82 |
83 debugname = snode.abspath 84 if not exists(debugname): 85 debugname = tnode.abspath 86 87 self.tnode = tnode 88 self.snode = snode |
89 self.pyname = pyname 90 self.package = package 91 self.modpath = modpath 92 self.arcname = arcname |
93 self.debugname = debugname |
94 self.compiled = File(filename + 'c') 95 self.assembly = File(filename + '.s') 96 self.symname = "PyEMB_" + self.invalid_sym_char.sub('_', modpath) 97 98 99######################################################################## 100# Code for adding source files of various types 101# --- 748 unchanged lines hidden (view full) --- 850 '''Action function to compile a .py into a code object, marshal 851 it, compress it, and stick it into an asm file so the code appears 852 as just bytes with a label in the data section''' 853 854 src = file(str(source[0]), 'r').read() 855 dst = file(str(target[0]), 'w') 856 857 pysource = py_sources_tnodes[source[0]] |
858 compiled = compile(src, pysource.debugname, 'exec') |
859 marshalled = marshal.dumps(compiled) 860 compressed = zlib.compress(marshalled) 861 data = compressed 862 863 # Some C/C++ compilers prepend an underscore to global symbol 864 # names, so if they're going to do that, we need to prepend that 865 # leading underscore to globals in the assembly file. 866 if env['LEADING_UNDERSCORE']: --- 193 unchanged lines hidden --- |