stdlib: Add 'common.Options' as a banned stdlib module
This commit adds the concept of a "banned module" to the stdlib. This blocks the user from importing modules from elsewhere in the project with known incompatibility to the stdlib. 'common.Options' has been added to this as 'common.Options' will import options to an stdlib run which are not supported. Issue-on: https://gem5.atlassian.net/browse/GEM5-1282 Change-Id: I8f2b1e24d03fab2872c735342dc8a1ff6528fb5d Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/63071 Reviewed-by: Jason Lowe-Power <power.jg@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com> Maintainer: Jason Lowe-Power <power.jg@gmail.com>
This commit is contained in:
committed by
Bobby Bruce
parent
36a1b6a73d
commit
5f40935da2
@@ -32,6 +32,7 @@ from m5.objects import Root
|
||||
from m5.util import warn
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Optional, List, Tuple, Dict, Generator, Union
|
||||
|
||||
@@ -70,6 +71,16 @@ class Simulator:
|
||||
This will run a simulation and execute default behavior for exit events.
|
||||
"""
|
||||
|
||||
# Here we declare the modules which should not be imported into any gem5
|
||||
# standard library run. The key is the module (e.g,
|
||||
# "import common.Options") and the value is the reason, which will be
|
||||
# output in the case this module is imported.
|
||||
# This is checked with the `run` function is executed.
|
||||
_banned_modules = {
|
||||
"common.Options": "The options provided by 'Options' are not "
|
||||
"compatible with the gem5 standard library.",
|
||||
}
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
board: AbstractBoard,
|
||||
@@ -344,6 +355,15 @@ class Simulator:
|
||||
reset. This is the **maximum number of ticks per simululation run**.
|
||||
"""
|
||||
|
||||
# Check to ensure no banned module has been imported.
|
||||
for banned_module in self._banned_modules.keys():
|
||||
if banned_module in sys.modules:
|
||||
raise Exception(
|
||||
f"The banned module '{banned_module}' has been included. "
|
||||
"Please do not use this in your simulations. "
|
||||
f"Reason: {self._banned_modules[banned_module]}"
|
||||
)
|
||||
|
||||
# We instantiate the board if it has not already been instantiated.
|
||||
self._instantiate()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user