dst = file(str(target[0]), 'w')
def dump_mod(sym, endchar=','):
+ def c_str(string):
+ if string is None:
+ return "0"
+ return '"%s"' % string
pysource = PySource.symnames[sym]
- print >>dst, ' { "%s",' % pysource.arcname
- print >>dst, ' "%s",' % pysource.modpath
- print >>dst, ' %s_beg, %s_end,' % (sym, sym)
- print >>dst, ' %s_end - %s_beg,' % (sym, sym)
- print >>dst, ' *(int *)%s_end }%s' % (sym, endchar)
+ print >>dst, ' { %s,' % c_str(pysource.arcname)
+ print >>dst, ' %s,' % c_str(pysource.abspath)
+ print >>dst, ' %s,' % c_str(pysource.modpath)
+ print >>dst, ' %s_beg, %s_end,' % (sym, sym)
+ print >>dst, ' %s_end - %s_beg,' % (sym, sym)
+ print >>dst, ' *(int *)%s_end }%s' % (sym, endchar)
print >>dst, '#include "sim/init.hh"'
# Skip the importer since we've already exported it
continue
dump_mod(sym)
- print >>dst, " { 0, 0, 0, 0, 0, 0 }"
+ print >>dst, " { 0, 0, 0, 0, 0, 0, 0 }"
print >>dst, "};"
def __init__(self):
self.modules = {}
- def add_module(self, filename, modpath, code):
+ def add_module(self, filename, abspath, modpath, code):
if modpath in self.modules:
raise AttributeError, "%s already found in importer"
- self.modules[modpath] = (filename, code)
+ self.modules[modpath] = (filename, abspath, code)
def find_module(self, fullname, path):
if fullname in self.modules:
try:
mod.__loader__ = self
- srcfile,code = self.modules[fullname]
+ srcfile,abspath,code = self.modules[fullname]
+
+ override = os.environ.get('M5_OVERRIDE_PY_SOURCE', 'false').lower()
+ if override in ('true', 'yes') and os.path.exists(abspath):
+ src = file(abspath, 'r').read()
+ code = compile(src, abspath, 'exec')
+
if os.path.basename(srcfile) == '__init__.py':
mod.__path__ = fullname.split('.')
mod.__file__ = srcfile
while (pymod->filename) {
PyObject *code = getCode(pymod);
PyObject *result = PyObject_CallMethod(module, PyCC("add_module"),
- PyCC("ssO"), pymod->filename, pymod->modpath, code);
+ PyCC("sssO"), pymod->filename, pymod->abspath, pymod->modpath,
+ code);
if (!result) {
PyErr_Print();
return 1;