[2/3] cookerdata: Set TOPDIR explicitly and fix broke findTopdir()

Message ID 20211113162549.3931833-2-richard.purdie@linuxfoundation.org
State New
Headers show
Series [1/3] tests/runqueue: Set TOPDIR in test | expand

Commit Message

Richard Purdie Nov. 13, 2021, 4:25 p.m. UTC
TOPDIR is set internally deep within the parser to os.getcwd(). Rather
than do that, set it explicitly if not set. Note that modern code will
almost always have a bblayers.conf file which would have already set
TOPDIR before this new code.

Also fix findTopdir since the conf/bitbake.conf codepath is just
plain incorrect, it would find build metadata, not the current
build directory that bitbake would use. Again, the use of bblayers.conf
means hitting the fallback code was unlikely.

This change makes everything clear and explicit.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/cookerdata.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Patch

diff --git a/lib/bb/cookerdata.py b/lib/bb/cookerdata.py
index 592bc2968e..397b43dfa7 100644
--- a/lib/bb/cookerdata.py
+++ b/lib/bb/cookerdata.py
@@ -210,7 +210,7 @@  def findConfigFile(configfile, data):
 
 #
 # We search for a conf/bblayers.conf under an entry in BBPATH or in cwd working
-# up to /. If that fails, we search for a conf/bitbake.conf in BBPATH.
+# up to /. If that fails, bitbake would fall back to cwd.
 #
 
 def findTopdir():
@@ -223,11 +223,8 @@  def findTopdir():
     layerconf = findConfigFile("bblayers.conf", d)
     if layerconf:
         return os.path.dirname(os.path.dirname(layerconf))
-    if bbpath:
-        bitbakeconf = bb.utils.which(bbpath, "conf/bitbake.conf")
-        if bitbakeconf:
-            return os.path.dirname(os.path.dirname(bitbakeconf))
-    return None
+
+    return os.path.abspath(os.getcwd())
 
 class CookerDataBuilder(object):
 
@@ -417,6 +414,9 @@  class CookerDataBuilder(object):
                         " invoked bitbake from the wrong directory?")
             raise SystemExit(msg)
 
+        if not data.getVar("TOPDIR"):
+            data.setVar("TOPDIR", os.path.abspath(os.getcwd()))
+
         data = parse_config_file(os.path.join("conf", "bitbake.conf"), data)
 
         # Parse files for loading *after* bitbake.conf and any includes