diff mbox series

[v2] classes/insane: improve HOME checks exceptions more

Message ID 20261202125320.3290642-1-ravi@prevas.dk
State Under Review
Headers show
Series [v2] classes/insane: improve HOME checks exceptions more | expand

Commit Message

Rasmus Villemoes Dec. 2, 2026, 12:53 p.m. UTC
From: Rasmus Villemoes <ravi@prevas.dk>

Currently, we skip the check if $HOME is a prefix of any of the
OEQA_BUILDPATHS_SKIP. That was done to avoid $HOME=/home/build
matching a packaged file containing e.g. /home/buildroot, and the
recipe having added /home/buildroot to OEQA_BUILDPATHS_SKIP.

However, one can avoid such false positives by instead checking that
the homedir actually appears as-is in the file without a following
alphanumeric. Python regexp matching does work for bytes objects, so
we can use a RE matching homedir literally followed by a \b word
boundary check (where, for bytes objects, word characters are ascii
alphanumerics [a-zA-Z0-9_]).

Concretely, what failed for me was sqlite3-src containing /home/user1,
and building in a docker container where $HOME happens to be
/home/user. Of course, one can (and probably should) add /home/user1
to sqlite3's OEQA_BUILDPATHS_SKIP, but let's make the check more
precise anyway to avoid spurious failures.

This essentially reverts f6b9494eac ("classes/insane: improve HOME
checks exceptions") and reimplements that, but in the meantime,
46b77e80ad ("insane.bbclass: Avoid buildpaths QA reporting on HOME if
its in TMPDIR") had come to rely on the prefix checking. So also
reimplement the intention of that commit somewhat more directly: when
the TMPDIR warning has fired, and TMPDIR is indeed under $HOME, just
skip the homedir checking.

Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
---

v2: Use word-boundary regexp matching instead of splitting on the
homedir substring. Thanks to Ross for pointing out that Python does
allow re matching on bytes objects.

 meta/classes-global/insane.bbclass | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes-global/insane.bbclass b/meta/classes-global/insane.bbclass
index 350e1f83c2..4e8774719b 100644
--- a/meta/classes-global/insane.bbclass
+++ b/meta/classes-global/insane.bbclass
@@ -430,6 +430,7 @@  def package_qa_check_buildpaths(path, name, d, elf):
     explicitly ignored.
     """
     import stat
+    import re
     # Ignore symlinks/devs/fifos
     mode = os.lstat(path).st_mode
     if stat.S_ISLNK(mode) or stat.S_ISBLK(mode) or stat.S_ISFIFO(mode) or stat.S_ISCHR(mode) or stat.S_ISSOCK(mode):
@@ -443,8 +444,10 @@  def package_qa_check_buildpaths(path, name, d, elf):
         if tmpdir in file_content:
             path = package_qa_clean_path(path, d, name)
             oe.qa.handle_error("buildpaths", "File %s in package %s contains reference to TMPDIR" % (path, name), d)
-            buildpaths_skip.append(tmpdir.decode())
-        if homedir and homedir in file_content and not any(path.startswith(homedir.decode()) for path in buildpaths_skip):
+            # If TMPDIR is inside $HOME and this warning fired, so will the one below. Skip that.
+            if tmpdir.startswith(homedir):
+                homedir = b''
+        if homedir and homedir.decode() not in buildpaths_skip and re.search(re.escape(homedir) + b'\\b', file_content):
             path = package_qa_clean_path(path, d, name)
             oe.qa.handle_error("buildpaths", "File %s in package %s contains a reference to the build host HOME directory. If upstream hardcodes a directory path that matches your home, you can set OEQA_BUILDPATHS_SKIP = \"%s\" in the recipe." % (path, name, homedir.decode()), d)