[Buildroot] [PATCH 16/16] utils/checkpackagelib: warn about $(HOST_DIR)/usr

Ricardo Martincoski ricardo.martincoski at gmail.com
Sun Jul 24 05:49:12 UTC 2022


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] http://patchwork.ozlabs.org/project/buildroot/patch/bc16adfe3d7143105e840072edb169e4cb7354cc.1658007000.git.yann.morin.1998@free.fr/

Cc: Yann E. MORIN <yann.morin.1998 at free.fr>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski at gmail.com>
---
NOTE to the maintainer applying this patch: please re-generate the list
of ignored warnings while applying:
$ ./utils/docker-run
br-user at ...$ ./utils/check-package --failed-only `git ls-tree -r --name-only HEAD` > .checkpackageignore

Run of unit tests:
$ utils/docker-run python3 -m pytest -vv utils/checkpackagelib/
232 passed in 0.86s
---
 .checkpackageignore                  | 22 ++++++++++++++++++++++
 utils/checkpackagelib/lib_mk.py      | 12 ++++++++++++
 utils/checkpackagelib/test_lib_mk.py | 23 +++++++++++++++++++++++
 3 files changed, 57 insertions(+)

diff --git a/.checkpackageignore b/.checkpackageignore
index 6f1a838562..92ab426685 100644
--- a/.checkpackageignore
+++ b/.checkpackageignore
@@ -91,9 +91,11 @@ board/zynqmp/post-build.sh Shellcheck
 board/zynqmp/post-image.sh Shellcheck
 board/zynqmp/zcu106/patches/uboot/0001-arm64-zynqmp-zynqmp-zcu102-revA-Fix-DP-PLL-configura.patch NumberedSubject
 boot/binaries-marvell/binaries-marvell.hash HashSpaces
+boot/grub2/grub2.mk DoNotInstallToHostdirUsr
 boot/s500-bootloader/s500-bootloader.hash HashSpaces
 boot/shim/shim.hash HashSpaces
 package/abootimg/abootimg.hash HashSpaces
+package/abootimg/abootimg.mk DoNotInstallToHostdirUsr
 package/acpitool/acpitool.hash HashSpaces
 package/aespipe/aespipe.hash HashSpaces
 package/alsamixergui/0001-misc-fixes.patch Sob
@@ -132,6 +134,7 @@ package/bcg729/bcg729.hash HashSpaces
 package/bdwgc/bdwgc.hash HashSpaces
 package/berkeleydb/berkeleydb.hash HashSpaces
 package/bind/S81named Indent Shellcheck Variables
+package/bind/bind.mk DoNotInstallToHostdirUsr
 package/biosdevname/biosdevname.hash HashSpaces
 package/bitstream/bitstream.hash HashSpaces
 package/bluez5_utils/S40bluetooth NotExecutable Variables
@@ -163,6 +166,7 @@ package/chrony/S49chrony Indent Shellcheck Variables
 package/cmocka/cmocka.hash HashSpaces
 package/collectd/collectd.hash HashSpaces
 package/comix-cursors/comix-cursors.hash HashSpaces
+package/compiler-rt/compiler-rt.mk DoNotInstallToHostdirUsr
 package/connman-gtk/connman-gtk.hash HashSpaces
 package/connman/S45connman Variables
 package/conntrack-tools/conntrack-tools.hash HashSpaces
@@ -192,6 +196,7 @@ package/datatables-buttons/datatables-buttons.hash HashSpaces
 package/datatables-fixedcolumns/datatables-fixedcolumns.hash HashSpaces
 package/datatables-responsive/datatables-responsive.hash HashSpaces
 package/datatables/datatables.hash HashSpaces
+package/dbus-python/dbus-python.mk DoNotInstallToHostdirUsr
 package/dbus/S30dbus Indent Shellcheck TrailingSpace Variables
 package/dc3dd/dc3dd.hash HashSpaces
 package/dcron/S90dcron Variables
@@ -267,6 +272,7 @@ package/frr/S50frr Shellcheck
 package/fstrcmp/fstrcmp.hash HashSpaces
 package/ftop/ftop.hash HashSpaces
 package/gamin/0002-no-const-return.patch Sob
+package/gawk/gawk.mk DoNotInstallToHostdirUsr
 package/gcc/arc-2020.09-release/0002-libsanitizer-Remove-cyclades-from-libsanitizer.patch Sob
 package/gconf/gconf.hash HashSpaces
 package/gengetopt/gengetopt.hash HashSpaces
@@ -274,6 +280,7 @@ package/genpart/genpart.hash HashSpaces
 package/genromfs/0001-build-system.patch Sob
 package/geoip/geoip.hash HashSpaces
 package/gerbera/S99gerbera Indent
+package/gettext-tiny/gettext-tiny.mk DoNotInstallToHostdirUsr
 package/gflags/gflags.hash HashSpaces
 package/ghostscript-fonts/ghostscript-fonts.hash HashSpaces
 package/giflib/giflib.hash HashSpaces
@@ -282,6 +289,7 @@ package/glm/glm.hash HashSpaces
 package/glorytun/glorytun.hash HashSpaces
 package/gnuradio/gnuradio.hash HashSpaces
 package/go/0002-cmd-dist-use-gohostarch-for-ssa-rewrite-check.patch Sob
+package/go/go.mk DoNotInstallToHostdirUsr
 package/gob2/gob2.hash HashSpaces
 package/google-breakpad/gen-syms.sh Shellcheck
 package/googlefontdirectory/googlefontdirectory.hash HashSpaces
@@ -326,6 +334,7 @@ package/iucode-tool/S00iucode-tool Variables
 package/iucode-tool/iucode-tool.hash HashSpaces
 package/iwd/S40iwd Shellcheck Variables
 package/jailhouse/jailhouse.hash HashSpaces
+package/jimtcl/jimtcl.mk DoNotInstallToHostdirUsr
 package/joe/joe.hash HashSpaces
 package/jquery/jquery.hash HashSpaces
 package/jsmin/jsmin.hash HashSpaces
@@ -337,6 +346,7 @@ package/kyua/kyua.hash HashSpaces
 package/lbreakout2/lbreakout2.hash HashSpaces
 package/lensfun/lensfun.hash HashSpaces
 package/libao/libao.hash HashSpaces
+package/libapparmor/libapparmor.mk DoNotInstallToHostdirUsr
 package/libart/0001-art-config-cross.patch Sob
 package/libart/libart.hash HashSpaces
 package/libasplib/libasplib.hash HashSpaces
@@ -424,6 +434,7 @@ package/libtool/libtool.hash HashSpaces
 package/libtorrent/libtorrent.hash HashSpaces
 package/libucl/libucl.hash HashSpaces
 package/libuecc/libuecc.hash HashSpaces
+package/libva/libva.mk DoNotInstallToHostdirUsr
 package/libwebsock/libwebsock.hash HashSpaces
 package/libxml-parser-perl/libxml-parser-perl.hash HashSpaces
 package/lightning/lightning.hash HashSpaces
@@ -482,6 +493,7 @@ package/lua-testmore/lua-testmore.hash HashSpaces
 package/lua-utf8/lua-utf8.hash HashSpaces
 package/lua-valua/lua-valua.hash HashSpaces
 package/lua-zlib/lua-zlib.hash HashSpaces
+package/lua/lua.mk DoNotInstallToHostdirUsr
 package/luadbi-sqlite3/luadbi-sqlite3.hash HashSpaces
 package/luadbi/luadbi.hash HashSpaces
 package/luaexpatutils/luaexpatutils.hash HashSpaces
@@ -564,10 +576,12 @@ package/obsidian-cursors/obsidian-cursors.hash HashSpaces
 package/ocrad/ocrad.hash HashSpaces
 package/odb/odb.hash HashSpaces
 package/ofono/S46ofono Variables
+package/ola/ola.mk DoNotInstallToHostdirUsr
 package/olsr/S50olsr Indent Shellcheck Variables
 package/olsr/olsr.hash HashSpaces
 package/omxplayer/omxplayer.hash HashSpaces
 package/opencore-amr/opencore-amr.hash HashSpaces
+package/openjdk-bin/openjdk-bin.mk DoNotInstallToHostdirUsr
 package/openmpi/openmpi.hash HashSpaces
 package/openntpd/S49ntp Shellcheck Variables
 package/openobex/openobex.hash HashSpaces
@@ -660,7 +674,11 @@ package/perl-xml-libxml/perl-xml-libxml.hash HashSpaces
 package/perl-xml-namespacesupport/perl-xml-namespacesupport.hash HashSpaces
 package/perl-xml-sax-base/perl-xml-sax-base.hash HashSpaces
 package/perl-xml-sax/perl-xml-sax.hash HashSpaces
+package/php-apcu/php-apcu.mk DoNotInstallToHostdirUsr
+package/php-lua/php-lua.mk DoNotInstallToHostdirUsr
+package/php-pam/php-pam.mk DoNotInstallToHostdirUsr
 package/php-pecl-dbus/php-pecl-dbus.hash HashSpaces
+package/php-pecl-dbus/php-pecl-dbus.mk DoNotInstallToHostdirUsr
 package/physfs/physfs.hash HashSpaces
 package/picocom/picocom.hash HashSpaces
 package/pigpio/S50pigpio Shellcheck Variables
@@ -703,6 +721,7 @@ package/python-cherrypy/python-cherrypy.hash HashSpaces
 package/python-constantly/python-constantly.hash HashSpaces
 package/python-couchdb/python-couchdb.hash HashSpaces
 package/python-crcmod/python-crcmod.hash HashSpaces
+package/python-cryptography/python-cryptography.mk DoNotInstallToHostdirUsr
 package/python-cssselect/python-cssselect.hash HashSpaces
 package/python-daemonize/python-daemonize.hash HashSpaces
 package/python-daphne/python-daphne.hash HashSpaces
@@ -750,6 +769,7 @@ package/python-piexif/python-piexif.hash HashSpaces
 package/python-ply/python-ply.hash HashSpaces
 package/python-portend/python-portend.hash HashSpaces
 package/python-pyaes/python-pyaes.hash HashSpaces
+package/python-pybind/python-pybind.mk DoNotInstallToHostdirUsr
 package/python-pyicu/python-pyicu.hash HashSpaces
 package/python-pylibftdi/python-pylibftdi.hash HashSpaces
 package/python-pyqrcode/python-pyqrcode.hash HashSpaces
@@ -806,6 +826,7 @@ package/rcw-smarc-sal28/rcw-smarc-sal28.hash HashSpaces
 package/rdesktop/0001-8bit-colors.patch Sob
 package/reaver/reaver.hash HashSpaces
 package/redis/S50redis Shellcheck Variables
+package/refpolicy/refpolicy.mk DoNotInstallToHostdirUsr
 package/restorecond/S02restorecond Shellcheck
 package/rings/rings.hash HashSpaces
 package/ripgrep/ripgrep.hash HashSpaces
@@ -1018,6 +1039,7 @@ package/xl2tp/xl2tpd TrailingSpace
 package/xmlstarlet/xmlstarlet.hash HashSpaces
 package/xutil_util-macros/xutil_util-macros.hash HashSpaces
 package/yad/yad.hash HashSpaces
+package/zfs/zfs.mk DoNotInstallToHostdirUsr
 package/zip/zip.hash HashSpaces
 package/zmqpp/zmqpp.hash HashSpaces
 package/zxing-cpp/zxing-cpp.hash HashSpaces
diff --git a/utils/checkpackagelib/lib_mk.py b/utils/checkpackagelib/lib_mk.py
index b50a19ac62..eaef19b2ec 100644
--- a/utils/checkpackagelib/lib_mk.py
+++ b/utils/checkpackagelib/lib_mk.py
@@ -21,6 +21,18 @@ 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()):
+            if self.filename in ['package/skeleton/skeleton.mk']:
+                return
+            return ["{}:{}: install files to $(HOST_DIR)/ instead of $(HOST_DIR)/usr/"
+                    .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..db6641f14c 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',
+     []),
+    ]
+
+
+ at 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
+
+
 Indent = [
     ('ignore comment at beginning of line',
      'any',
-- 
2.25.1




More information about the buildroot mailing list