config: make M5_PATH a real search path

Although you can put a list of colon-separated directory names
in M5_PATH, the current code just takes the first one that
exists and assumes all files must live there.  This change
makes the code search the specified list of directories
for each individual binary or disk image that's requested.

The main motivation is that the x86/Alpha binaries and the
ARM binaries are in separate downloads, and thus naturally
end up in separate directories.  With this change, you can
have M5_PATH point to those two directories, then run any
FS regression test without changing M5_PATH.  Currently,
you either have to merge the two download directories
or change M5_PATH (or do something else I haven't figured out).
This commit is contained in:
Steve Reinhardt 2015-02-05 16:45:06 -08:00
parent 461a80beb3
commit 634d923751

View file

@ -33,39 +33,46 @@ from os import environ as env
config_path = os.path.dirname(os.path.abspath(__file__)) config_path = os.path.dirname(os.path.abspath(__file__))
config_root = os.path.dirname(config_path) config_root = os.path.dirname(config_path)
def searchpath(path, file):
for p in path:
f = joinpath(p, file)
if os.path.exists(f):
return f
raise IOError, "Can't find file '%s' on path." % file
def disk(file): def disk(file):
system() system()
return joinpath(disk.dir, file) return searchpath(disk.path, file)
def binary(file): def binary(file):
system() system()
return joinpath(binary.dir, file) return searchpath(binary.path, file)
def script(file): def script(file):
system() system()
return joinpath(script.dir, file) return searchpath(script.path, file)
def system(): def system():
if not system.dir: if not system.path:
try: try:
path = env['M5_PATH'].split(':') path = env['M5_PATH'].split(':')
except KeyError: except KeyError:
path = [ '/dist/m5/system', '/n/poolfs/z/dist/m5/system' ] path = [ '/dist/m5/system', '/n/poolfs/z/dist/m5/system' ]
for system.dir in path: # filter out non-existent directories
if os.path.isdir(system.dir): system.path = filter(os.path.isdir, path)
break
else:
raise ImportError, "Can't find a path to system files."
if not binary.dir: if not system.path:
binary.dir = joinpath(system.dir, 'binaries') raise IOError, "Can't find a path to system files."
if not disk.dir:
disk.dir = joinpath(system.dir, 'disks')
if not script.dir:
script.dir = joinpath(config_root, 'boot')
system.dir = None if not binary.path:
binary.dir = None binary.path = [joinpath(p, 'binaries') for p in system.path]
disk.dir = None if not disk.path:
script.dir = None disk.path = [joinpath(p, 'disks') for p in system.path]
if not script.path:
script.path = [joinpath(config_root, 'boot')]
system.path = None
binary.path = None
disk.path = None
script.path = None