Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/40970 )

Change subject: scons: Create a small helper function for disecting a build target path.
......................................................................

scons: Create a small helper function for disecting a build target path.

This function does about half of the work of the loop which determines
the build root and the list of variants.

Change-Id: I4f44d1e2643244a4be889c677b25b83d41a39b19
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/40970
Tested-by: kokoro <[email protected]>
Reviewed-by: Gabe Black <[email protected]>
Maintainer: Gabe Black <[email protected]>
---
M SConstruct
M site_scons/gem5_scons/__init__.py
2 files changed, 28 insertions(+), 16 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/SConstruct b/SConstruct
index b63e2cc..beaf9ae 100755
--- a/SConstruct
+++ b/SConstruct
@@ -124,7 +124,7 @@
           help='Build systemc tests')

 from gem5_scons import Transform, error, warning, summarize_warnings
-from gem5_scons import TempFileSpawn
+from gem5_scons import TempFileSpawn, parse_build_path
 import gem5_scons

 ########################################################################
@@ -182,24 +182,20 @@

 # 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:
-        error("No non-leaf 'build' dir found on target path.", t)
-    this_build_root = joinpath('/',*path_dirs[:build_top+1])
+    this_build_root, variant = parse_build_path(t)
+
+    # Make sure all targets use the same build root.
     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(os.path.join('/', build_root, variant))

 # Make sure build_root exists (might not if this is the first build there)
 if not isdir(build_root):
diff --git a/site_scons/gem5_scons/__init__.py b/site_scons/gem5_scons/__init__.py
index 5b5777c..6b167af 100644
--- a/site_scons/gem5_scons/__init__.py
+++ b/site_scons/gem5_scons/__init__.py
@@ -221,4 +221,20 @@
     print_message('Error: ', termcap.Red, message, **kwargs)
     SCons.Script.Exit(1)

-__all__ = ['Configure', 'Transform', 'warning', 'error']
+def parse_build_path(target):
+    path_dirs = target.split('/')
+
+    # 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)
+
+    return os.path.join('/', *path_dirs), variant_dir
+
+__all__ = ['Configure', 'Transform', 'warning', 'error', 'parse_build_dir']



8 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/40970
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: I4f44d1e2643244a4be889c677b25b83d41a39b19
Gerrit-Change-Number: 40970
Gerrit-PatchSet: 12
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[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