Giacomo Travaglini has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/49083 )

Change subject: python: Provide a repoPath helper function
......................................................................

python: Provide a repoPath helper function

The function will return the absolute path of the gem5 repo
hosting the m5 library.
One of the use of this helper is to effectively refer/import
gem5 modules from EXTRAS repositories.

If I wanted to import the Ruby module from configs/ruby I could
do that with:

from m5.util import addToPath, repoPath

configs_path = os.path.join(repoPath(), configs)
addToPath(configs_path)

from ruby import Ruby

This isn't an out of tree scripts utility only: most of our configs are
currently relying on doing relative backward imports and could be ported
to use the repoPath utility:

addToPath(../..) is quite a common pattern

This makes the dependencies difficult to read/track and a bit fragile
as it all relies on the relative position between modules.

Change-Id: I26f6ef34b44f20903cc1b6248330b6156378f40b
Signed-off-by: Giacomo Travaglini <[email protected]>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/49083
Reviewed-by: Jason Lowe-Power <[email protected]>
Maintainer: Jason Lowe-Power <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/python/m5/util/__init__.py
1 file changed, 12 insertions(+), 1 deletion(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/python/m5/util/__init__.py b/src/python/m5/util/__init__.py
index 3f9d76e..c73947e 100644
--- a/src/python/m5/util/__init__.py
+++ b/src/python/m5/util/__init__.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2016, 2020 ARM Limited
+# Copyright (c) 2016, 2020-2021 Arm Limited
 # All rights reserved.
 #
 # The license below extends only to copyright in the software and shall
@@ -95,6 +95,17 @@
     # so place the new dir right after that.
     sys.path.insert(1, path)

+def repoPath():
+    """
+    Return the abspath of the gem5 repository.
+    This is relying on the following structure:
+
+    <gem5-repo>/build/<ISA>/gem5.[opt,debug...]
+    """
+    return os.path.dirname(
+        os.path.dirname(
+            os.path.dirname(sys.executable)))
+
 # Apply method to object.
 # applyMethod(obj, 'meth', <args>) is equivalent to obj.meth(<args>)
 def applyMethod(obj, meth, *args, **kwargs):

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/49083
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: I26f6ef34b44f20903cc1b6248330b6156378f40b
Gerrit-Change-Number: 49083
Gerrit-PatchSet: 2
Gerrit-Owner: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Richard Cooper <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to