[PATCH] Spec hierarchy dumping for a config

Philip Kirkpatrick p.kirkpatrick at reflexaerospace.com
Fri Apr 28 09:27:24 UTC 2023


I don't know if anyone else will find this useful or if it already exists
and I duplicated some effort, but I find it difficult to just read the
files in the spec folder and understand how they are connected and what
files are used in BSPs I'm interested in.  I looked through the wscript and
didn't see an existing way to dump the item tree for a given configuration,
so I added it.  The patch is as follows:

---
diff --git a/wscript b/wscript
index 567f42db2f..4e59188188 100755
--- a/wscript
+++ b/wscript
@@ -151,6 +151,61 @@ def _is_enabled(enabled, enabled_by):
         return _IS_ENABLED_OP[key](enabled, value)
     return enabled_by in enabled

+color_true = '\x1b[32m'
+color_false = '\x1b[31m'
+color_clear = '\x1b[0m'
+
+def _get_enabler_op_and(enabled, enabled_by):
+    and_str = "{ "
+    first = True
+    for next_enabled_by in enabled_by:
+        if first:
+            first = False
+        else:
+            and_str = and_str + " and "
+        and_str = and_str + _get_enabler(enabled, next_enabled_by)
+    return and_str + " }"
+
+
+def _get_enabler_op_not(enabled, enabled_by):
+    return "{ " + color_true + "not " + color_false +
_get_enabler(enabled, enabled_by) + color_clear + " }"
+
+
+def _get_enabler_op_or(enabled, enabled_by):
+    or_str = "{ "
+    first = True
+    for next_enabled_by in enabled_by:
+        if first:
+            first = False
+        else:
+            or_str = or_str + " or "
+        if _is_enabled(enabled, next_enabled_by):
+            color_start = color_true
+            color_end = color_clear
+        else:
+            color_start = color_false
+            color_end = color_clear
+        or_str = or_str + color_start + _get_enabler(enabled,
next_enabled_by) + color_end
+    return or_str + " }"
+
+
+_GET_ENABLER_OP = {
+    "and": _get_enabler_op_and,
+    "not": _get_enabler_op_not,
+    "or": _get_enabler_op_or,
+}
+
+
+def _get_enabler(enabled, enabled_by):
+    if isinstance(enabled_by, bool):
+        return color_true + str(enabled_by) + color_clear
+    if isinstance(enabled_by, list):
+        return _get_enabler_op_or(enabled, enabled_by)
+    if isinstance(enabled_by, dict):
+        key, value = next(iter(enabled_by.items()))
+        return _GET_ENABLER_OP[key](enabled, value)
+    return enabled_by
+

 def _asm_explicit_target(self, node):
     task = self.create_task("asm", node,
@@ -233,6 +288,14 @@ class Item(object):
                     "Build error related to item spec:{}: {}".format(
                         self.uid, str(e)))

+
+    def dump_spec(self, bld, bic, depth):
+        if _is_enabled(bld.env.ENABLE, self.get_enabled_by()):
+            enabler = _get_enabler(bld.env.ENABLE, self.get_enabled_by())
+            print("│  " * depth + "├──" + self.uid + " # enabled-by: " +
enabler)
+            for p in self.links():
+                p.dump_spec(bld, bic, depth + 1)
+
     def do_defaults(self, enabled):
         return

@@ -1320,6 +1383,14 @@ def options(ctx):
         help=
         "sets the option identified by KEY to the VALUE in the build
specification; it is intended for RTEMS maintainers and may be used in the
bspdefaults and configure commands",
     )
+    rg.add_option(
+        "--rtems-dumpspec",
+        action="store_true",
+        dest="rtems_dump_spec",
+        default=False,
+        help=
+        "dumps the currently enable spec yaml files and the links tree; it
is intended for RTEMS maintainers and may be used in the build commands",
+    )


 def check_environment(conf):
@@ -1587,8 +1658,14 @@ def build(bld):
     long_command_line_workaround(bld)
     bic = BuildItemContext(bld.env.ARCH_INCLUDES.split(), [], [], [], [],
[],
                            [])
-    bsps[bld.env.ARCH][bld.env.BSP_BASE].build(bld, bic)
-    items[bld.env.TOPGROUP].build(bld, bic)
+    if(bld.options.rtems_dump_spec):
+        print("BSPS:")
+        bsps[bld.env.ARCH][bld.env.BSP_BASE].dump_spec(bld, bic, 0)
+        print("items:")
+        items[bld.env.TOPGROUP].dump_spec(bld, bic, 0)
+    else:
+        bsps[bld.env.ARCH][bld.env.BSP_BASE].build(bld, bic)
+        items[bld.env.TOPGROUP].build(bld, bic)


 def add_log_filter(name):
---
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20230428/ac98868d/attachment-0001.htm>


More information about the devel mailing list