[bitbake-devel,RFC] bitbake: ConfHandler: Add BBINCLUDESTACK

Submitted by Jacob Kroon on June 9, 2020, 2:10 p.m. | Patch ID: 173425

Details

Message ID 20200609141023.1751706-1-jacob.kroon@gmail.com
State New
Headers show

Commit Message

Jacob Kroon June 9, 2020, 2:10 p.m.
Add variable 'BBINCLUDESTACK' that contains the file inclusion stack.

Signed-off-by: Jacob Kroon <jacob.kroon@gmail.com>
---
 .../bitbake-user-manual-ref-variables.xml                 | 8 ++++++++
 lib/bb/parse/parse_py/ConfHandler.py                      | 7 +++++++
 2 files changed, 15 insertions(+)
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#11407): https://lists.openembedded.org/g/bitbake-devel/message/11407
Mute This Topic: https://lists.openembedded.org/mt/74774845/3617530
Group Owner: bitbake-devel+owner@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub  [oe-patchwork@oe-patch.openembedded.org]
-=-=-=-=-=-=-=-=-=-=-=-

Patch hide | download patch | download mbox

diff --git a/doc/bitbake-user-manual/bitbake-user-manual-ref-variables.xml b/doc/bitbake-user-manual/bitbake-user-manual-ref-variables.xml
index c4bd1f25..255000cd 100644
--- a/doc/bitbake-user-manual/bitbake-user-manual-ref-variables.xml
+++ b/doc/bitbake-user-manual/bitbake-user-manual-ref-variables.xml
@@ -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>
diff --git a/lib/bb/parse/parse_py/ConfHandler.py b/lib/bb/parse/parse_py/ConfHandler.py
index af64d344..396056ed 100644
--- a/lib/bb/parse/parse_py/ConfHandler.py
+++ b/lib/bb/parse/parse_py/ConfHandler.py
@@ -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