utils/checkpackagelib: warn about executable files

Currently there are no .mk, Config.in, .patch or .hash files with
executable permissions in the tree.
But we don't want to have that.

So warn when a file checked by check-package has executable permission.

This check will be reused when testing SysV init scripts in the tree.

Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
[Arnout: use context manager for temp dir so it gets deleted]
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
2022.02.x
Ricardo Martincoski 2021-12-26 15:49:16 -03:00 committed by Arnout Vandecappelle (Essensium/Mind)
parent 1734127e59
commit 7947328de4
6 changed files with 53 additions and 0 deletions

View File

@ -10,6 +10,7 @@ from checkpackagelib.lib import ConsecutiveEmptyLines # noqa: F401
from checkpackagelib.lib import EmptyLastLine # noqa: F401
from checkpackagelib.lib import NewlineAtEof # noqa: F401
from checkpackagelib.lib import TrailingSpace # noqa: F401
from checkpackagelib.tool import NotExecutable # noqa: F401
def _empty_or_comment(text):

View File

@ -10,6 +10,7 @@ from checkpackagelib.lib import ConsecutiveEmptyLines # noqa: F401
from checkpackagelib.lib import EmptyLastLine # noqa: F401
from checkpackagelib.lib import NewlineAtEof # noqa: F401
from checkpackagelib.lib import TrailingSpace # noqa: F401
from checkpackagelib.tool import NotExecutable # noqa: F401
def _empty_line_or_comment(text):

View File

@ -13,6 +13,7 @@ from checkpackagelib.lib import EmptyLastLine # noqa: F401
from checkpackagelib.lib import NewlineAtEof # noqa: F401
from checkpackagelib.lib import TrailingSpace # noqa: F401
from checkpackagelib.lib import Utf8Characters # noqa: F401
from checkpackagelib.tool import NotExecutable # noqa: F401
# used in more than one check
start_conditional = ["ifdef", "ifeq", "ifndef", "ifneq"]

View File

@ -8,6 +8,7 @@ import re
from checkpackagelib.base import _CheckFunction
from checkpackagelib.lib import NewlineAtEof # noqa: F401
from checkpackagelib.tool import NotExecutable # noqa: F401
class ApplyOrder(_CheckFunction):

View File

@ -0,0 +1,41 @@
import os
import pytest
import re
import tempfile
import checkpackagelib.tool as m
workdir_regex = re.compile(r'/tmp/tmp[^/]*-checkpackagelib-test-tool')
def check_file(tool, filename, string, permissions=None):
with tempfile.TemporaryDirectory(suffix='-checkpackagelib-test-tool') as workdir:
script = os.path.join(workdir, filename)
with open(script, 'wb') as f:
f.write(string.encode())
if permissions:
os.chmod(script, permissions)
obj = tool(script)
result = obj.run()
if result is None:
return []
return [workdir_regex.sub('dir', r) for r in result]
NotExecutable = [
('664',
'package.mk',
0o664,
'',
[]),
('775',
'package.mk',
0o775,
'',
["dir/package.mk:0: This file does not need to be executable"]),
]
@pytest.mark.parametrize('testname,filename,permissions,string,expected', NotExecutable)
def test_NotExecutable(testname, filename, permissions, string, expected):
warnings = check_file(m.NotExecutable, filename, string, permissions)
assert warnings == expected

View File

@ -0,0 +1,8 @@
import os
from checkpackagelib.base import _Tool
class NotExecutable(_Tool):
def run(self):
if os.access(self.filename, os.X_OK):
return ["{}:0: This file does not need to be executable".format(self.filename)]