mirror of
https://gitlab.com/buildroot.org/buildroot.git
synced 2026-08-01 21:23:51 -09:00
Enable the common checks: - consecutive empty lines - empty last line - missing new line at end of file - trailing space - warn for executable files, with the hint to instead use '$(INSTALL) -D -m 0755' in the .mk file Check indent with tabs: - add a simple check function to warn only when the indent is done using spaces or a mix of tabs and spaces. It does not check indenting levels, but it already makes the review easier, since it diferentiates spaces and tabs. Check variables: - check DAEMON is defined - when DAEMON is defined, check the filename is in the form S01daemon - when PIDFILE is defined, expect it to be in /var/run and defined using $DAEMON. Also add unit test for this. Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com> [Arnout: avoid 'del NotExecutable_base' by importing the module instead of the class; refer to manual in warnings] Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
69 lines
3.0 KiB
Python
69 lines
3.0 KiB
Python
import os
|
|
import re
|
|
|
|
from checkpackagelib.base import _CheckFunction
|
|
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
|
|
import checkpackagelib.tool
|
|
|
|
|
|
class Indent(_CheckFunction):
|
|
INDENTED_WITH_SPACES = re.compile(r"^[\t]* ")
|
|
|
|
def check_line(self, lineno, text):
|
|
if self.INDENTED_WITH_SPACES.search(text.rstrip()):
|
|
return ["{}:{}: should be indented with tabs ({}#adding-packages-start-script)"
|
|
.format(self.filename, lineno, self.url_to_manual),
|
|
text]
|
|
|
|
|
|
class NotExecutable(checkpackagelib.tool.NotExecutable):
|
|
def hint(self):
|
|
return ", just make sure you use '$(INSTALL) -D -m 0755' in the .mk file"
|
|
|
|
|
|
class Variables(_CheckFunction):
|
|
DAEMON_VAR = re.compile(r"^DAEMON=[\"']{0,1}([^\"']*)[\"']{0,1}")
|
|
PIDFILE_PATTERN = re.compile(r"/var/run/(\$DAEMON|\$\{DAEMON\}).pid")
|
|
PIDFILE_VAR = re.compile(r"^PIDFILE=[\"']{0,1}([^\"']*)[\"']{0,1}")
|
|
|
|
def before(self):
|
|
self.name = None
|
|
|
|
def check_line(self, lineno, text):
|
|
name_found = self.DAEMON_VAR.search(text.rstrip())
|
|
if name_found:
|
|
if self.name:
|
|
return ["{}:{}: DAEMON variable redefined ({}#adding-packages-start-script)"
|
|
.format(self.filename, lineno, self.url_to_manual),
|
|
text]
|
|
self.name = name_found.group(1)
|
|
if '/' in self.name:
|
|
self.name = os.path.basename(self.name) # to be used in after() to check the expected filename
|
|
return ["{}:{}: Do not include path in DAEMON ({}#adding-packages-start-script)"
|
|
.format(self.filename, lineno, self.url_to_manual),
|
|
text,
|
|
'DAEMON="{}"'.format(self.name)]
|
|
return
|
|
|
|
pidfile_found = self.PIDFILE_VAR.search(text.rstrip())
|
|
if pidfile_found:
|
|
pidfile = pidfile_found.group(1)
|
|
if not self.PIDFILE_PATTERN.match(pidfile):
|
|
return ["{}:{}: Incorrect PIDFILE value ({}#adding-packages-start-script)"
|
|
.format(self.filename, lineno, self.url_to_manual),
|
|
text,
|
|
'PIDFILE="/var/run/$DAEMON.pid"']
|
|
|
|
def after(self):
|
|
if self.name is None:
|
|
return ["{}:0: DAEMON variable not defined ({}#adding-packages-start-script)"
|
|
.format(self.filename, self.url_to_manual)]
|
|
expected_filename = re.compile(r"S\d\d{}$".format(self.name))
|
|
if not expected_filename.match(os.path.basename(self.filename)):
|
|
return ["{}:0: filename should be S<number><number><daemon name> ({}#adding-packages-start-script)"
|
|
.format(self.filename, self.url_to_manual),
|
|
"expecting S<number><number>{}".format(self.name)]
|