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',