Skip to contentSkip to conversation

bitbake: ConfHandler: Add BBINCLUDESTACK

RFC PATCH New Jacob Kroon 1 participant 1 message Jun 9, 2020

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 bitbake: ConfHandler: Add BBINCLUDESTACK

Add variable 'BBINCLUDESTACK' that contains the file inclusion stack.

---
 .../bitbake-user-manual-ref-variables.xml                 | 8 ++++++++
 lib/bb/parse/parse_py/ConfHandler.py                      | 7 +++++++
 2 files changed, 15 insertions(+)
doc/bitbake-user-manual/bitbake-user-manual-ref-variables.xml +8 -0
index c4bd1f25..255000cd 100644
@@ -1134,6 +1134,14 @@
             </glossdef>
         </glossentry>
 
+        <glossentry id='var-bb-BBINCLUDESTACK'><glossterm>BBINCLUDESTACK</glossterm>
+            <glossdef>
+                <para>
+                    Contains a space-separated list of the file inclusion stack.
+                </para>
+            </glossdef>
+        </glossentry>
+
         <glossentry id='var-bb-BBINCLUDELOGS'><glossterm>BBINCLUDELOGS</glossterm>
             <glossdef>
                 <para>
lib/bb/parse/parse_py/ConfHandler.py +7 -0
index af64d344..396056ed 100644
@@ -16,6 +16,7 @@ import re
 import os
 import bb.utils
 from bb.parse import ParseError, resolve_file, ast, logger, handle
+from collections import deque
 
 __config_regexp__  = re.compile( r"""
     ^
@@ -46,6 +47,7 @@ __require_regexp__ = re.compile( r"require\s+(.+)" )
 __export_regexp__ = re.compile( r"export\s+([a-zA-Z0-9\-_+.${}/~]+)$" )
 __unset_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)$" )
 __unset_flag_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)\[([a-zA-Z0-9\-_+.]+)\]$" )
+include_stack = deque()
 
 def init(data):
     topdir = data.getVar('TOPDIR', False)
@@ -89,6 +91,9 @@ def include_single_file(parentfn, fn, lineno, data, error_out):
     elif bb.parse.check_dependency(data, fn):
         logger.warning("Duplicate inclusion for %s in %s" % (fn, data.getVar('FILE')))
 
+    include_stack.append(parentfn)
+    data.setVar('BBINCLUDESTACK', ' '.join(include_stack))
+
     try:
         bb.parse.handle(fn, data, True)
     except (IOError, OSError) as exc:
@@ -101,6 +106,8 @@ def include_single_file(parentfn, fn, lineno, data, error_out):
                 raise ParseError("Could not %s file %s: %s" % (error_out, fn, exc.strerror), parentfn, lineno)
             else:
                 raise ParseError("Error parsing %s: %s" % (fn, exc.strerror), parentfn, lineno)
+    finally:
+        include_stack.pop()
 
 # We have an issue where a UI might want to enforce particular settings such as
 # an empty DISTRO variable. If configuration files do something like assigning