From df0bed6858a4b78c1148337695a07e2aeb4125af Mon Sep 17 00:00:00 2001 From: Nikos Nikoleris Date: Thu, 9 Feb 2023 09:33:17 +0000 Subject: [PATCH] python: Ensure that m5.internal.params is available Add an import to m5.internal.params which became necessary after: 95f9017c2e configs,python: Clean some cruft out of m5.objects. This import is necessary but also causes problems when scons calls build_tools/sim_object_param_struct_hh.py to generate params/SimObject.hh. m5.internal.params itself imports _m5 and _m5 is unavalailable resulting in an ImportError. This is bening and we can safely ignore it. Change-Id: I3809e81284e730fb9c9e0e7e91bd61b801d73f90 Signed-off-by: Nikos Nikoleris Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/67797 Maintainer: Giacomo Travaglini Tested-by: kokoro Reviewed-by: Giacomo Travaglini --- src/python/m5/SimObject.py | 3 +++ src/python/m5/internal/params.py | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py index b5dfca9752..6caa532897 100644 --- a/src/python/m5/SimObject.py +++ b/src/python/m5/SimObject.py @@ -445,6 +445,9 @@ class MetaSimObject(type): return cls.__name__ def getCCClass(cls): + # Ensure that m5.internal.params is available. + import m5.internal.params + return getattr(m5.internal.params, cls.pybind_class) # See ParamValue.cxx_predecls for description. diff --git a/src/python/m5/internal/params.py b/src/python/m5/internal/params.py index 8762a69e61..8225d0b059 100644 --- a/src/python/m5/internal/params.py +++ b/src/python/m5/internal/params.py @@ -37,8 +37,17 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import inspect -import _m5 -for name, module in inspect.getmembers(_m5): - if name.startswith("param_") or name.startswith("enum_"): - exec("from _m5.%s import *" % name) +try: + # Avoid ImportErrors at build time when _m5 is not available + import _m5 + + in_gem5 = True +except ImportError: + # The import failed, we're being called from the build system + in_gem5 = False + +if in_gem5: + for name, module in inspect.getmembers(_m5): + if name.startswith("param_") or name.startswith("enum_"): + exec("from _m5.%s import *" % name)