Skip to content

Commit

Permalink
oelint.vars.srcurioptions: add usehead implications
Browse files Browse the repository at this point in the history
as usehead implies nobranch, add that to the branch check.
Furthermore check that branch or nobranch is set
when usehead is used.

Closes #621

Signed-off-by: Konrad Weihmann <[email protected]>
  • Loading branch information
priv-kweihmann committed Oct 13, 2024
1 parent 8c322e0 commit 425b267
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
15 changes: 13 additions & 2 deletions oelint_adv/rule_base/rule_var_src_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,13 @@ def __init__(self) -> None:
}

self._required_unless_options = {
'git': {'branch': ['nobranch']},
'gitsm': {'branch': ['nobranch']},
'git': {'branch': ['nobranch', 'usehead']},
'gitsm': {'branch': ['nobranch', 'usehead']},
}

self._required_if_options = {
'git': {'usehead': ['branch', 'nobranch']},
'gitsm': {'usehead': ['branch', 'nobranch']},
}

def __analyse(self, stash: Stash, item: Variable, _input: str, _index: int) -> List[Tuple[str, int, str]]:
Expand Down Expand Up @@ -188,6 +193,12 @@ def __analyse(self, stash: Stash, item: Variable, _input: str, _index: int) -> L
'Fetcher \'{fetcher}\' requires option \'{option}\' or any of \'{other}\' to be set'.format(
fetcher=_url['scheme'], option=key, other=','.join(val_)),
blockoffset=item.InFileLine)
for key, val_ in self._required_if_options.get(_url['scheme'], {}).items():
if key in _url['options'] and not any(x in _url['options'] for x in val_):
res += self.finding(item.Origin, item.InFileLine + _index,
'Fetcher \'{fetcher}\' option \'{option}\' requires any of \'{other}\' to be set'.format(
fetcher=_url['scheme'], option=key, other=','.join(val_)),
blockoffset=item.InFileLine)
return res

def check(self, _file: str, stash: Stash) -> List[Tuple[str, int, str]]:
Expand Down
24 changes: 24 additions & 0 deletions tests/test_class_oelint_vars_srcurireqopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class TestClassOelintVarsSRCURIReqOpt(TestBaseClass):
{
'oelint_adv_test.bb':
'SRC_URI += "gitsm://foo.org/gaz.git;name=foo;protocol=ssh"',
},
{
'oelint_adv_test.bb':
'SRC_URI += "git://foo.org/gaz.git;protocol=ssh;usehead=1"',
},
{
'oelint_adv_test.bb':
'SRC_URI += "gitsm://foo.org/gaz.git;protocol=ssh;usehead=1"',
},
],
)
Expand Down Expand Up @@ -67,6 +75,22 @@ def test_really_bad(self, input_, id_, occurrence):
'oelint_adv_test.bb':
'SRC_URI += "gitsm://foo.org/gaz.git;name=foo;protocol=ssh;nobranch=1"',
},
{
'oelint_adv_test.bb':
'SRC_URI += "git://foo.org/gaz.git;name=foo;protocol=ssh;nobranch=1;usehead=1"',
},
{
'oelint_adv_test.bb':
'SRC_URI += "gitsm://foo.org/gaz.git;name=foo;protocol=ssh;nobranch=1;usehead=1"',
},
{
'oelint_adv_test.bb':
'SRC_URI += "git://foo.org/gaz.git;name=foo;protocol=ssh;branch=main;usehead=1"',
},
{
'oelint_adv_test.bb':
'SRC_URI += "gitsm://foo.org/gaz.git;name=foo;protocol=ssh;branch=main;usehead=1"',
},
{
'oelint-adv_test.bb':
'''
Expand Down

0 comments on commit 425b267

Please sign in to comment.