diff --git a/package/busybox/busybox.mk b/package/busybox/busybox.mk index 0f14bf999d..f8f9cb5616 100644 --- a/package/busybox/busybox.mk +++ b/package/busybox/busybox.mk @@ -110,6 +110,7 @@ BUSYBOX_MAKE_OPTS = \ # specifying BUSYBOX_CONFIG_FILE on the command-line overrides the .config # setting. +# check-package disable Ifdef ifndef BUSYBOX_CONFIG_FILE BUSYBOX_CONFIG_FILE = $(call qstrip,$(BR2_PACKAGE_BUSYBOX_CONFIG)) endif diff --git a/package/uclibc/uclibc.mk b/package/uclibc/uclibc.mk index 0ddf7dfa6d..125aa4cdcf 100644 --- a/package/uclibc/uclibc.mk +++ b/package/uclibc/uclibc.mk @@ -22,6 +22,7 @@ UCLIBC_DEPENDENCIES = host-gcc-initial linux-headers # specifying UCLIBC_CONFIG_FILE on the command-line overrides the .config # setting. +# check-package disable Ifdef ifndef UCLIBC_CONFIG_FILE UCLIBC_CONFIG_FILE = $(call qstrip,$(BR2_UCLIBC_CONFIG)) endif diff --git a/utils/checkpackagelib/lib_mk.py b/utils/checkpackagelib/lib_mk.py index b50a19ac62..8adf844e9a 100644 --- a/utils/checkpackagelib/lib_mk.py +++ b/utils/checkpackagelib/lib_mk.py @@ -21,6 +21,24 @@ continue_conditional = ["elif", "else"] end_conditional = ["endif"] +class Ifdef(_CheckFunction): + IFDEF = re.compile(r"^\s*(else\s+|)(ifdef|ifndef)\s") + + def check_line(self, lineno, text): + m = self.IFDEF.search(text) + if m is None: + return + word = m.group(2) + if word == 'ifdef': + return ["{}:{}: use ifeq ($(SYMBOL),y) instead of ifdef SYMBOL" + .format(self.filename, lineno), + text] + else: + return ["{}:{}: use ifneq ($(SYMBOL),y) instead of ifndef SYMBOL" + .format(self.filename, lineno), + text] + + class Indent(_CheckFunction): COMMENT = re.compile(r"^\s*#") CONDITIONAL = re.compile(r"^\s*({})\s".format("|".join(start_conditional + end_conditional + continue_conditional))) diff --git a/utils/checkpackagelib/test_lib_mk.py b/utils/checkpackagelib/test_lib_mk.py index 49fa216fcd..80a1736b4e 100644 --- a/utils/checkpackagelib/test_lib_mk.py +++ b/utils/checkpackagelib/test_lib_mk.py @@ -3,6 +3,54 @@ import checkpackagelib.test_util as util import checkpackagelib.lib_mk as m +Ifdef = [ + ('ignore commented line', + 'any', + '# ifdef\n', + []), + ('simple', + 'any', + '\n' + 'ifdef BR2_PACKAGE_FWTS_EFI_RUNTIME_MODULE\n' + 'endif\n', + [['any:2: use ifeq ($(SYMBOL),y) instead of ifdef SYMBOL', + 'ifdef BR2_PACKAGE_FWTS_EFI_RUNTIME_MODULE\n']]), + ('ignore indentation', + 'any', + ' ifdef FOO\n' + ' endif\n' + '\tifdef BAR\n' + 'endif\n', + [['any:1: use ifeq ($(SYMBOL),y) instead of ifdef SYMBOL', + ' ifdef FOO\n'], + ['any:3: use ifeq ($(SYMBOL),y) instead of ifdef SYMBOL', + '\tifdef BAR\n']]), + ('typo', + 'any', + '\n' + 'ifndef ($(BR2_ENABLE_LOCALE),y)\n' + 'endif\n', + [['any:2: use ifneq ($(SYMBOL),y) instead of ifndef SYMBOL', + 'ifndef ($(BR2_ENABLE_LOCALE),y)\n']]), + ('else ifdef', + 'any', + 'else ifdef SYMBOL # comment\n', + [['any:1: use ifeq ($(SYMBOL),y) instead of ifdef SYMBOL', + 'else ifdef SYMBOL # comment\n']]), + ('else ifndef', + 'any', + '\t else ifndef\t($(SYMBOL),y) # comment\n', + [['any:1: use ifneq ($(SYMBOL),y) instead of ifndef SYMBOL', + '\t else ifndef\t($(SYMBOL),y) # comment\n']]), + ] + + +@pytest.mark.parametrize('testname,filename,string,expected', Ifdef) +def test_Ifdef(testname, filename, string, expected): + warnings = util.check_file(m.Ifdef, filename, string) + assert warnings == expected + + Indent = [ ('ignore comment at beginning of line', 'any',