* [OE-core][PATCH v4] patch.py: Initialize git repo before patching
[not found] <16BCAC9ACE071CC4.4083@lists.openembedded.org>
@ 2021-12-01 16:12 ` Pavel Zhukov
2021-12-01 22:41 ` Richard Purdie
0 siblings, 1 reply; 3+ messages in thread
From: Pavel Zhukov @ 2021-12-01 16:12 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 with error message:
Command Error: 'git rev-parse --show-toplevel' exited with 0 Output:
fatal: not a git repository (or any of the parent directories): .git
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 fccbedb519..8326cb55bc 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -56,6 +56,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
@@ -298,6 +302,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 6779e62103..2c3defc6b7 100644
--- a/meta/lib/oeqa/selftest/cases/bbtests.py
+++ b/meta/lib/oeqa/selftest/cases/bbtests.py
@@ -297,3 +297,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] 3+ messages in thread
* Re: [OE-core][PATCH v4] patch.py: Initialize git repo before patching
2021-12-01 16:12 ` [OE-core][PATCH v4] patch.py: Initialize git repo before patching Pavel Zhukov
@ 2021-12-01 22:41 ` Richard Purdie
2021-12-02 7:56 ` [OE-core][PATCH v5] " Pavel Zhukov
0 siblings, 1 reply; 3+ messages in thread
From: Richard Purdie @ 2021-12-01 22:41 UTC (permalink / raw)
To: Pavel Zhukov, openembedded-core; +Cc: Pavel Zhukov
On Wed, 2021-12-01 at 17:12 +0100, Pavel Zhukov wrote:
> 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 with error message:
> Command Error: 'git rev-parse --show-toplevel' exited with 0 Output:
> fatal: not a git repository (or any of the parent directories): .git
>
> 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 fccbedb519..8326cb55bc 100644
> --- a/meta/lib/oe/patch.py
> +++ b/meta/lib/oe/patch.py
> @@ -56,6 +56,10 @@ def runcmd(args, dir = None):
> if dir:
> os.chdir(olddir)
>
> +def getstatusoutput(cmd):
> + import subprocess
> + return subprocess.getstatusoutput(cmd.split())
> +
I'm not convinced this function is adding much or is needed. imports can just go
at the start of the python file in this case too.
> class PatchError(Exception):
> def __init__(self, msg):
> self.msg = msg
> @@ -298,6 +302,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 6779e62103..2c3defc6b7 100644
> --- a/meta/lib/oeqa/selftest/cases/bbtests.py
> +++ b/meta/lib/oeqa/selftest/cases/bbtests.py
> @@ -297,3 +297,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')
Can you add a comment here about what exactly we're testing please? If something
changes the way the man-db recipe works, this test will break (e.g. it became a
git based recipe rather than tarball).
We may also want to check that the man-db SRC_URI doesn't contain git:// to
guard against that and better document what the test is testing?
Cheers,
Richard
^ permalink raw reply [flat|nested] 3+ messages in thread
* [OE-core][PATCH v5] patch.py: Initialize git repo before patching
2021-12-01 22:41 ` Richard Purdie
@ 2021-12-02 7:56 ` Pavel Zhukov
0 siblings, 0 replies; 3+ messages in thread
From: Pavel Zhukov @ 2021-12-02 7:56 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 with error message:
Command Error: 'git rev-parse --show-toplevel' exited with 0 Output:
fatal: not a git repository (or any of the parent directories): .git
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 | 16 +++++++++++++++-
meta/lib/oeqa/selftest/cases/bbtests.py | 15 +++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
index fccbedb519..950fe723dc 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -4,6 +4,7 @@
import oe.path
import oe.types
+import subprocess
class NotFoundError(bb.BBHandledException):
def __init__(self, path):
@@ -25,7 +26,6 @@ class CmdError(bb.BBHandledException):
def runcmd(args, dir = None):
import pipes
- import subprocess
if dir:
olddir = os.path.abspath(os.curdir)
@@ -56,6 +56,7 @@ def runcmd(args, dir = None):
if dir:
os.chdir(olddir)
+
class PatchError(Exception):
def __init__(self, msg):
self.msg = msg
@@ -298,6 +299,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) = subprocess.getstatusoutput(cmd.split())
+ ## Make sure repo is 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 6779e62103..a74576bc02 100644
--- a/meta/lib/oeqa/selftest/cases/bbtests.py
+++ b/meta/lib/oeqa/selftest/cases/bbtests.py
@@ -297,3 +297,18 @@ 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):
+ """ PATCHTOOL=git should work with non-git sources like tarballs
+ test recipe for the test must NOT containt git:// repository in SRC_URI
+ """
+ test_recipe = "man-db"
+ self.write_recipeinc(test_recipe, 'PATCHTOOL=\"git\"')
+ src = get_bb_var("SRC_URI",test_recipe)
+ gitscm = re.search("git://", src)
+ self.assertFalse(gitscm, "test_git_patchtool pre-condition failed: {} test recipe contains git repo!".format(test_recipe))
+ result = bitbake('man-db -c patch', ignore_status=False)
+ fatal = re.search("fatal: not a git repository (or any of the parent directories)", result.output)
+ self.assertFalse(fatal, "Failed to patch using PATCHTOOL=\"git\"")
+ self.delete_recipeinc(test_recipe)
+ bitbake('-cclean man-db')
--
2.34.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-12-02 7:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <16BCAC9ACE071CC4.4083@lists.openembedded.org>
2021-12-01 16:12 ` [OE-core][PATCH v4] patch.py: Initialize git repo before patching Pavel Zhukov
2021-12-01 22:41 ` Richard Purdie
2021-12-02 7:56 ` [OE-core][PATCH v5] " Pavel Zhukov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.