From 29a0dd4a3006c06d4b8d82821bd74b8b9f26715a Mon Sep 17 00:00:00 2001 From: Ricardo Martincoski Date: Sun, 31 Jul 2022 16:35:20 -0300 Subject: [PATCH] utils/checkpackagelib: warn about $(HOST_DIR)/usr It's been ages (5 years at the next release) that we've not installed host packages in $(HOST_DIR)/usr, but we still have a few packages that reference it or install things in there. See [1] Add a new check_function that warns when a file is added installing to or referencing $(HOST_DIR)/usr . [1] "d9ff62c4cd pacakge: drop remnants of $(HOST_DIR)/usr" Cc: Yann E. MORIN Signed-off-by: Ricardo Martincoski [Arnout: exclude skeleton.mk with disable comment instead of explicit code] Signed-off-by: Arnout Vandecappelle --- package/skeleton/skeleton.mk | 1 + utils/checkpackagelib/lib_mk.py | 10 ++++++++++ utils/checkpackagelib/test_lib_mk.py | 23 +++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/package/skeleton/skeleton.mk b/package/skeleton/skeleton.mk index 9d97f02f08..634c76e437 100644 --- a/package/skeleton/skeleton.mk +++ b/package/skeleton/skeleton.mk @@ -14,6 +14,7 @@ SKELETON_ADD_SKELETON_DEPENDENCY = NO # We create a compatibility symlink in case a post-build script still # uses $(HOST_DIR)/usr define HOST_SKELETON_INSTALL_CMDS +# check-package DoNotInstallToHostdirUsr $(Q)ln -snf . $(HOST_DIR)/usr $(Q)mkdir -p $(HOST_DIR)/lib $(Q)mkdir -p $(HOST_DIR)/include diff --git a/utils/checkpackagelib/lib_mk.py b/utils/checkpackagelib/lib_mk.py index 8adf844e9a..d340882971 100644 --- a/utils/checkpackagelib/lib_mk.py +++ b/utils/checkpackagelib/lib_mk.py @@ -21,6 +21,16 @@ continue_conditional = ["elif", "else"] end_conditional = ["endif"] +class DoNotInstallToHostdirUsr(_CheckFunction): + INSTALL_TO_HOSTDIR_USR = re.compile(r"^[^#].*\$\(HOST_DIR\)/usr") + + def check_line(self, lineno, text): + if self.INSTALL_TO_HOSTDIR_USR.match(text.rstrip()): + return ["{}:{}: install files to $(HOST_DIR)/ instead of $(HOST_DIR)/usr/" + .format(self.filename, lineno), + text] + + class Ifdef(_CheckFunction): IFDEF = re.compile(r"^\s*(else\s+|)(ifdef|ifndef)\s") diff --git a/utils/checkpackagelib/test_lib_mk.py b/utils/checkpackagelib/test_lib_mk.py index 80a1736b4e..2086237ebb 100644 --- a/utils/checkpackagelib/test_lib_mk.py +++ b/utils/checkpackagelib/test_lib_mk.py @@ -3,6 +3,29 @@ import checkpackagelib.test_util as util import checkpackagelib.lib_mk as m +DoNotInstallToHostdirUsr = [ + ('real case', + 'libapparmor.mk', + 'LIBAPPARMOR_CONF_OPTS += \\\n' + '\t--with-python \\\n' + '\tPYTHON=$(HOST_DIR)/usr/bin/python3 \\\n' + '\tPYTHON_CONFIG=$(STAGING_DIR)/usr/bin/python3-config \\\n' + '\tSWIG=$(SWIG)\n', + [['libapparmor.mk:3: install files to $(HOST_DIR)/ instead of $(HOST_DIR)/usr/', + '\tPYTHON=$(HOST_DIR)/usr/bin/python3 \\\n']]), + ('ignore comment', + 'any', + '# following code do not install to $(HOST_DIR)/usr/\n', + []), + ] + + +@pytest.mark.parametrize('testname,filename,string,expected', DoNotInstallToHostdirUsr) +def test_DoNotInstallToHostdirUsr(testname, filename, string, expected): + warnings = util.check_file(m.DoNotInstallToHostdirUsr, filename, string) + assert warnings == expected + + Ifdef = [ ('ignore commented line', 'any',