Skip to contentSkip to conversation

kernel.bbclass: make do_symlink_kernelsrc reentrant

PATCH Superseded [email protected] 1 participant 1 message Dec 19, 2023

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 kernel.bbclass: make do_symlink_kernelsrc reentrant

From: Etienne Cordonnier <[email protected]>

The function do_symlink_kernsrc is not reentrant in the case where S is defined to a non-default value. This causes build-failures e.g. when building linux-yocto, then updating poky to a commit which modifies kernel.bbclass, and then building linux-yocto again.

Bugzilla: https://bugzilla.yoctoproject.org/show_bug.cgi?id=15325

Tested with a recipe "my-custom-linux" which unpacks sources to a custom ${S} directory and ran symlink_kernsrc several times:

$ bitbake -f -c symlink_kernsrc my-custom-linux
---
 meta/classes-recipe/kernel.bbclass | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
meta/classes-recipe/kernel.bbclass +7 -1
index 9ff37f5c38..42c5519f81 100644
@@ -189,11 +189,17 @@ python do_symlink_kernsrc () {
             # drop trailing slash, so that os.symlink(kernsrc, s) doesn't use s as
             # directory name and fail
             s = s[:-1]
-        if d.getVar("EXTERNALSRC"):
+        if d.getVar("EXTERNALSRC") and not os.path.islink(s):
             # With EXTERNALSRC S will not be wiped so we can symlink to it
             os.symlink(s, kernsrc)
         else:
             import shutil
+            # perform idempotent/reentrant copy
+            s_copy = s + ".orig"
+            if not os.path.isdir(s_copy):
+                shutil.copytree(s, s_copy)
+            bb.utils.remove(s, recurse=True)
+            shutil.copytree(s_copy, s)
             shutil.move(s, kernsrc)
             os.symlink(kernsrc, s)
 }
Signature · 1 line
2.36.1.vfs.0.0