-
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.
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
1 parent
8fa2245
commit deeb63a
Showing
2 changed files
with
74 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,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 |
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,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 |