Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/621 #628

Merged
merged 2 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions oelint_adv/rule_base/rule_var_src_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ def __init__(self) -> None:
'protocol',
'scmdata',
],
'crate': [],
'crate': [
'downloadfilename',
],
'crcc': [
'module',
'proto',
'protocol',
'vob',
],
'cvs': [
Expand Down Expand Up @@ -88,6 +90,22 @@ def __init__(self) -> None:
'destdir',
'proto',
],
'gomod': [
'downloadfilename',
'mod',
'module',
'version',
],
'gomodgit': [
'bareclone',
'branch',
'module',
'nobranch',
'protocol',
'repo',
'srcrev',
'version',
],
'hg': [
'module',
'rev',
Expand Down Expand Up @@ -148,11 +166,18 @@ def __init__(self) -> None:
self._required_might_options = {
'git': ['protocol'],
'gitsm': ['protocol'],
'gomod': ['version'],
'gomodgit': ['version'],
}

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 +213,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
63 changes: 60 additions & 3 deletions tests/test_class_oelint_vars_srcurioptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
'crate': [
'apply',
'destsuffix',
'downloadfilename',
'name',
'patchdir',
'striplevel',
Expand All @@ -77,7 +78,7 @@
'module',
'name',
'patchdir',
'proto',
'protocol',
'striplevel',
'subdir',
'unpack',
Expand Down Expand Up @@ -176,6 +177,22 @@
'name',
'proto',
],
'gomod': [
'downloadfilename',
'mod',
'module',
'version',
],
'gomodgit': [
'bareclone',
'branch',
'module',
'nobranch',
'protocol',
'repo',
'srcrev',
'version',
],
'hg': [
'apply',
'destsuffix',
Expand Down Expand Up @@ -372,7 +389,7 @@ def test_good_bzr(self, id_, occurrence, protocol, option):
@pytest.mark.parametrize('id_', ['oelint.vars.srcurioptions'])
@pytest.mark.parametrize('occurrence', [1])
@pytest.mark.parametrize('protocol', ['crate'])
@pytest.mark.parametrize('option', [x for x in OPTIONS_AVAILABLE if x not in OPTION_MAPPING['az']])
@pytest.mark.parametrize('option', [x for x in OPTIONS_AVAILABLE if x not in OPTION_MAPPING['crate']])
def test_bad_crate(self, id_, occurrence, protocol, option):
input_ = {
'oelint_adv_test.bb': self.__generate_sample_code(protocol, option),
Expand All @@ -382,7 +399,7 @@ def test_bad_crate(self, id_, occurrence, protocol, option):
@pytest.mark.parametrize('id_', ['oelint.vars.srcurioptions'])
@pytest.mark.parametrize('occurrence', [0])
@pytest.mark.parametrize('protocol', ['crate'])
@pytest.mark.parametrize('option', OPTION_MAPPING['az'])
@pytest.mark.parametrize('option', OPTION_MAPPING['crate'])
def test_good_crate(self, id_, occurrence, protocol, option):
input_ = {
'oelint_adv_test.bb': self.__generate_sample_code(protocol, option),
Expand Down Expand Up @@ -545,6 +562,46 @@ def test_good_gitannex(self, id_, occurrence, protocol, option):
}
self.check_for_id(self._create_args(input_), id_, occurrence)

@pytest.mark.parametrize('id_', ['oelint.vars.srcurioptions'])
@pytest.mark.parametrize('occurrence', [1])
@pytest.mark.parametrize('protocol', ['gomod'])
@pytest.mark.parametrize('option', ['xyz', 'abc'])
def test_bad_gomod(self, id_, occurrence, protocol, option):
input_ = {
'oelint_adv_test.bb': self.__generate_sample_code(protocol, 'version=1;' + option),
}
self.check_for_id(self._create_args(input_), id_, occurrence)

@pytest.mark.parametrize('id_', ['oelint.vars.srcurioptions'])
@pytest.mark.parametrize('occurrence', [0])
@pytest.mark.parametrize('protocol', ['gomod'])
@pytest.mark.parametrize('option', OPTION_MAPPING['gomod'])
def test_good_gomod(self, id_, occurrence, protocol, option):
input_ = {
'oelint_adv_test.bb': self.__generate_sample_code(protocol, 'version=1;' + option),
}
self.check_for_id(self._create_args(input_), id_, occurrence)

@pytest.mark.parametrize('id_', ['oelint.vars.srcurioptions'])
@pytest.mark.parametrize('occurrence', [1])
@pytest.mark.parametrize('protocol', ['gomodgit'])
@pytest.mark.parametrize('option', ['xyz', 'abc'])
def test_bad_gomodgit(self, id_, occurrence, protocol, option):
input_ = {
'oelint_adv_test.bb': self.__generate_sample_code(protocol, 'version=1;' + option),
}
self.check_for_id(self._create_args(input_), id_, occurrence)

@pytest.mark.parametrize('id_', ['oelint.vars.srcurioptions'])
@pytest.mark.parametrize('occurrence', [0])
@pytest.mark.parametrize('protocol', ['gomodgit'])
@pytest.mark.parametrize('option', OPTION_MAPPING['gomodgit'])
def test_good_gomodgit(self, id_, occurrence, protocol, option):
input_ = {
'oelint_adv_test.bb': self.__generate_sample_code(protocol, 'version=1;' + option),
}
self.check_for_id(self._create_args(input_), id_, occurrence)

@pytest.mark.parametrize('id_', ['oelint.vars.srcurioptions'])
@pytest.mark.parametrize('occurrence', [1])
@pytest.mark.parametrize('protocol', ['hg'])
Expand Down
40 changes: 40 additions & 0 deletions tests/test_class_oelint_vars_srcurireqopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ 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"',
},
{
'oelint_adv_test.bb':
'SRC_URI += "gomod://golang.org/x/net"',
},
{
'oelint_adv_test.bb':
'SRC_URI += "gomodgit://golang.org/x/net"',
},
],
)
def test_bad(self, input_, id_, occurrence):
Expand Down Expand Up @@ -67,6 +83,30 @@ 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':
'SRC_URI += "gomod://golang.org/x/net;version=1.0"',
},
{
'oelint_adv_test.bb':
'SRC_URI += "gomodgit://golang.org/x/net;version=1.0"',
},
{
'oelint-adv_test.bb':
'''
Expand Down