buildroot/utils/checkpackagelib/tool.py
Yann E. MORIN 32b4912a75 utils/checkpackagelib: instruct shellcheck to follow included files
We do have a few shell scripts that have source directives (either with
'source' or with '.'), and they all are currently either globally
ignored in .checkpackageignore, or have shellcheck directives to ignore
the source statement (SC1090).

So, we can safely instruct shellcheck where to lookup for sourced files;
that does not trigger any new error.

This will alow fixing some shellcheck errors in later commits.

Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Cc: Ricardo Martincoski <ricardo.martincoski@datacom.com.br>
[Arnout: use long option]
Signed-off-by: Arnout Vandecappelle <arnout@mind.be>
2024-07-14 10:09:07 +02:00

45 lines
1.6 KiB
Python

import flake8.main.application
import os
import subprocess
import tempfile
from checkpackagelib.base import _Tool
class NotExecutable(_Tool):
def ignore(self):
return False
def run(self):
if self.ignore():
return
if os.access(self.filename, os.X_OK):
return ["{}:0: This file does not need to be executable{}".format(self.filename, self.hint())]
class Flake8(_Tool):
def run(self):
with tempfile.NamedTemporaryFile() as output:
app = flake8.main.application.Application()
app.run(['--output-file={}'.format(output.name), self.filename])
stdout = output.readlines()
processed_output = [str(line.decode().rstrip()) for line in stdout if line]
if len(stdout) == 0:
return
return ["{}:0: run 'flake8' and fix the warnings".format(self.filename),
'\n'.join(processed_output)]
class Shellcheck(_Tool):
def run(self):
cmd = ['shellcheck', "--external-sources", self.filename]
try:
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout = p.communicate()[0]
processed_output = [str(line.decode().rstrip()) for line in stdout.splitlines() if line]
if p.returncode == 0:
return
return ["{}:0: run 'shellcheck' and fix the warnings".format(self.filename),
'\n'.join(processed_output)]
except FileNotFoundError:
return ["{}:0: failed to call 'shellcheck'".format(self.filename)]