diff --git a/README.md b/README.md index e3ab86f..48a85f2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/wiki/oelint.vars.unpackdir.md b/docs/wiki/oelint.vars.unpackdir.md new file mode 100644 index 0000000..0c9af62 --- /dev/null +++ b/docs/wiki/oelint.vars.unpackdir.md @@ -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" +``` diff --git a/oelint_adv/rule_base/rule_vars_unpackdir.py b/oelint_adv/rule_base/rule_vars_unpackdir.py new file mode 100644 index 0000000..8eec906 --- /dev/null +++ b/oelint_adv/rule_base/rule_vars_unpackdir.py @@ -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 diff --git a/oelint_adv/tweaks.py b/oelint_adv/tweaks.py index 9354dd6..73bfab4 100644 --- a/oelint_adv/tweaks.py +++ b/oelint_adv/tweaks.py @@ -41,7 +41,7 @@ class Tweaks: "mickledore": {"constantmods": {"-": {"variables": {"known": ["PACKAGEBUILDPKGD"]}}}}, "nanbield": {"constantmods": {"-": {"variables": {"suggested": ["AUTHOR"]}}}}, "scarthgap": {}, - "styhead": {}, + "styhead": {"constantmods": {"+": {"variables": {"known": ["UNPACKDIR"]}}}}, "latest": {}, } diff --git a/tests/test_class_oelint_vars_unpackdir.py b/tests/test_class_oelint_vars_unpackdir.py new file mode 100644 index 0000000..752c93e --- /dev/null +++ b/tests/test_class_oelint_vars_unpackdir.py @@ -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)