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)