Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/40859 )

Change subject: scons: Streamline searching for the "build" dir for of targets.
......................................................................

scons: Streamline searching for the "build" dir for of targets.

Simplify this method a little and get rid of the helper rfind function.

Change-Id: Ief0a2c9b4892d7ca51e9a000a4d5dd942333324a
---
M SConstruct
1 file changed, 20 insertions(+), 19 deletions(-)



diff --git a/SConstruct b/SConstruct
index b57131d..50d5672 100755
--- a/SConstruct
+++ b/SConstruct
@@ -155,13 +155,6 @@
 # Find default configuration & binary.
 Default(environ.get('M5_DEFAULT_BINARY', 'build/ARM/gem5.debug'))

-# helper function: find last occurrence of element in list
-def rfind(l, elt, offs = -1):
-    for i in range(len(l)+offs, 0, -1):
-        if l[i] == elt:
-            return i
-    raise ValueError("element not found")
-
 # Take a list of paths (or SCons Nodes) and return a list with all
 # paths made absolute and ~-expanded.  Paths will be interpreted
 # relative to the launch directory unless a different root is provided
@@ -182,24 +175,32 @@

 # Generate a list of the unique build roots and configs that the
 # collected targets reference.
-variant_paths = []
+variant_paths = set()
 build_root = None
 for t in BUILD_TARGETS:
     path_dirs = t.split('/')
-    try:
-        build_top = rfind(path_dirs, 'build', -2)
-    except:
+
+    # Pop off the target file.
+    path_dirs.pop()
+
+ # Search backwards for the "build" directory. Whatever was just before it
+    # was the name of the variant.
+    variant_dir = path_dirs.pop()
+    while path_dirs and path_dirs[-1] != 'build':
+        variant_dir = path_dirs.pop()
+    if not path_dirs:
         error("No non-leaf 'build' dir found on target path.", t)
-    this_build_root = joinpath('/',*path_dirs[:build_top+1])
+
+    # Make sure all targets use the same build root.
+    this_build_root = joinpath('/', *path_dirs)
     if not build_root:
         build_root = this_build_root
-    else:
-        if this_build_root != build_root:
-            error("build targets not under same build root\n"
-                  "  %s\n  %s" % (build_root, this_build_root))
-    variant_path = joinpath('/',*path_dirs[:build_top+2])
-    if variant_path not in variant_paths:
-        variant_paths.append(variant_path)
+    elif this_build_root != build_root:
+        error("build targets not under same build root\n  %s\n  %s" %
+            (build_root, this_build_root))
+
+    # Collect all the variants into a set.
+    variant_paths.add(joinpath('/', *path_dirs, variant_dir))

 # Make sure build_root exists (might not if this is the first build there)
 if not isdir(build_root):

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/40859
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: Ief0a2c9b4892d7ca51e9a000a4d5dd942333324a
Gerrit-Change-Number: 40859
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
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