Openembedded Core Discussions
 help / color / mirror / Atom feed
* [meta-oe][PATCH v2] patch.py: Initialize git repo before patching
@ 2021-12-01 14:15 Pavel Zhukov
  2021-12-01 15:56 ` [OE-core] " Alexander Kanavin
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Zhukov @ 2021-12-01 14:15 UTC (permalink / raw)
  To: openembedded-core; +Cc: Pavel Zhukov, pavel

From: Pavel Zhukov <pavel.zhukov@huawei.com>

If PATCHTOOL="git" has been specified but workdir is not git repo
bitbake fails to apply the patches. Fix this by initializing the repo
before patching.
This allows binary git patches to be applied.

Signed-off-by: Pavel Zhukov <pavel.zhukov@huawei.com>
---
 meta/lib/oe/patch.py                    | 17 +++++++++++++++++
 meta/lib/oeqa/selftest/cases/bbtests.py |  6 ++++++
 2 files changed, 23 insertions(+)

diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
index 7cd8436da5..720c6f663c 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -52,6 +52,10 @@ def runcmd(args, dir = None):
         if dir:
             os.chdir(olddir)
 
+def getstatusoutput(cmd):
+    import subprocess
+    return subprocess.getstatusoutput(cmd.split())
+
 class PatchError(Exception):
     def __init__(self, msg):
         self.msg = msg
@@ -294,6 +298,19 @@ class GitApplyTree(PatchTree):
         PatchTree.__init__(self, dir, d)
         self.commituser = d.getVar('PATCH_GIT_USER_NAME')
         self.commitemail = d.getVar('PATCH_GIT_USER_EMAIL')
+        if not self._isInitialized():
+            self._initRepo()
+
+    def _isInitialized(self):
+        cmd = "git rev-parse --show-toplevel"
+        (status, output) = getstatusoutput(cmd)
+        ## Make sure we're in builddir to not break top-level git repos
+        return status == 0 and os.path.samedir(output, self.dir)
+
+    def _initRepo(self):
+        runcmd("git init".split(), self.dir)
+        runcmd("git add .".split(), self.dir)
+        runcmd("git commit -a --allow-empty -m Patching_started".split(), self.dir)
 
     @staticmethod
     def extractPatchHeader(patchfile):
diff --git a/meta/lib/oeqa/selftest/cases/bbtests.py b/meta/lib/oeqa/selftest/cases/bbtests.py
index d4f6a08991..8c046074f6 100644
--- a/meta/lib/oeqa/selftest/cases/bbtests.py
+++ b/meta/lib/oeqa/selftest/cases/bbtests.py
@@ -294,3 +294,9 @@ INHERIT_remove = \"report-error\"
 
         test_recipe_summary_after = get_bb_var('SUMMARY', test_recipe)
         self.assertEqual(expected_recipe_summary, test_recipe_summary_after)
+
+    def test_git_patchtool(self):
+        self.write_recipeinc('man-db', 'PATCHTOOL=\"git\"')
+        result = bitbake('man-db -c patch', ignore_status=False)
+        self.delete_recipeinc('man-db')
+        bitbake('-cclean man-db')
-- 
2.34.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-12-01 16:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-01 14:15 [meta-oe][PATCH v2] patch.py: Initialize git repo before patching Pavel Zhukov
2021-12-01 15:56 ` [OE-core] " Alexander Kanavin
2021-12-01 16:00   ` Pavel Zhukov
2021-12-01 16:07     ` Alexander Kanavin
2021-12-01 16:14       ` Pavel Zhukov
2021-12-01 16:26         ` Alexander Kanavin
2021-12-01 16:26           ` Alexander Kanavin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox