-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check LICENSE containing valid SPDX like code
Closes #426 Signed-off-by: Konrad Weihmann <[email protected]>
- Loading branch information
1 parent
c05e695
commit 7611388
Showing
3 changed files
with
68 additions
and
2 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
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,19 @@ | ||
from oelint_parser.cls_item import Variable | ||
from oelint_adv.cls_rule import Rule | ||
|
||
|
||
class LicenseSDPX(Rule): | ||
def __init__(self): | ||
super().__init__(id='oelint.vars.licensesdpx', | ||
severity='warning', | ||
message='LICENSE is not a valid OpenEmbedded SPDX expression') | ||
|
||
def check(self, _file, stash): | ||
res = [] | ||
items = stash.GetItemsFor(filename=_file, classifier=Variable.CLASSIFIER, | ||
attribute=Variable.ATTR_VAR) | ||
for i in [x for x in items if x.VarName == 'LICENSE']: | ||
if (('|' in i.VarValueStripped and ' | ' not in i.VarValueStripped) or | ||
('&' in i.VarValueStripped and ' & ' not in i.VarValueStripped)): | ||
res += self.finding(i.Origin, i.InFileLine) | ||
return res |
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,47 @@ | ||
import pytest # noqa: I900 | ||
|
||
from .base import TestBaseClass | ||
|
||
|
||
class TestClassOelintVarLicenseSPDX(TestBaseClass): | ||
|
||
@pytest.mark.parametrize('id_', ['oelint.vars.licensesdpx']) | ||
@pytest.mark.parametrize('occurrence', [1]) | ||
@pytest.mark.parametrize('input_', | ||
[ | ||
{ | ||
'oelint_adv_test.bb': | ||
''' | ||
LICENSE:a = "ISC &MIT" | ||
''', | ||
}, | ||
{ | ||
'oelint_adv_test.bb': | ||
''' | ||
LICENSE:e = "(ISC|MIT) & Apache-2.0 & BSD-3-Clause" | ||
''', | ||
}, | ||
], | ||
) | ||
def test_bad(self, input_, id_, occurrence): | ||
self.check_for_id(self._create_args(input_), id_, occurrence) | ||
|
||
@pytest.mark.parametrize('id_', ['oelint.var.licensesdpx']) | ||
@pytest.mark.parametrize('occurrence', [0]) | ||
@pytest.mark.parametrize('input_', | ||
[ | ||
{ | ||
'oelint_adv_test.bb': | ||
''' | ||
LICENSE:${PN} = "BSD-2-Clause" | ||
LICENSE:b = "(ISC | MIT)" | ||
LICENSE:c = "(BSD-2-Clause | MIT)" | ||
LICENSE:d = "(BSD-2-Clause | MIT) & MIT" | ||
LICENSE:f = "BSD-3-Clause" | ||
LICENSE = "Unknown" | ||
''', | ||
}, | ||
], | ||
) | ||
def test_good(self, input_, id_, occurrence): | ||
self.check_for_id(self._create_args(input_), id_, occurrence) |