[2/6] CI: Add API for sbuild hook insertion

Message ID 20250221154843.515037-3-amikan@ilbers.de
State New
Headers show
Series Fix essentials rebuild and cover with CI | expand

Commit Message

Anton Mikanovich Feb. 21, 2025, 3:48 p.m. UTC
Custom hook will be added to dpkg.bbclass. Method will return the file
name to be restored after the testing to be sure the sources were not
changed after testsuite running.
This API will be used later for build dependencies checking.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 testsuite/cibuilder.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Patch

diff --git a/testsuite/cibuilder.py b/testsuite/cibuilder.py
index e671a4ae..d335dbe8 100755
--- a/testsuite/cibuilder.py
+++ b/testsuite/cibuilder.py
@@ -339,6 +339,22 @@  class CIBuilder(Test):
         cmd = f"dpkg-query --root={rootfs} -f='${{Version}}' -W {package}"
         return process.getoutput(cmd)
 
+    def set_sbuild_hook(self, hook, type='post-build-commands'):
+        append_data = f"        --{type}=\"{hook}\" \\\n"
+
+        layerdir_core = CIUtils.getVars('LAYERDIR_core')
+        sbuildclass_file = os.path.join(layerdir_core, 'classes/dpkg.bbclass')
+        self.backupfile(sbuildclass_file)
+        with open(sbuildclass_file, 'r') as file:
+            lines = file.readlines()
+        with open(sbuildclass_file, 'w') as file:
+            for line in lines:
+                file.write(line)
+                if 'sbuild -A -n' in line:
+                    file.write(append_data)
+
+        return sbuildclass_file
+
     def get_ssh_cmd_prefix(self, user, host, port, priv_key):
         cmd_prefix = (
             f"ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no -p {port} "