Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/49387 )

Change subject: scons: Eliminate the tnode dict in PySource.
......................................................................

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
---
M src/SConscript
1 file changed, 14 insertions(+), 13 deletions(-)



diff --git a/src/SConscript b/src/SConscript
index a3dd639..0aa4deb 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -87,11 +87,6 @@
 # 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
@@ -103,12 +98,14 @@

     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('''\
@@ -123,8 +120,8 @@
     bytesToCppArray(code, 'embedded_module_data', data)
     code('''
 EmbeddedPython embedded_module_info(
-    ${{c_str(pysource.abspath)}},
-    ${{c_str(pysource.modpath)}},
+    "${abspath}",
+    "${modpath}",
     embedded_module_data,
     ${{len(data)}},
     ${{len(marshalled)}});
@@ -137,7 +134,6 @@
 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'''
@@ -167,10 +163,15 @@
         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')


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/49387
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I466613c194bfd965a6f5f34e1e92131834fb8b66
Gerrit-Change-Number: 49387
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to