Skip to content

Commit

Permalink
oelint.vars.layerconf: add new rule
Browse files Browse the repository at this point in the history
to check that only layer.conf specific variables
are set in a layer.conf

Relates to #607

Signed-off-by: Konrad Weihmann <[email protected]>
  • Loading branch information
priv-kweihmann committed Sep 3, 2024
1 parent 8fa2245 commit deeb63a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
31 changes: 31 additions & 0 deletions docs/wiki/oelint.vars.layerconf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# oelint.vars.layerconf

severity: warn

## Example

```
IMAGE_INSTALL += "my-recipe"
```

## Why is this bad?

A setting from a ``layer.conf`` becomes effective, just by including the layer into the build.
Adding settings beyond the pure layer configuration should be reserved for machine, distro or image configuration.

## Ways to fix it

Only the following variables should be set as part of a ``layer.conf``

- BBFILES
- BBFILES_DYNAMIC
- BBFILE_COLLECTIONS
- BBFILE_PATTERN_.*
- BBFILE_PRIORITY_.*
- BBPATH
- HOSTTOOLS_NONFATAL
- LAYERDEPENDS_.*
- LAYERRECOMMENDS_.*
- LAYERSERIES_COMPAT_.*
- LAYERVERSION_.*
- LICENSE_PATH
43 changes: 43 additions & 0 deletions oelint_adv/rule_base/rule_vars_layerconf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import fnmatch
from typing import List, Tuple

from oelint_parser.cls_item import Variable
from oelint_parser.cls_stash import Stash
from oelint_parser.rpl_regex import RegexRpl

from oelint_adv.cls_rule import Rule


class VarsLayerConf(Rule):
def __init__(self) -> None:
self.good = [
r'BBFILES',
r'BBFILES_DYNAMIC',
r'BBFILE_COLLECTIONS',
r'BBFILE_PATTERN_.*',
r'BBFILE_PRIORITY_.*',
r'BBPATH',
r'HOSTTOOLS_NONFATAL',
r'LAYERDEPENDS_.*',
r'LAYERRECOMMENDS_.*',
r'LAYERSERIES_COMPAT_.*',
r'LAYERVERSION_.*',
r'LICENSE_PATH',
]

super().__init__(id='oelint.vars.layerconf',
severity='warn',
message='{var} should not be set as part of a layer configuration')

def check(self, _file: str, stash: Stash) -> List[Tuple[str, int, str]]:
res = []
items: List[Variable] = stash.GetItemsFor(filename=_file, classifier=Variable.CLASSIFIER,
attribute=Variable.ATTR_VAR)

for i in items:
if not fnmatch.fnmatch(i.Origin, '*/layer.conf'):
continue
if not any(RegexRpl.match(x, i.VarName) for x in self.good):
res += self.finding(_file, i.Line,
self.Msg.format(var=i.VarName))
return res

0 comments on commit deeb63a

Please sign in to comment.