1 # See support/scripts/check-package.txt before editing this file.
2 # There are already dependency checks during the build, so below check
3 # functions don't need to check for things already checked by exploring the
4 # menu options using "make menuconfig" and by running "make" with appropriate
9 from checkpackagebase import _CheckFunction
10 # Notice: ignore 'imported but unused' from pyflakes for check functions.
11 from checkpackagelib import ConsecutiveEmptyLines
12 from checkpackagelib import EmptyLastLine
13 from checkpackagelib import NewlineAtEof
14 from checkpackagelib import TrailingSpace
17 class Indent(_CheckFunction):
18 COMMENT = re.compile("^\s*#")
19 CONDITIONAL = re.compile("^\s*(ifeq|ifneq|endif)\s")
20 ENDS_WITH_BACKSLASH = re.compile(r"^[^#].*\\$")
21 END_DEFINE = re.compile("^\s*endef\s")
22 MAKEFILE_TARGET = re.compile("^[^# \t]+:\s")
23 START_DEFINE = re.compile("^\s*define\s")
27 self.backslash = False
28 self.makefile_target = False
30 def check_line(self, lineno, text):
31 if self.START_DEFINE.search(text):
34 if self.END_DEFINE.search(text):
39 if self.define or self.backslash or self.makefile_target:
41 if self.CONDITIONAL.search(text):
44 # calculate for next line
45 if self.ENDS_WITH_BACKSLASH.search(text):
48 self.backslash = False
50 if self.MAKEFILE_TARGET.search(text):
51 self.makefile_target = True
53 if text.strip() == "":
54 self.makefile_target = False
57 # comment can be indented or not inside define ... endef, so ignore it
58 if self.define and self.COMMENT.search(text):
62 if not text.startswith("\t"):
63 return ["{}:{}: expected indent with tabs"
64 .format(self.filename, lineno),
67 if text.startswith("\t"):
68 return ["{}:{}: unexpected indent with tabs"
69 .format(self.filename, lineno),
73 class PackageHeader(_CheckFunction):
77 def check_line(self, lineno, text):
78 if self.skip or lineno > 6:
82 if lineno == 1 and text.startswith("include "):
85 if text.rstrip() != "#" * 80:
86 return ["{}:{}: should be 80 hashes ({}#writing-rules-mk)"
87 .format(self.filename, lineno, self.url_to_manual),
90 elif lineno in [2, 4]:
91 if text.rstrip() != "#":
92 return ["{}:{}: should be 1 hash ({}#writing-rules-mk)"
93 .format(self.filename, lineno, self.url_to_manual),
96 if text.rstrip() != "":
97 return ["{}:{}: should be a blank line ({}#writing-rules-mk)"
98 .format(self.filename, lineno, self.url_to_manual),
102 class SpaceBeforeBackslash(_CheckFunction):
103 TAB_OR_MULTIPLE_SPACES_BEFORE_BACKSLASH = re.compile(r"^.*( |\t)\\$")
105 def check_line(self, lineno, text):
106 if self.TAB_OR_MULTIPLE_SPACES_BEFORE_BACKSLASH.match(text.rstrip()):
107 return ["{}:{}: use only one space before backslash"
108 .format(self.filename, lineno),
112 class TrailingBackslash(_CheckFunction):
113 ENDS_WITH_BACKSLASH = re.compile(r"^[^#].*\\$")
116 self.backslash = False
118 def check_line(self, lineno, text):
119 last_line_ends_in_backslash = self.backslash
121 # calculate for next line
122 if self.ENDS_WITH_BACKSLASH.search(text):
123 self.backslash = True
126 self.backslash = False
128 if last_line_ends_in_backslash and text.strip() == "":
129 return ["{}:{}: remove trailing backslash"
130 .format(self.filename, lineno - 1),
134 class UselessFlag(_CheckFunction):
135 DEFAULT_AUTOTOOLS_FLAG = re.compile("^.*{}".format("|".join([
136 "_AUTORECONF\s*=\s*NO",
137 "_LIBTOOL_PATCH\s*=\s*YES"])))
138 DEFAULT_GENERIC_FLAG = re.compile("^.*{}".format("|".join([
139 "_INSTALL_IMAGES\s*=\s*NO",
140 "_INSTALL_REDISTRIBUTE\s*=\s*YES",
141 "_INSTALL_STAGING\s*=\s*NO",
142 "_INSTALL_TARGET\s*=\s*YES"])))
143 END_CONDITIONAL = re.compile("^\s*(endif)")
144 START_CONDITIONAL = re.compile("^\s*(ifeq|ifneq)")
149 def check_line(self, lineno, text):
150 if self.START_CONDITIONAL.search(text):
151 self.conditional += 1
153 if self.END_CONDITIONAL.search(text):
154 self.conditional -= 1
157 # allow non-default conditionally overridden by default
158 if self.conditional > 0:
161 if self.DEFAULT_GENERIC_FLAG.search(text):
162 return ["{}:{}: useless default value ({}#"
163 "_infrastructure_for_packages_with_specific_build_systems)"
164 .format(self.filename, lineno, self.url_to_manual),
167 if self.DEFAULT_AUTOTOOLS_FLAG.search(text):
168 return ["{}:{}: useless default value "
169 "({}#_infrastructure_for_autotools_based_packages)"
170 .format(self.filename, lineno, self.url_to_manual),