Skip to content
This repository was archived by the owner on Apr 6, 2022. It is now read-only.

Commit eb7f1e1

Browse files
ulfalizercarlescufi
authored andcommitted
check_compliance.py: Kconfig: Flag redundant $ZEPHYR_BASE in 'source'
'source's like source "$(ZEPHYR_BASE)/Kconfig.zephyr" can be simplified to source "Kconfig.zephyr" since $srctree already points to the Zephyr root. Flag it in the Nits test. This also avoids absolute paths showing up in some places. Signed-off-by: Ulf Magnusson <[email protected]>
1 parent c9837d6 commit eb7f1e1

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

scripts/check_compliance.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,20 +684,21 @@ def run(self):
684684
is_kconfig = "Kconfig" in fname
685685

686686
if is_kconfig:
687-
self.check_kconfig_file(fname)
687+
self.check_kconfig_header(fname)
688+
self.check_redundant_zephyr_source(fname)
688689

689690
if fname.endswith((".c", ".cpp", ".h", ".ld", ".py", ".rst",
690691
".yaml", ".yml")) or is_kconfig:
691692
self.check_source_file(fname)
692693

693-
def check_kconfig_file(self, fname):
694-
# Nits related to Kconfig files
694+
def check_kconfig_header(self, fname):
695+
# Checks for a spammy copy-pasted header format
695696

696697
with open(os.path.join(GIT_TOP, fname), encoding="utf-8") as f:
697698
contents = f.read()
698699

699700
# 'Kconfig - yada yada' has a copy-pasted redundant filename at the
700-
# start. This probably means all of the header was copy-pasted.
701+
# top. This probably means all of the header was copy-pasted.
701702
if re.match(r"\s*#\s*(K|k)config[\w.-]*\s*-", contents):
702703
self.add_failure("""
703704
Please use this format for the header in '{}' (see
@@ -715,6 +716,22 @@ def check_kconfig_file(self, fname):
715716
failure.
716717
""".format(fname))
717718

719+
def check_redundant_zephyr_source(self, fname):
720+
# Checks for 'source "$(ZEPHYR_BASE)/Kconfig[.zephyr]"', which can be
721+
# be simplified to 'source "Kconfig[.zephyr]"'
722+
723+
with open(os.path.join(GIT_TOP, fname), encoding="utf-8") as f:
724+
# Look for e.g. rsource as well, for completeness
725+
match = re.search(
726+
r'^\s*(?:o|r|or)?source\s*"\$\(?ZEPHYR_BASE\)?/(Kconfig(?:\.zephyr)?)"',
727+
f.read(), re.MULTILINE)
728+
729+
if match:
730+
self.add_failure("""
731+
Redundant 'source "$(ZEPHYR_BASE)/{0}" in '{1}'. Just do 'source "{0}"'
732+
instead. The $srctree environment variable already points to the Zephyr root,
733+
and all 'source's are relative to it.""".format(match.group(1), fname))
734+
718735
def check_source_file(self, fname):
719736
# Generic nits related to various source files
720737

0 commit comments

Comments
 (0)