[PATCH] feat: don't use sub-processes to filter FIXME variables and

Michael Krasnyk <[email protected]>
Newsgroups org.yoctoproject.lists.poky
Message-ID <CAL-AFs1GQ+TFJwSax6s2CoVbqBou=BzcJNGYcNFvpffyCpziwQ@mail.gmail.com>
From a75040b2a197c0ddb55a047dcc0d834606ddf284 Mon Sep 17 00:00:00 2001
From: Michael Krasnyk <[email protected]>
Date: Fri, 18 Oct 2024 23:50:12 +0200
Subject: [PATCH] feat: don't use sub-processes to filter FIXME variables and
 use only Python

---
 meta/classes-global/staging.bbclass | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/meta/classes-global/staging.bbclass
b/meta/classes-global/staging.bbclass
index c0f5e3ebb6..896592fb7e 100644
--- a/meta/classes-global/staging.bbclass
+++ b/meta/classes-global/staging.bbclass
@@ -176,16 +176,26 @@ def staging_copydir(c, target, dest, seendirs):
         seendirs.add(dest)

 def staging_processfixme(fixme, target, recipesysroot,
recipesysrootnative, d):
-    import subprocess
-
     if not fixme:
         return
-    cmd = "sed -e 's:^[^/]*/:%s/:g' %s | xargs sed -i -e
's:FIXMESTAGINGDIRTARGET:%s:g; s:FIXMESTAGINGDIRHOST:%s:g'" % (target, "
".join(fixme), recipesysroot, recipesysrootnative)
-    for fixmevar in ['PSEUDO_SYSROOT', 'HOSTTOOLS_DIR', 'PKGDATA_DIR',
'PSEUDO_LOCALSTATEDIR', 'LOGFIFO']:
-        fixme_path = d.getVar(fixmevar)
-        cmd += " -e 's:FIXME_%s:%s:g'" % (fixmevar, fixme_path)
-    bb.debug(2, cmd)
-    subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
+
+    import re
+
+    fixme_vars = {re.escape("FIXME_" + fixmevar): 'd.getVar(fixmevar)' for
fixmevar in ['PSEUDO_SYSROOT', 'HOSTTOOLS_DIR', 'PKGDATA_DIR',
'PSEUDO_LOCALSTATEDIR', 'LOGFIFO']}
+    fixme_path = {"FIXMESTAGINGDIRTARGET": recipesysroot,
"FIXMESTAGINGDIRHOST": recipesysrootnative, **fixme_vars}
+    target_re = re.compile(r"^[^/]*(?=/)")
+    fixme_re = re.compile("|".join(fixme_path.keys()))
+    fixme_files = set()
+    # Read fixme files
+    for path in fixme:
+        with open(path) as fixme_file:
+            fixme_files.update(target_re.sub(target, line.strip()) for
line in fixme_file.readlines())
+    # Fix files in-place
+    for path in fixme_files:
+        with open(path, "r+") as fixed_file:
+            text = fixme_re.sub(lambda m:
fixme_path[re.escape(m.group(0))], fixed_file.read())
+            fixed_file.seek(0)
+            fixed_file.write(text)


 def staging_populate_sysroot_dir(targetsysroot, nativesysroot, native, d):
-- 
2.39.3 (Apple Git-146)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.