-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
oelint.vars.distroconf: add new rule
to check on discouraged variables in distro configurations Relates to #607 Signed-off-by: Konrad Weihmann <[email protected]>
- Loading branch information
1 parent
80ecca8
commit 8fa2245
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |