diff options
author | Pavel Zhukov <pavel@zhukoff.net> | 2022-03-07 11:19:29 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-03-15 16:38:29 +0000 |
commit | 630d754ea3d7206976b1e0f4489e054cdbc08fe8 (patch) | |
tree | 9eeaf772b9cab48a6fda7cf4903122bd91feddd2 | |
parent | 2c9e93bc40fb0c274ed007c0b07b5a9bd75de018 (diff) | |
download | poky-630d754ea3d7206976b1e0f4489e054cdbc08fe8.tar.gz |
patch.py: Prevent git repo reinitialization
There were few bugs in the _isInitialized() function which might trigger
git repo to be reinitialized and patches failing to apply.
(From OE-Core rev: 427f4ef11beb8ceee007b5c7e152f2383a114aca)
Signed-off-by: Pavel Zhukov <pavel.zhukov@huawei.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta-selftest/recipes-test/gitrepotest/gitrepotest.bb | 16 | ||||
-rw-r--r-- | meta-selftest/recipes-test/gitrepotest/gitrepotest/0001-testpatch.patch | 9 | ||||
-rw-r--r-- | meta/lib/oe/patch.py | 11 | ||||
-rw-r--r-- | meta/lib/oeqa/selftest/cases/bbtests.py | 18 |
4 files changed, 49 insertions, 5 deletions
diff --git a/meta-selftest/recipes-test/gitrepotest/gitrepotest.bb b/meta-selftest/recipes-test/gitrepotest/gitrepotest.bb new file mode 100644 index 0000000000..f1b6c55833 --- /dev/null +++ b/meta-selftest/recipes-test/gitrepotest/gitrepotest.bb | |||
@@ -0,0 +1,16 @@ | |||
1 | SUMMARY = "Test recipe for git repo initialization" | ||
2 | HOMEPAGE = "https://git.yoctoproject.org/git/matchbox-panel-2" | ||
3 | LICENSE = "GPL-2.0-or-later" | ||
4 | LIC_FILES_CHKSUM = "file://COPYING;md5=94d55d512a9ba36caa9b7df079bae19f" | ||
5 | |||
6 | INHIBIT_DEFAULT_DEPS = "1" | ||
7 | |||
8 | PATCHTOOL="git" | ||
9 | |||
10 | SRC_URI = "git://git.yoctoproject.org/git/matchbox-panel-2;branch=master;protocol=https \ | ||
11 | file://0001-testpatch.patch \ | ||
12 | " | ||
13 | |||
14 | SRCREV = "f82ca3f42510fb3ef10f598b393eb373a2c34ca7" | ||
15 | |||
16 | S = "${WORKDIR}/git" | ||
diff --git a/meta-selftest/recipes-test/gitrepotest/gitrepotest/0001-testpatch.patch b/meta-selftest/recipes-test/gitrepotest/gitrepotest/0001-testpatch.patch new file mode 100644 index 0000000000..bccda17ee9 --- /dev/null +++ b/meta-selftest/recipes-test/gitrepotest/gitrepotest/0001-testpatch.patch | |||
@@ -0,0 +1,9 @@ | |||
1 | diff --git a/Makefile.am b/Makefile.am | ||
2 | index 432a9b4..bbf7c74 100644 | ||
3 | --- a/Makefile.am | ||
4 | +++ b/Makefile.am | ||
5 | @@ -1,3 +1,4 @@ | ||
6 | +## This is useless comment to test if patch works | ||
7 | ACLOCAL_AMFLAGS = -I m4 | ||
8 | |||
9 | SUBDIRS = matchbox-panel applets data po | ||
diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py index 950fe723dc..9034fcae03 100644 --- a/meta/lib/oe/patch.py +++ b/meta/lib/oe/patch.py | |||
@@ -304,14 +304,19 @@ class GitApplyTree(PatchTree): | |||
304 | 304 | ||
305 | def _isInitialized(self): | 305 | def _isInitialized(self): |
306 | cmd = "git rev-parse --show-toplevel" | 306 | cmd = "git rev-parse --show-toplevel" |
307 | (status, output) = subprocess.getstatusoutput(cmd.split()) | 307 | try: |
308 | output = runcmd(cmd.split(), self.dir).strip() | ||
309 | except CmdError as err: | ||
310 | ## runcmd returned non-zero which most likely means 128 | ||
311 | ## Not a git directory | ||
312 | return False | ||
308 | ## Make sure repo is in builddir to not break top-level git repos | 313 | ## Make sure repo is in builddir to not break top-level git repos |
309 | return status == 0 and os.path.samedir(output, self.dir) | 314 | return os.path.samefile(output, self.dir) |
310 | 315 | ||
311 | def _initRepo(self): | 316 | def _initRepo(self): |
312 | runcmd("git init".split(), self.dir) | 317 | runcmd("git init".split(), self.dir) |
313 | runcmd("git add .".split(), self.dir) | 318 | runcmd("git add .".split(), self.dir) |
314 | runcmd("git commit -a --allow-empty -m Patching_started".split(), self.dir) | 319 | runcmd("git commit -a --allow-empty -m bitbake_patching_started".split(), self.dir) |
315 | 320 | ||
316 | @staticmethod | 321 | @staticmethod |
317 | def extractPatchHeader(patchfile): | 322 | def extractPatchHeader(patchfile): |
diff --git a/meta/lib/oeqa/selftest/cases/bbtests.py b/meta/lib/oeqa/selftest/cases/bbtests.py index 31962b92d7..a08001a173 100644 --- a/meta/lib/oeqa/selftest/cases/bbtests.py +++ b/meta/lib/oeqa/selftest/cases/bbtests.py | |||
@@ -310,8 +310,22 @@ INHERIT:remove = \"report-error\" | |||
310 | src = get_bb_var("SRC_URI",test_recipe) | 310 | src = get_bb_var("SRC_URI",test_recipe) |
311 | gitscm = re.search("git://", src) | 311 | gitscm = re.search("git://", src) |
312 | self.assertFalse(gitscm, "test_git_patchtool pre-condition failed: {} test recipe contains git repo!".format(test_recipe)) | 312 | self.assertFalse(gitscm, "test_git_patchtool pre-condition failed: {} test recipe contains git repo!".format(test_recipe)) |
313 | result = bitbake('man-db -c patch', ignore_status=False) | 313 | result = bitbake('{} -c patch'.format(test_recipe), ignore_status=False) |
314 | fatal = re.search("fatal: not a git repository (or any of the parent directories)", result.output) | 314 | fatal = re.search("fatal: not a git repository (or any of the parent directories)", result.output) |
315 | self.assertFalse(fatal, "Failed to patch using PATCHTOOL=\"git\"") | 315 | self.assertFalse(fatal, "Failed to patch using PATCHTOOL=\"git\"") |
316 | self.delete_recipeinc(test_recipe) | 316 | self.delete_recipeinc(test_recipe) |
317 | bitbake('-cclean man-db') | 317 | bitbake('-cclean {}'.format(test_recipe)) |
318 | |||
319 | def test_git_patchtool2(self): | ||
320 | """ Test if PATCHTOOL=git works with git repo and doesn't reinitialize it | ||
321 | """ | ||
322 | test_recipe = "gitrepotest" | ||
323 | src = get_bb_var("SRC_URI",test_recipe) | ||
324 | gitscm = re.search("git://", src) | ||
325 | self.assertTrue(gitscm, "test_git_patchtool pre-condition failed: {} test recipe doesn't contains git repo!".format(test_recipe)) | ||
326 | result = bitbake('{} -c patch'.format(test_recipe), ignore_status=False) | ||
327 | srcdir = get_bb_var('S', test_recipe) | ||
328 | result = runCmd("git log", cwd = srcdir) | ||
329 | self.assertFalse("bitbake_patching_started" in result.output, msg = "Repository has been reinitialized. {}".format(srcdir)) | ||
330 | self.delete_recipeinc(test_recipe) | ||
331 | bitbake('-cclean {}'.format(test_recipe)) | ||