From 0b06c5552090fb5bb87d21ed32e3234ba2d5f88f Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Wed, 4 Aug 2021 23:56:46 -0700 Subject: [PATCH] scons: Eliminate the tnode dict in PySource. Rather than pass these values to the embedPyFile function indirectly through python, we should pass them through the environment so SCons can know about them, and also to simplify the PySource class. Change-Id: I466613c194bfd965a6f5f34e1e92131834fb8b66 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/49387 Maintainer: Gabe Black Tested-by: kokoro Reviewed-by: Hoa Nguyen --- src/SConscript | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/SConscript b/src/SConscript index 8c5c2b9e2d..a5b679c97e 100644 --- a/src/SConscript +++ b/src/SConscript @@ -88,11 +88,6 @@ py_marshal = marshal_env.Program('marshal', 'python/marshal.cc')[0] # byte code, compress it, and then generate a c++ file that # inserts the result into an array. def embedPyFile(target, source, env): - def c_str(string): - if string is None: - return "0" - return '"%s"' % string - '''Action function to compile a .py into a code object, marshal it, compress it, and stick it into an asm file so the code appears as just bytes with a label in the data section. The action takes two @@ -104,12 +99,14 @@ def embedPyFile(target, source, env): import subprocess + marshal_bin, pysource = source + modpath = env['PYSOURCE_MODPATH'] + abspath = env['PYSOURCE_ABSPATH'] marshalled = subprocess.check_output( - [source[0].abspath, str(source[1])], env=env['ENV']) + [marshal_bin.abspath, str(pysource)], env=env['ENV']) compressed = zlib.compress(marshalled) data = compressed - pysource = PySource.tnodes[source[1]] code = code_formatter() code('''\ @@ -127,8 +124,8 @@ namespace # into a global list. code(''' EmbeddedPython embedded_module_info( - ${{c_str(pysource.abspath)}}, - ${{c_str(pysource.modpath)}}, + "${abspath}", + "${modpath}", embedded_module_data, ${{len(data)}}, ${{len(marshalled)}}); @@ -141,7 +138,6 @@ EmbeddedPython embedded_module_info( class PySource(SourceFile): '''Add a python source file to the named package''' modules = {} - tnodes = {} def __init__(self, package, source, tags=None, add_tags=None): '''specify the python package, the source file, and any tags''' @@ -171,10 +167,15 @@ class PySource(SourceFile): self.cpp = File(self.filename + '.cc') PySource.modules[modpath] = self - PySource.tnodes[self.tnode] = self - marshal_env.Command(self.cpp, [ py_marshal, self.tnode ], - MakeAction(embedPyFile, Transform("EMBED PY"))) + overrides = { + 'PYSOURCE_MODPATH': modpath, + 'PYSOURCE_ABSPATH': abspath, + } + marshal_env.Command(self.cpp, [ py_marshal, File(source) ], + MakeAction(embedPyFile, Transform("EMBED PY"), + varlist=overrides.keys()), + **overrides) if main['USE_PYTHON']: Source(self.cpp, tags=self.tags, add_tags='python')