Skip to contentSkip to conversation

BBHandler: Allow earlier exit for classes not found

PATCH In review Richard Purdie 3 participants 7 messages Aug 10, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 BBHandler: Allow earlier exit for classes not found

Rather than relying on later code to error if the class isn't found, exit earlier and more clearly from a code perspective.

---
 lib/bb/parse/parse_py/BBHandler.py | 3 +++
 1 file changed, 3 insertions(+)
lib/bb/parse/parse_py/BBHandler.py +3 -0
index 68415735fd..532a4e08f1 100644
@@ -56,6 +56,9 @@ def inherit(files, fn, lineno, d):
             if abs_fn:
                 file = abs_fn
 
+        if not os.path.exists(file):
+            raise ParseError("Could not inherit file %s" % (file), fn, lineno)
+
         if not file in __inherit_cache:
             logger.debug("Inheriting %s (from %s:%d)" % (file, fn, lineno))
             __inherit_cache.append( file )
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/3 BBHandler: Make inherit calls more directly

Rather than recursing into the conf handler code, simply call into the parse code directly when inheriting files as we've already resolved the paths and don't need anything the other codepath brings. This makes the codepath clearer at the expense of some slight duplication.

---
 lib/bb/parse/parse_py/BBHandler.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/bb/parse/parse_py/BBHandler.py +4 -1
index 532a4e08f1..1189114341 100644
@@ -63,7 +63,10 @@ def inherit(files, fn, lineno, d):
             logger.debug("Inheriting %s (from %s:%d)" % (file, fn, lineno))
             __inherit_cache.append( file )
             d.setVar('__inherit_cache', __inherit_cache)
-            include(fn, file, lineno, d, "inherit")
+            try:
+                bb.parse.handle(file, d, True)
+            except (IOError, OSError) as exc:
+                raise ParseError("Could not inherit file %s: %s" % (fn, exc.strerror), fn, lineno)
             __inherit_cache = d.getVar('__inherit_cache', False) or []
 
 def get_statements(filename, absolute_filename, base_name):
Signature · 1 line
2.34.1
#2 lore raw

PATCH 3/3 BBHandler/cooker: Implement recipe and global classes

In reply to Richard Purdie

We have some confusion for users since some classes are meant to work in the configuration space (or "globally") and some are meant to be selected by recipes individually.

The cleanest way I could find to clarify this is to create "classes-global" and "classes-recipe" directories which contain the approproate classes and have bitbake switch scope between them at the appropriate point during parsing. The existing "classes" directory is always searched as a fallback.

Once a class is moved to a specific directory, it will no longer be found in the incorrect context. A good example from OE is that

INHERIT += "testimage"

will no longer work but

IMAGE_CLASSES += "testimage"

will, which makes the global scope cleaner by only including it where it is useful and intended to be used (images).

---
 lib/bb/cooker.py                   |  1 +
 lib/bb/cookerdata.py               |  2 ++
 lib/bb/parse/parse_py/BBHandler.py | 29 ++++++++++++++++++-----------
 3 files changed, 21 insertions(+), 11 deletions(-)
lib/bb/cooker.py +1 -0
index 2adf4d297d..1b6ee3032c 100644
@@ -402,6 +402,7 @@ class BBCooker:
         for mc in self.databuilder.mcdata.values():
             mc.renameVar("__depends", "__base_depends")
             self.add_filewatch(mc.getVar("__base_depends", False), self.configwatcher)
+            mc.setVar("__bbclasstype", "recipe")
 
         self.baseconfig_valid = True
         self.parsecache_valid = False
lib/bb/cookerdata.py +2 -0
index d54ac932e5..b3a171509b 100644
@@ -254,6 +254,7 @@ class CookerDataBuilder(object):
         filtered_keys = bb.utils.approved_variables()
         bb.data.inheritFromOS(self.basedata, self.savedenv, filtered_keys)
         self.basedata.setVar("BB_ORIGENV", self.savedenv)
+        self.basedata.setVar("__bbclasstype", "global")
 
         if worker:
             self.basedata.setVar("BB_WORKERCONTEXT", "1")
@@ -448,6 +449,7 @@ class CookerDataBuilder(object):
 
         # Handle any INHERITs and inherit the base class
         bbclasses  = ["base"] + (data.getVar('INHERIT') or "").split()
+        bb.warn(str(bbclasses))
         for bbclass in bbclasses:
             data = _inherit(bbclass, data)
 
lib/bb/parse/parse_py/BBHandler.py +18 -11
index 1189114341..18e6868387 100644
@@ -44,17 +44,24 @@ def inherit(files, fn, lineno, d):
     __inherit_cache = d.getVar('__inherit_cache', False) or []
     files = d.expand(files).split()
     for file in files:
-        if not os.path.isabs(file) and not file.endswith(".bbclass"):
-            file = os.path.join('classes', '%s.bbclass' % file)
-
-        if not os.path.isabs(file):
-            bbpath = d.getVar("BBPATH")
-            abs_fn, attempts = bb.utils.which(bbpath, file, history=True)
-            for af in attempts:
-                if af != abs_fn:
-                    bb.parse.mark_dependency(d, af)
-            if abs_fn:
-                file = abs_fn
+        classtype = d.getVar("__bbclasstype", False)
+        origfile = file
+        for t in ["classes-" + classtype, "classes"]:
+            file = origfile
+            if not os.path.isabs(file) and not file.endswith(".bbclass"):
+                file = os.path.join(t, '%s.bbclass' % file)
+
+            if not os.path.isabs(file):
+                bbpath = d.getVar("BBPATH")
+                abs_fn, attempts = bb.utils.which(bbpath, file, history=True)
+                for af in attempts:
+                    if af != abs_fn:
+                        bb.parse.mark_dependency(d, af)
+                if abs_fn:
+                    file = abs_fn
+
+            if os.path.exists(file):
+                break
 
         if not os.path.exists(file):
             raise ParseError("Could not inherit file %s" % (file), fn, lineno)
Signature · 1 line
2.34.1
#3 lore raw
In reply to Richard Purdie

I seeing

% bitbake binutils
WARNING: ['base', 'sanity-meta-odroid-extras', 'clang', 'report-error', 'image-buildinfo', 'package_ipk', 'buildhistory', 'buildstats', 'buildstats-summary', 'debian', 'devshell', 'sstate', 'license', 'remove-libtool', 'sanity']
ERROR: ParseError at /mnt/b/yoe/master/sources/openembedded-core/meta/classes/buildhistory.bbclass:10:
Could not inherit file classes/image-artifact-names.bbclass

Quoted 35 lines · Richard Purdie

Rather than relying on later code to error if the class isn't found, exit earlier and more clearly from a code perspective.

---
 lib/bb/parse/parse_py/BBHandler.py | 3 +++
 1 file changed, 3 insertions(+)
lib/bb/parse/parse_py/BBHandler.py +3 -1
index 68415735fd..532a4e08f1 100644
@@ -56,6 +56,9 @@ def inherit(files, fn, lineno, d):
             if abs_fn:
                 file = abs_fn
 
+        if not os.path.exists(file):
+            raise ParseError("Could not inherit file %s" % (file), fn, lineno)
+
         if not file in __inherit_cache:
             logger.debug("Inheriting %s (from %s:%d)" % (file, fn, lineno))
             __inherit_cache.append( file )
--

2.34.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#13880): https://lists.openembedded.org/g/bitbake-devel/message/13880
Mute This Topic: https://lists.openembedded.org/mt/92936457/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#4 lore raw
Quoted 10 lines · Khem Raj

I seeing

% bitbake binutils
WARNING: ['base', 'sanity-meta-odroid-extras', 'clang', 'report-error', 'image-buildinfo', 'package_ipk', 'buildhistory', 'buildstats', 'buildstats-summary', 'debian', 'devshell', 'sstate', 'license', 'remove-libtool', 'sanity']
ERROR: ParseError at /mnt/b/yoe/master/sources/openembedded-core/meta/classes/buildhistory.bbclass:10:
Could not inherit file classes/image-artifact-names.bbclass

I think we need something like:

meta/classes/buildhistory.bbclass +1 -1
index 4345ffc6939..203310ba975 100644
@@ -7,7 +7,7 @@
 # Copyright (C) 2007-2011 Koen Kooi <[email protected]>
 #
 
-inherit image-artifact-names
+IMAGE_CLASSES += "image-artifact-names"
 
 BUILDHISTORY_FEATURES ?= "image package sdk"
 BUILDHISTORY_DIR ?= "${TOPDIR}/buildhistory"

Does that help?

I need to remove that warning too! Although it does help debugging right now.

Cheers,

Richard

#5 lore raw

Can we not make the inherit command adapt to current inherit context, global or recipe?

Quoted 50 lines · Richard Purdie
Quoted 9 lines · Khem Raj

I seeing

% bitbake binutils
WARNING: ['base', 'sanity-meta-odroid-extras', 'clang', 'report-error', 'image-buildinfo', 'package_ipk', 'buildhistory', 'buildstats', 'buildstats-summary', 'debian', 'devshell', 'sstate', 'license', 'remove-libtool', 'sanity']
ERROR: ParseError at

/mnt/b/yoe/master/sources/openembedded-core/meta/classes/buildhistory.bbclass:10:

Quoted 1 line

Could not inherit file classes/image-artifact-names.bbclass

I think we need something like:

meta/classes/buildhistory.bbclass +1 -1
index 4345ffc6939..203310ba975 100644
@@ -7,7 +7,7 @@
 # Copyright (C) 2007-2011 Koen Kooi <[email protected]>
 #
 
-inherit image-artifact-names
+IMAGE_CLASSES += "image-artifact-names"
 
 BUILDHISTORY_FEATURES ?= "image package sdk"
 BUILDHISTORY_DIR ?= "${TOPDIR}/buildhistory"

Does that help?

I need to remove that warning too! Although it does help debugging right now.

Cheers,

Richard

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#13888):
https://lists.openembedded.org/g/bitbake-devel/message/13888
Mute This Topic: https://lists.openembedded.org/mt/92936457/3617123
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Signature · 4 lines
Christopher Larson
[email protected], [email protected], [email protected]
Principal Software Engineer, Embedded Linux Solutions, Siemens Digital
Industries Software
#6 lore raw
Quoted 2 lines · Christopher Larson

Can we not make the inherit command adapt to current inherit context, global or recipe?

The issue is that I'd made image-artifact-names a recipes class in OE- Core and it was trying to be pulled into the global space via buildhistory.

Either we accept it as a global class and change some of the users, or we make it image specific as I'm proposing in the patch.

Cheers,

Richard

Quoted 54 lines
Quoted 50 lines · Richard Purdie
Quoted 12 lines · Khem Raj

I seeing

% bitbake binutils
WARNING: ['base', 'sanity-meta-odroid-extras', 'clang', 'report-error', 'image-buildinfo', 'package_ipk', 'buildhistory', 'buildstats', 'buildstats-summary', 'debian', 'devshell', 'sstate',
'license', 'remove-libtool', 'sanity']
ERROR: ParseError at /mnt/b/yoe/master/sources/openembedded- core/meta/classes/buildhistory.bbclass:10:
Could not inherit file classes/image-artifact-names.bbclass

I think we need something like:

meta/classes/buildhistory.bbclass +1 -1
index 4345ffc6939..203310ba975 100644
@@ -7,7 +7,7 @@
  # Copyright (C) 2007-2011 Koen Kooi <[email protected]>
  #
 
-inherit image-artifact-names
+IMAGE_CLASSES += "image-artifact-names"
 

 BUILDHISTORY_FEATURES ?= "image package sdk"
 BUILDHISTORY_DIR ?= "${TOPDIR}/buildhistory"

Does that help?

I need to remove that warning too! Although it does help debugging right now.

Cheers,

Richard

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#13888):
https://lists.openembedded.org/g/bitbake-devel/message/13888
Mute This Topic: https://lists.openembedded.org/mt/92936457/3617123
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-