Bobby R. Bruce has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/52423 )
Change subject: stdlib: Fix resource downloader download to cwd upon failure
......................................................................
stdlib: Fix resource downloader download to cwd upon failure
There are some cases where default downloading to `~/.cache/gem5` will
not work (for example, running gem5 in a Docker container, an error
observed here:
https://gem5-review.googlesource.com/c/public/gem5/+/51950).
To fix this, the `_get_default_resource_dir` has been altered to iterate
through a list of default resource directory targets. This change will
mean if `~/.cache/gem5` is not available then the resource is downloaded
to the current working directory of gem5.
Change-Id: I84e523f3adc182e140959243ff9335510d6b7185
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/52423
Reviewed-by: Bobby R. Bruce <bbr...@ucdavis.edu>
Maintainer: Bobby R. Bruce <bbr...@ucdavis.edu>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/python/gem5/resources/resource.py
1 file changed, 46 insertions(+), 3 deletions(-)
Approvals:
Bobby R. Bruce: Looks good to me, approved; Looks good to me, approved
kokoro: Regressions pass
diff --git a/src/python/gem5/resources/resource.py
b/src/python/gem5/resources/resource.py
index b054b09..1abc9b4 100644
--- a/src/python/gem5/resources/resource.py
+++ b/src/python/gem5/resources/resource.py
@@ -102,7 +102,7 @@
:param resource_directory: The location of the directory in which
the
resource is to be stored. If this parameter is not set, it will
set to
the environment variable `GEM5_RESOURCE_DIR`. If the environment
is not
- set it will default to `~/.cache/gem5`.
+ set it will default to `~/.cache/gem5` if available, otherwise the
CWD.
:param override: If the resource is present, but does not have the
correct md5 value, the resoruce will be deleted and re-downloaded
if
this value is True. Otherwise an exception will be thrown. False by
@@ -137,8 +137,28 @@
def _get_default_resource_dir(cls) -> str:
"""
- Obtain the default gem5 resources directory on the host system.
+ Obtain the default gem5 resources directory on the host system.
This
+ function will iterate through sensible targets until it finds one
that
+ works on the host system.
:returns: The default gem5 resources directory.
"""
- return os.path.join(Path.home(), ".cache", "gem5")
+ test_list = [
+ # First try `~/.cache/gem5`.
+ os.path.join(Path.home(), ".cache", "gem5"),
+ # Last resort, just put things in the cwd.
+ os.path.join(Path.cwd(), "resources"),
+ ]
+
+ for path in test_list:
+ if os.path.exists(path): # If the path already exists...
+ if os.path.isdir(path): # Check to see the path is a
directory.
+ return path # If so, the path is valid and can be used.
+ else: # If the path does not exist, try to create it.
+ try:
+ os.makedirs(path, exist_ok=False)
+ return path
+ except OSError:
+ continue # If the path cannot be created, then try
another.
+
+ raise Exception("Cannot find a valid location to download
resources")
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/52423
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I84e523f3adc182e140959243ff9335510d6b7185
Gerrit-Change-Number: 52423
Gerrit-PatchSet: 3
Gerrit-Owner: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-CC: Gabe Black <gabe.bl...@gmail.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s