Skip to content

Commit

Permalink
oelint.vars.distroconf: add new rule
Browse files Browse the repository at this point in the history
to check on discouraged variables in
distro configurations

Relates to #607

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

severity: warn

## Example

```
IMAGE_INSTALL += "my-recipe"
MACHINE_FEATURES:append = " vfat"
```

## Why is this bad?

Image and or machine specific settings should not be set by a distro configuration.

## Ways to fix it

Avoid using any of the following variables in a distro configuration

- MACHINE
- MACHINE_ARCH
- MACHINE_ESSENTIAL_EXTRA_RDEPENDS
- MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS
- MACHINE_EXTRA_RRECOMMENDS
- MACHINE_FEATURES
- MACHINE_FEATURES_BACKFILL
- MACHINE_FEATURES_BACKFILL_CONSIDERED
- IMAGE_INSTALL
- MACHINEOVERRIDES
41 changes: 41 additions & 0 deletions oelint_adv/rule_base/rule_vars_distroconf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import fnmatch
from typing import List, Tuple

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

from oelint_adv.cls_rule import Rule


class VarsDistroConf(Rule):
def __init__(self) -> None:
self.needles = [
'MACHINE',
'MACHINE_ARCH',
'MACHINE_ESSENTIAL_EXTRA_RDEPENDS',
'MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS',
'MACHINE_EXTRA_RRECOMMENDS',
'MACHINE_FEATURES',
'MACHINE_FEATURES_BACKFILL',
'MACHINE_FEATURES_BACKFILL_CONSIDERED',
'IMAGE_INSTALL',
'MACHINEOVERRIDES',
]

super().__init__(id='oelint.vars.distroconf',
severity='warn',
message='{var} should not be set as part of a distro configuration',
appendix=self.needles)

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, '*/distro/*.conf'):
continue
if i.VarName in self.needles:
res += self.finding(_file, i.Line,
self.Msg.format(var=i.VarName), appendix=i.VarName)
return res

0 comments on commit 8fa2245

Please sign in to comment.