Skip to content

Commit

Permalink
rules: support for UNPACKDIR
Browse files Browse the repository at this point in the history
also adding UNPACKDIR to the list of known vars from styhead
release on

Closes #568

Signed-off-by: Konrad Weihmann <[email protected]>
  • Loading branch information
priv-kweihmann committed May 24, 2024
1 parent 87a1759 commit 0dbc722
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ Rules marked with **[S]** can have multiple sub-IDs
* [oelint.vars.srcurisrcrevtag](https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.srcurisrcrevtag.md) - 'tag' in SRC_URI and a SRCREV for the same component doesn't compute
* [oelint.vars.summary80chars](https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.summary80chars.md) - SUMMARY should max. be 80 characters long
* [oelint.vars.summarylinebreaks](https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.summarylinebreaks.md) - No line breaks in SUMMARY
* [oelint.vars.unpackdir](https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.unpackdir.md) - \$\{UNPACKDIR\} should be used instead of \$\{WORKDIR\} in S and B
* [oelint.vars.valuequoted](https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.valuequoted.md) - Variable values should be properly quoted
* [oelint.vars.virtual](https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.virtual.md) - no virtual/ items in RDEPENDS/RPROVIDES
Expand Down
36 changes: 36 additions & 0 deletions docs/wiki/oelint.vars.unpackdir.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# oelint.vars.unpackdir

severity: error

## Example

```
S = "${WORKDIR}"
```

or

```
B = "${WORKDIR}/foo/bar"
```

## Why is this bad?

Recently upstream changed the way sources are unpacked/refreshed
on changes of the SRC_URI inputs.
Unpacking in WORKDIR makes it impossible to determine what is
a new resource and what might be a left-over from a previous run.
Hence UNPACKDIR was introduced - users should refrain from
using WORKDIR for S or B

## Ways to fix it

```
S = "${UNPACKDIR}"
```

or

```
B = "${UNPACKDIR}/foo/bar"
```
23 changes: 23 additions & 0 deletions oelint_adv/rule_base/rule_vars_unpackdir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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 VarRootfsPostprocessCommand(Rule):
def __init__(self) -> None:
super().__init__(id='oelint.vars.unpackdir',
severity='error',
valid_from_release='styhead',
message='Use ${UNPACKDIR} instead of ${WORKDIR}')

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, attributeValue=['S', 'B'])
for i in items:
if '${WORKDIR}' in i.VarValueStripped:
res += self.finding(i.Origin, i.InFileLine)
return res
2 changes: 1 addition & 1 deletion oelint_adv/tweaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Tweaks:
"mickledore": {"constantmods": {"-": {"variables": {"known": ["PACKAGEBUILDPKGD"]}}}},
"nanbield": {"constantmods": {"-": {"variables": {"suggested": ["AUTHOR"]}}}},
"scarthgap": {},
"styhead": {},
"styhead": {"constantmods": {"+": {"variables": {"known": ["UNPACKDIR"]}}}},
"latest": {},
}

Expand Down
71 changes: 71 additions & 0 deletions tests/test_class_oelint_vars_unpackdir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import pytest # noqa: I900

from .base import TestBaseClass


class TestClassOelintVarsUnpackdir(TestBaseClass):

@pytest.mark.parametrize('id_', ['oelint.vars.unpackdir'])
@pytest.mark.parametrize('occurrence', [1])
@pytest.mark.parametrize('input_',
[
{
'oelint_adv_test.bb':
'S = "${WORKDIR}"',
},
{
'oelint_adv_test.bb':
'''
B = "${WORKDIR}/foo/bar"
''',
},
],
)
def test_bad_new(self, input_, id_, occurrence):
self.check_for_id(self._create_args(input_, ['--release=styhead']), id_, occurrence)

@pytest.mark.parametrize('id_', ['oelint.vars.unpackdir'])
@pytest.mark.parametrize('occurrence', [0])
@pytest.mark.parametrize('input_',
[
{
'oelint_adv_test.bb':
'S = "${WORKDIR}"',
},
{
'oelint_adv_test.bb':
'''
B = "${WORKDIR}/foo/bar"
''',
},
],
)
def test_bad_old(self, input_, id_, occurrence):
self.check_for_id(self._create_args(input_), id_, occurrence)

@pytest.mark.parametrize('id_', ['oelint.vars.unpackdir'])
@pytest.mark.parametrize('occurrence', [0])
@pytest.mark.parametrize('input_',
[
{
'oelint_adv_test.bb':
'''
S = "${UNPACKDIR}"
''',
},
{
'oelint_adv_test.bb':
'''
B = "${UNPACKDIR}/foo/bar"
''',
},
{
'oelint_adv_test.bb':
'''
SOMEOTHER = "${WORKDIR}/foo/bar"
''',
},
],
)
def test_good_inherit(self, input_, id_, occurrence):
self.check_for_id(self._create_args(input_, ['--release=styhead']), id_, occurrence)

0 comments on commit 0dbc722

Please sign in to comment.