scons,python: Split the marshal binary into a c++ wrapper and script.

The new c++ wrapper is called gem5py, and will run any python script
using gem5's embedded python interpreter. The "marshal" functionality is
split out into a separate python script gem5py can run.

The command line for gem5py should look like this:

gem5py ${SCRIPT TO RUN} ${ARGS TO THE SCRIPT}

So, for instance, to marshal a file called foo.py, the command line
might look like this:

gem5py python/marshal.py foo.py

Also, this change reorders the sources for the python embedding action
and limits the max_sources for Transform() to 1, so that it just shows
the python file being embedded and not gem5py or the marshal.py script.
Those are still sources so dependency tracking works correctly, but they
are also implied and just add visual noise to the build output.

Change-Id: I7ae6bd114973ae44c3b634884b6dafc6577e0788
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/49392
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Gabe Black <gabe.black@gmail.com>
Maintainer: Gabe Black <gabe.black@gmail.com>
This commit is contained in:
Gabe Black
2021-08-14 04:58:07 -07:00
parent de05063ea7
commit dfec508976
4 changed files with 91 additions and 29 deletions

View File

@@ -80,7 +80,8 @@ class Source(SourceFile):
# Build a small helper that marshals the Python code using the same version
# of Python as gem5. This is in an unorthodox location to avoid building it
# for every variant.
py_marshal = marshal_env.Program('marshal', 'python/marshal.cc')[0]
gem5py = gem5py_env.Program('gem5py', 'python/gem5py.cc')[0]
marshal_py = Dir('python').File('marshal.py')
# Embed python files. All .py files that have been indicated by a
# PySource() call in a SConscript need to be embedded into the M5
@@ -99,11 +100,11 @@ def embedPyFile(target, source, env):
import subprocess
marshal_bin, pysource = source
pysource, gem5py, marshal_py = source
modpath = env['PYSOURCE_MODPATH']
abspath = env['PYSOURCE_ABSPATH']
marshalled = subprocess.check_output(
[marshal_bin.abspath, str(pysource)], env=env['ENV'])
[gem5py.abspath, str(marshal_py), str(pysource)], env=env['ENV'])
compressed = zlib.compress(marshalled)
data = compressed
@@ -172,8 +173,8 @@ class PySource(SourceFile):
'PYSOURCE_MODPATH': modpath,
'PYSOURCE_ABSPATH': abspath,
}
marshal_env.Command(cpp, [ py_marshal, File(source) ],
MakeAction(embedPyFile, Transform("EMBED PY"),
gem5py_env.Command(cpp, [ File(source), gem5py, marshal_py ],
MakeAction(embedPyFile, Transform("EMBED PY", max_sources=1),
varlist=overrides.keys()),
**overrides)
Source(cpp, tags=self.tags, add_tags='python')