浏览代码

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 <yann.morin.1998@free.fr>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
[Arnout: exclude skeleton.mk with disable comment instead of explicit
         code]
Signed-off-by: Arnout Vandecappelle <arnout@mind.be>
Ricardo Martincoski 3 年之前
父节点
当前提交
29a0dd4a30
共有 3 个文件被更改,包括 34 次插入0 次删除
  1. 1 0
      package/skeleton/skeleton.mk
  2. 10 0
      utils/checkpackagelib/lib_mk.py
  3. 23 0
      utils/checkpackagelib/test_lib_mk.py

+ 1 - 0
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

+ 10 - 0
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")
 

+ 23 - 0
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',