Skip to contentSkip to conversation

Ensure that BBFILE_COLLECTIONS and BBPATH exist at add-layers and parsing

PATCH In review Talel BELHAJSALEM 2 participants 6 messages Oct 10, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Ensure that BBFILE_COLLECTIONS and BBPATH exist at add-layers and parsing

Empty layer.conf is added to bblayers.conf and not shown by show-layers.

It will have no effect on BBFILES or BBPATH so no need to add it in the first place.

Other than this, when working with the layer.conf variables, I noticed the following:

1) No BBFILE_COLLECTIONS will lead to no effect for BBFILE_PATTERN, so BBFILES on its own work well.
2) No BBFILE_COLLECTIONS and no BBPATH with BBFILES set to a directoy will work as well but custom inherits will fail only if the recipe matches: meta-*/*.bb. So checking on BBPATH will also fix this.

In conclusion any messing around with layer.conf's variables will lead to unexpected behavior.

Making sure BBFILE_COLLECTIONS exist will ensure:
- error if no LAYERSERIES_COMPAT
- error if no BBFILE_PATTERN
- warning if no BBFILES
- Layer shown in (bitbake-layers show-layers)

Making sure BBPATH exist will ensure that classes and conf found regardless of BBFILES content (it can be a directory that will trigger find_bbfiles)

---
 bitbake/lib/bb/cooker.py       |  2 +-
 bitbake/lib/bb/cookerdata.py   |  7 ++++++-
 bitbake/lib/bblayers/action.py | 26 ++++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
bitbake/lib/bb/cooker.py +1 -1
index 2adf4d297d..f163d3a2a3 100644
@@ -1827,7 +1827,7 @@ class CookerCollectFiles(object):
             for ignored in ('SCCS', 'CVS', '.svn'):
                 if ignored in dirs:
                     dirs.remove(ignored)
-            found += [os.path.join(dir, f) for f in files if (f.endswith(['.bb', '.bbappend']))]
+            found += [os.path.join(dir, f) for f in files if (f.endswith(('.bb', '.bbappend')))]
 
         return found
 
bitbake/lib/bb/cookerdata.py +6 -1
index ec3741cc1d..fd1e0cf06f 100644
@@ -18,6 +18,7 @@ from functools import wraps
 import bb
 from bb import data
 import bb.parse
+from bblayers.action import ActionPlugin
 
 logger      = logging.getLogger("BitBake")
 parselog    = logging.getLogger("BitBake.Parsing")
@@ -377,7 +378,11 @@ class CookerDataBuilder(object):
                     layer = layer.rstrip('/')
                 data.setVar('LAYERDIR', layer)
                 data.setVar('LAYERDIR_RE', re.escape(layer))
-                data = parse_config_file(os.path.join(layer, "conf", "layer.conf"), data)
+                layer_conf = os.path.join(layer, "conf", "layer.conf")
+                res, msg = ActionPlugin.do_check_layer(layer_conf)
+                if not res:
+                    bb.fatal(msg)
+                data = parse_config_file(layer_conf, data)
                 data.expandVarref('LAYERDIR')
                 data.expandVarref('LAYERDIR_RE')
 
bitbake/lib/bblayers/action.py +26 -0
index 454c251410..5a2fcf7f8f 100644
@@ -23,6 +23,27 @@ def plugin_init(plugins):
 
 
 class ActionPlugin(LayerPlugin):
+
+    def do_check_layer(path):
+        """
+        make sure that BBFILE_COLLECTIONS and BBPATH are found in layer.conf
+        they should exist in non-commented lines
+        """
+        def _is_found(var, line):
+                return var in line and not line.startswith('#')
+
+        with open(path) as layer_conf_fd:
+            lines = layer_conf_fd.readlines()
+            find_result = {}
+            for to_find in ['BBFILE_COLLECTIONS', 'BBPATH']:
+                for line in lines:
+                    find_result[to_find] = True if _is_found(to_find, line) else False
+                    if find_result[to_find]:
+                        break
+                if not find_result[to_find]:
+                    return False, "Specified layer configuration %s doesn't contain %s\n" % (path, to_find)
+        return True, ""
+
     def do_add_layer(self, args):
         """Add one or more layers to bblayers.conf."""
         layerdirs = [os.path.abspath(ldir) for ldir in args.layerdir]
@@ -37,6 +58,11 @@ class ActionPlugin(LayerPlugin):
                 sys.stderr.write("Specified layer directory %s doesn't contain a conf/layer.conf file\n" % layerdir)
                 return 1
 
+            res, msg = ActionPlugin.do_check_layer(layer_conf)
+            if not res:
+                sys.stderr.write(msg)
+                return 1
+
         bblayers_conf = os.path.join('conf', 'bblayers.conf')
         if not os.path.exists(bblayers_conf):
             sys.stderr.write("Unable to find bblayers.conf\n")
Signature · 1 line
2.25.1
#1 lore raw

I was coding this at 2 in the morning then I realized a simple check on the start of the line for a given variable is enough.
But also it can be a pattern for BBFILE_COLLECTIONS or other ideas. This can be fixed, but I need a review on the idea itself first.

Kind regards
Talel

Quoted 129 lines · Talel BELHAJSALEM

Empty layer.conf is added to bblayers.conf and not shown by show-layers.

It will have no effect on BBFILES or BBPATH so no need to add it in the first place.

Other than this, when working with the layer.conf variables, I noticed the following:

1) No BBFILE_COLLECTIONS will lead to no effect for BBFILE_PATTERN, so BBFILES on its own work well.
2) No BBFILE_COLLECTIONS and no BBPATH with BBFILES set to a directoy will work as well but custom inherits will fail only if the recipe matches:
meta-*/*.bb.
So checking on BBPATH will also fix this.

In conclusion any messing around with layer.conf's variables will lead to unexpected behavior.

Making sure BBFILE_COLLECTIONS exist will ensure:
- error if no LAYERSERIES_COMPAT
- error if no BBFILE_PATTERN
- warning if no BBFILES
- Layer shown in (bitbake-layers show-layers)

Making sure BBPATH exist will ensure that classes and conf found regardless of BBFILES content (it can be a directory that will trigger find_bbfiles)

---
 bitbake/lib/bb/cooker.py       |  2 +-
 bitbake/lib/bb/cookerdata.py   |  7 ++++++-
 bitbake/lib/bblayers/action.py | 26 ++++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
bitbake/lib/bb/cooker.py +0 -1
index 2adf4d297d..f163d3a2a3 100644
@@ -1827,7 +1827,7 @@ class CookerCollectFiles(object):
             for ignored in ('SCCS', 'CVS', '.svn'):
                 if ignored in dirs:
                     dirs.remove(ignored)
-            found += [os.path.join(dir, f) for f in files if

(f.endswith(['.bb', '.bbappend']))]
+ found += [os.path.join(dir, f) for f in files if
(f.endswith(('.bb', '.bbappend')))]

return found

bitbake/lib/bb/cookerdata.py +6 -1
index ec3741cc1d..fd1e0cf06f 100644
@@ -18,6 +18,7 @@ from functools import wraps
 import bb
 from bb import data
 import bb.parse
+from bblayers.action import ActionPlugin
 
 logger      = logging.getLogger("BitBake")
 parselog    = logging.getLogger("BitBake.Parsing")
@@ -377,7 +378,11 @@ class CookerDataBuilder(object):
                     layer = layer.rstrip('/')
                 data.setVar('LAYERDIR', layer)
                 data.setVar('LAYERDIR_RE', re.escape(layer))
-                data = parse_config_file(os.path.join(layer, "conf",
 "layer.conf"), data)
+                layer_conf = os.path.join(layer, "conf", "layer.conf")
+                res, msg = ActionPlugin.do_check_layer(layer_conf)
+                if not res:
+                    bb.fatal(msg)
+                data = parse_config_file(layer_conf, data)
                 data.expandVarref('LAYERDIR')
                 data.expandVarref('LAYERDIR_RE')
bitbake/lib/bblayers/action.py +4 -0
index 454c251410..5a2fcf7f8f 100644
@@ -23,6 +23,27 @@ def plugin_init(plugins):
 
 
 class ActionPlugin(LayerPlugin):
+
+    def do_check_layer(path):
+        """
+        make sure that BBFILE_COLLECTIONS and BBPATH are found in

layer.conf

bitbake/lib/bblayers/action.py +11 -0
+        they should exist in non-commented lines
+        """
+        def _is_found(var, line):
+                return var in line and not line.startswith('#')
+
+        with open(path) as layer_conf_fd:
+            lines = layer_conf_fd.readlines()
+            find_result = {}
+            for to_find in ['BBFILE_COLLECTIONS', 'BBPATH']:
+                for line in lines:
+                    find_result[to_find] = True if _is_found(to_find,

line) else False

bitbake/lib/bblayers/action.py +4 -0
+                    if find_result[to_find]:
+                        break
+                if not find_result[to_find]:
+                    return False, "Specified layer configuration %s

doesn't contain %s\n" % (path, to_find)

bitbake/lib/bblayers/action.py +7 -0
+        return True, ""
+
     def do_add_layer(self, args):
         """Add one or more layers to bblayers.conf."""
         layerdirs = [os.path.abspath(ldir) for ldir in args.layerdir]
@@ -37,6 +58,11 @@ class ActionPlugin(LayerPlugin):
                 sys.stderr.write("Specified layer directory %s doesn't
 contain a conf/layer.conf file\n" % layerdir)
                 return 1
 
+            res, msg = ActionPlugin.do_check_layer(layer_conf)
+            if not res:
+                sys.stderr.write(msg)
+                return 1
+
         bblayers_conf = os.path.join('conf', 'bblayers.conf')
         if not os.path.exists(bblayers_conf):

sys.stderr.write("Unable to find bblayers.conf\n")
--
2.25.1

#2 lore raw
In reply to Talel BELHAJSALEM
Quoted 32 lines · BELHADJ SALEM Talel

Empty layer.conf is added to bblayers.conf and not shown by show-layers.

It will have no effect on BBFILES or BBPATH so no need to add it in the first place.

Other than this, when working with the layer.conf variables, I noticed the following:

1) No BBFILE_COLLECTIONS will lead to no effect for BBFILE_PATTERN, so BBFILES on its own work well.
2) No BBFILE_COLLECTIONS and no BBPATH with BBFILES set to a directoy will work as well but custom inherits will fail only if the recipe matches: meta-*/*.bb. So checking on BBPATH will also fix this.

In conclusion any messing around with layer.conf's variables will lead to unexpected behavior.

Making sure BBFILE_COLLECTIONS exist will ensure:
- error if no LAYERSERIES_COMPAT
- error if no BBFILE_PATTERN
- warning if no BBFILES
- Layer shown in (bitbake-layers show-layers)

Making sure BBPATH exist will ensure that classes and conf found regardless of BBFILES content (it can be a directory that will trigger find_bbfiles)

---
 bitbake/lib/bb/cooker.py       |  2 +-
 bitbake/lib/bb/cookerdata.py   |  7 ++++++-
 bitbake/lib/bblayers/action.py | 26 ++++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
bitbake/lib/bb/cooker.py +0 -0
index 2adf4d297d..f163d3a2a3 100644

bitbake/lib/bb/cooker.py class CookerCollectFiles(object): · line 1832

Quoted 7 lines
bitbake/lib/bb/cooker.py +1 -1
@@ -1827,7 +1827,7 @@ class CookerCollectFiles(object):
             for ignored in ('SCCS', 'CVS', '.svn'):
                 if ignored in dirs:
                     dirs.remove(ignored)
-            found += [os.path.join(dir, f) for f in files if (f.endswith(['.bb', '.bbappend']))]
+            found += [os.path.join(dir, f) for f in files if (f.endswith(('.bb', '.bbappend')))]
 
         return found

I think this piece should become a separate commit.

Quoted 45 lines
bitbake/lib/bb/cookerdata.py +6 -1
index ec3741cc1d..fd1e0cf06f 100644
@@ -18,6 +18,7 @@ from functools import wraps
 import bb
 from bb import data
 import bb.parse
+from bblayers.action import ActionPlugin
 
 logger      = logging.getLogger("BitBake")
 parselog    = logging.getLogger("BitBake.Parsing")
@@ -377,7 +378,11 @@ class CookerDataBuilder(object):
                     layer = layer.rstrip('/')
                 data.setVar('LAYERDIR', layer)
                 data.setVar('LAYERDIR_RE', re.escape(layer))
-                data = parse_config_file(os.path.join(layer, "conf", "layer.conf"), data)
+                layer_conf = os.path.join(layer, "conf", "layer.conf")
+                res, msg = ActionPlugin.do_check_layer(layer_conf)
+                if not res:
+                    bb.fatal(msg)
+                data = parse_config_file(layer_conf, data)
                 data.expandVarref('LAYERDIR')
                 data.expandVarref('LAYERDIR_RE')
 
bitbake/lib/bblayers/action.py +11 -0
index 454c251410..5a2fcf7f8f 100644
@@ -23,6 +23,27 @@ def plugin_init(plugins):
 
 
 class ActionPlugin(LayerPlugin):
+
+    def do_check_layer(path):
+        """
+        make sure that BBFILE_COLLECTIONS and BBPATH are found in layer.conf
+        they should exist in non-commented lines
+        """
+        def _is_found(var, line):
+                return var in line and not line.startswith('#')
+
+        with open(path) as layer_conf_fd:
+            lines = layer_conf_fd.readlines()

bitbake/lib/bblayers/action.py def plugin_init(plugins): · line 46

Quoted 10 lines
bitbake/lib/bblayers/action.py +10 -0
+            find_result = {}
+            for to_find in ['BBFILE_COLLECTIONS', 'BBPATH']:
+                for line in lines:
+                    find_result[to_find] = True if _is_found(to_find, line) else False
+                    if find_result[to_find]:
+                        break
+                if not find_result[to_find]:
+                    return False, "Specified layer configuration %s doesn't contain %s\n" % (path, to_find)
+        return True, ""
+

I don't think writing a new parser is a great idea. There are other ways we could detect if those variables were set/changed.

I'd also question whether this is correct. It would be perfectly fine for a layer just to add python library files using addpylib for example and not set BB_FILE_COLLECTIONS or BBPATH.

Cheers,

Richard

#3 lore raw

Hello Richard

Thanks for the reply,

Regarding the second comment:

Do you mean using addpylib can be an alternative for not setting BBFILE_COLLECTIONS and BBPATH ? If yes, I can't see an example on how to do that.

Kind regards,
Talel

Quoted 125 lines · Richard Purdie
Quoted 3 lines · BELHADJ SALEM Talel

Empty layer.conf is added to bblayers.conf and not shown by show-layers.

It will have no effect on BBFILES or BBPATH so no need to add it in the

first place.

Quoted 2 lines

Other than this, when working with the layer.conf variables, I noticed

the following:

Quoted 2 lines

1) No BBFILE_COLLECTIONS will lead to no effect for BBFILE_PATTERN, so

BBFILES on its own work well.

Quoted 1 line

2) No BBFILE_COLLECTIONS and no BBPATH with BBFILES set to a directoy

will work as well but custom inherits will fail only if the recipe matches:
meta-*/*.bb.

Quoted 3 lines

So checking on BBPATH will also fix this.

In conclusion any messing around with layer.conf's variables will lead

to unexpected behavior.

Quoted 8 lines

Making sure BBFILE_COLLECTIONS exist will ensure:
- error if no LAYERSERIES_COMPAT
- error if no BBFILE_PATTERN
- warning if no BBFILES
- Layer shown in (bitbake-layers show-layers)

Making sure BBPATH exist will ensure that classes and conf found

regardless of BBFILES content (it can be a directory that will trigger find_bbfiles)

Quoted 13 lines
---
 bitbake/lib/bb/cooker.py       |  2 +-
 bitbake/lib/bb/cookerdata.py   |  7 ++++++-
 bitbake/lib/bblayers/action.py | 26 ++++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
bitbake/lib/bb/cooker.py +0 -0
index 2adf4d297d..f163d3a2a3 100644

bitbake/lib/bb/cooker.py class CookerCollectFiles(object): · line 1830

Quoted 4 lines
bitbake/lib/bb/cooker.py +0 -1
@@ -1827,7 +1827,7 @@ class CookerCollectFiles(object):
             for ignored in ('SCCS', 'CVS', '.svn'):
                 if ignored in dirs:
                     dirs.remove(ignored)
-            found += [os.path.join(dir, f) for f in files if

(f.endswith(['.bb', '.bbappend']))]

bitbake/lib/bb/cooker.py class CookerCollectFiles(object): · line 1830

Quoted 1 line
bitbake/lib/bb/cooker.py +1 -0
+            found += [os.path.join(dir, f) for f in files if

(f.endswith(('.bb', '.bbappend')))]

bitbake/lib/bb/cooker.py class CookerCollectFiles(object): · line 1832

Quoted 2 lines
bitbake/lib/bb/cooker.py +0 -0
         return found

I think this piece should become a separate commit.

Quoted 14 lines
bitbake/lib/bb/cookerdata.py +1 -0
index ec3741cc1d..fd1e0cf06f 100644
@@ -18,6 +18,7 @@ from functools import wraps
 import bb
 from bb import data
 import bb.parse
+from bblayers.action import ActionPlugin
 
 logger      = logging.getLogger("BitBake")
 parselog    = logging.getLogger("BitBake.Parsing")

bitbake/lib/bb/cookerdata.py class CookerDataBuilder(object): · line 380

Quoted 4 lines
bitbake/lib/bb/cookerdata.py +0 -1
@@ -377,7 +378,11 @@ class CookerDataBuilder(object):
                     layer = layer.rstrip('/')
                 data.setVar('LAYERDIR', layer)
                 data.setVar('LAYERDIR_RE', re.escape(layer))
-                data = parse_config_file(os.path.join(layer, "conf",

"layer.conf"), data)

Review

Quoted 9 lines
bitbake/lib/bb/cookerdata.py +5 -0
+                layer_conf = os.path.join(layer, "conf", "layer.conf")
+                res, msg = ActionPlugin.do_check_layer(layer_conf)
+                if not res:
+                    bb.fatal(msg)
+                data = parse_config_file(layer_conf, data)
                 data.expandVarref('LAYERDIR')
                 data.expandVarref('LAYERDIR_RE')
 
(quoted diff) +0 -0

b/bitbake/lib/bblayers/action.py

bitbake/lib/bblayers/action.py def plugin_init(plugins): · line 29

Quoted 11 lines

index 454c251410..5a2fcf7f8f 100644

bitbake/lib/bblayers/action.py +4 -0
@@ -23,6 +23,27 @@ def plugin_init(plugins):
 
 
 class ActionPlugin(LayerPlugin):
+
+    def do_check_layer(path):
+        """
+        make sure that BBFILE_COLLECTIONS and BBPATH are found in

layer.conf

bitbake/lib/bblayers/action.py def plugin_init(plugins):

Quoted 11 lines
bitbake/lib/bblayers/action.py +11 -0
+        they should exist in non-commented lines
+        """
+        def _is_found(var, line):
+                return var in line and not line.startswith('#')
+
+        with open(path) as layer_conf_fd:
+            lines = layer_conf_fd.readlines()
+            find_result = {}
+            for to_find in ['BBFILE_COLLECTIONS', 'BBPATH']:
+                for line in lines:
+                    find_result[to_find] = True if _is_found(to_find,

line) else False

bitbake/lib/bblayers/action.py def plugin_init(plugins):

Quoted 4 lines
bitbake/lib/bblayers/action.py +4 -0
+                    if find_result[to_find]:
+                        break
+                if not find_result[to_find]:
+                    return False, "Specified layer configuration %s

doesn't contain %s\n" % (path, to_find)

bitbake/lib/bblayers/action.py def plugin_init(plugins): · line 46

Quoted 2 lines
bitbake/lib/bblayers/action.py +2 -0
+        return True, ""
+

I don't think writing a new parser is a great idea. There are other ways we could detect if those variables were set/changed.

I'd also question whether this is correct. It would be perfectly fine for a layer just to add python library files using addpylib for example and not set BB_FILE_COLLECTIONS or BBPATH.

Cheers,

Richard

#4 lore raw
Quoted 7 lines · Talel BELHADJ SALEM

Thanks for the reply,

Regarding the second comment:

Do you mean using addpylib can be an alternative for not setting BBFILE_COLLECTIONS and BBPATH ? If yes, I can't see an example on how to do that.

Layers don't have to contain recipes. Whether or not there is an example, a layer with just library functions would be a valid layer and I'm not taking patches which show them as invalid.

Cheers,

Richard

#5 lore raw

"*Layers don't have to contain recipes*" is what I missed in the first place that led me to this analysis. I think it should stand out in the documentation as well.

So, I think I will keep the first patch of find_bbfiles.

Do you have any further ideas for BBFILE_COLLECTIONS and BBPATH ? Because still show-layers are based on BBFILE_COLLECTIONS, is it expected behavior or it should be fixed ?

Kind regards
Talel

Quoted 18 lines · Richard Purdie
Quoted 7 lines · Talel BELHADJ SALEM

Thanks for the reply,

Regarding the second comment:

Do you mean using addpylib can be an alternative for not setting BBFILE_COLLECTIONS and BBPATH ? If yes, I can't see an example on how to do that.

Layers don't have to contain recipes. Whether or not there is an example, a layer with just library functions would be a valid layer and I'm not taking patches which show them as invalid.

Cheers,

Richard