diff mbox series

[v2] kernel.bbclass: make do_symlink_kernelsrc reentrant

Message ID 20231216135306.188070-1-ecordonnier@snap.com
State New
Headers show
Series [v2] kernel.bbclass: make do_symlink_kernelsrc reentrant | expand

Commit Message

Etienne Cordonnier Dec. 16, 2023, 1:53 p.m. UTC
From: Etienne Cordonnier <ecordonnier@snap.com>

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

Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
---
 meta/classes-recipe/kernel.bbclass | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Bruce Ashfield Dec. 17, 2023, 5:25 p.m. UTC | #1
On Sat, Dec 16, 2023 at 8:53 AM Etienne Cordonnier via
lists.openembedded.org <ecordonnier=snap.com@lists.openembedded.org>
wrote:
>
> From: Etienne Cordonnier <ecordonnier@snap.com>
>
> 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
>
> Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
> ---
>  meta/classes-recipe/kernel.bbclass | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/meta/classes-recipe/kernel.bbclass b/meta/classes-recipe/kernel.bbclass
> index 9ff37f5c38..130bedd901 100644
> --- a/meta/classes-recipe/kernel.bbclass
> +++ b/meta/classes-recipe/kernel.bbclass
> @@ -194,6 +194,11 @@ python do_symlink_kernsrc () {
>              os.symlink(s, kernsrc)
>          else:
>              import shutil
> +            if os.path.islink(s):
> +                # this happens for instance when a poky update forces symlink_kernsrc to run again
> +                # after s was already moved to kernsrc
> +                bb.warn("%s is already a symlink! Not symlinking kernel sources" % s)

I don't think this is a warning situation, perhaps bb.info() is better.

Since nothing is wrong, no unexpected results will occur and I really
don't see any side effects .. is why I don't see it as a warning.

Bruce

> +                return 0
>              shutil.move(s, kernsrc)
>              os.symlink(kernsrc, s)
>  }
> --
> 2.34.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#192564): https://lists.openembedded.org/g/openembedded-core/message/192564
> Mute This Topic: https://lists.openembedded.org/mt/103208527/1050810
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [bruce.ashfield@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Richard Purdie Dec. 17, 2023, 7:52 p.m. UTC | #2
On Sat, 2023-12-16 at 14:53 +0100, Etienne Cordonnier via
lists.openembedded.org wrote:
> From: Etienne Cordonnier <ecordonnier@snap.com>
> 
> 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
> 
> Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
> ---
>  meta/classes-recipe/kernel.bbclass | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/meta/classes-recipe/kernel.bbclass b/meta/classes-recipe/kernel.bbclass
> index 9ff37f5c38..130bedd901 100644
> --- a/meta/classes-recipe/kernel.bbclass
> +++ b/meta/classes-recipe/kernel.bbclass
> @@ -194,6 +194,11 @@ python do_symlink_kernsrc () {
>              os.symlink(s, kernsrc)
>          else:
>              import shutil
> +            if os.path.islink(s):
> +                # this happens for instance when a poky update forces symlink_kernsrc to run again
> +                # after s was already moved to kernsrc
> +                bb.warn("%s is already a symlink! Not symlinking kernel sources" % s)
> +                return 0
>              shutil.move(s, kernsrc)
>              os.symlink(kernsrc, s)
>  }

Usually what we recommend is that the first pass does something if "if
not exists X.org; cp X X.orig; fi", then you can always copy from
X.orig.

As Bruce says, it definitely shouldn't be a warning, this can happen
quite normally. 

Cheers,

Richard
Etienne Cordonnier Dec. 18, 2023, 11:45 a.m. UTC | #3
My thinking was that in my local build I was updating from a build without
https://github.com/yoctoproject/poky/commit/3b8d0acca30c806fb69fc3096d41593cc76ed22c
to a build containing this commit, so the behavior of do_symlink_kernsrc
got modified, but my incremental build is not executing the new version of
the code since it detects that the symlink already exists and then the rest
of the function gets skipped, so I thought this justified a warning.

I'll lower the warning to info, but then this assumes that we will never
modify do_symlink_kernsrc in a way which is not backwards-compatible.

@Richard: the reason I didn't go for the copy to "orig" is that I don't see
a way to add this without breaking incremental builds (where s is a symlink
to kernsrc which is potentially modified already by do_patch etc.). However
I think it would be a cleaner solution than simply skipping the code like I
did:

-        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
+            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)

Etienne


On Sun, Dec 17, 2023 at 8:52 PM Richard Purdie <
richard.purdie@linuxfoundation.org> wrote:

> On Sat, 2023-12-16 at 14:53 +0100, Etienne Cordonnier via
> lists.openembedded.org wrote:
> > From: Etienne Cordonnier <ecordonnier@snap.com>
> >
> > 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://urldefense.proofpoint.com/v2/url?u=https-3A__bugzilla.yoctoproject.org_show-5Fbug.cgi-3Fid-3D15325&d=DwIFaQ&c=ncDTmphkJTvjIDPh0hpF_4vCHvabgGkICC2epckfdiw&r=AhkbNonVuMIGRfPx_Qj9TsRih1DULJTKUkSGa66m67E&m=qcRut2Wm9dH26YP_YovPl6QVczLOYUxs1xfzA75ZJBiHj4dWwxbAS-2JjGPlyiyS&s=_WTBsDroHfmiIIyCOXRV2CAId9PmKZ4sN3bRO3EOcyU&e=
> >
> > Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
> > ---
> >  meta/classes-recipe/kernel.bbclass | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/meta/classes-recipe/kernel.bbclass
> b/meta/classes-recipe/kernel.bbclass
> > index 9ff37f5c38..130bedd901 100644
> > --- a/meta/classes-recipe/kernel.bbclass
> > +++ b/meta/classes-recipe/kernel.bbclass
> > @@ -194,6 +194,11 @@ python do_symlink_kernsrc () {
> >              os.symlink(s, kernsrc)
> >          else:
> >              import shutil
> > +            if os.path.islink(s):
> > +                # this happens for instance when a poky update forces
> symlink_kernsrc to run again
> > +                # after s was already moved to kernsrc
> > +                bb.warn("%s is already a symlink! Not symlinking kernel
> sources" % s)
> > +                return 0
> >              shutil.move(s, kernsrc)
> >              os.symlink(kernsrc, s)
> >  }
>
> Usually what we recommend is that the first pass does something if "if
> not exists X.org; cp X X.orig; fi", then you can always copy from
> X.orig.
>
> As Bruce says, it definitely shouldn't be a warning, this can happen
> quite normally.
>
> Cheers,
>
> Richard
>
Bruce Ashfield Dec. 18, 2023, 2:25 p.m. UTC | #4
On Mon, Dec 18, 2023 at 6:45 AM Etienne Cordonnier via
lists.openembedded.org <ecordonnier=snap.com@lists.openembedded.org>
wrote:
>
> My thinking was that in my local build I was updating from a build without https://github.com/yoctoproject/poky/commit/3b8d0acca30c806fb69fc3096d41593cc76ed22c to a build containing this commit, so the behavior of do_symlink_kernsrc got modified, but my incremental build is not executing the new version of the code since it detects that the symlink already exists and then the rest of the function gets skipped, so I thought this justified a warning.
>
> I'll lower the warning to info, but then this assumes that we will never modify do_symlink_kernsrc in a way which is not backwards-compatible.
>
> @Richard: the reason I didn't go for the copy to "orig" is that I don't see a way to add this without breaking incremental builds (where s is a symlink to kernsrc which is potentially modified already by do_patch etc.). However I think it would be a cleaner solution than simply skipping the code like I did:

If the only way to trigger the issue is through really rare pre-<some
commit> to post
that commit that happens to modify the detection/manipulation/other of S and the
symlink, then it is rare enough to just drop an info message breadcrumb and keep
moving.

But if it really is a rare situation like you ran into, or some sort
of forced execution
of the task, I don't think that a copy would be an unexpected thing to happen.

Bruce

>
> -        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
> +            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)
>
> Etienne
>
>
> On Sun, Dec 17, 2023 at 8:52 PM Richard Purdie <richard.purdie@linuxfoundation.org> wrote:
>>
>> On Sat, 2023-12-16 at 14:53 +0100, Etienne Cordonnier via
>> lists.openembedded.org wrote:
>> > From: Etienne Cordonnier <ecordonnier@snap.com>
>> >
>> > 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://urldefense.proofpoint.com/v2/url?u=https-3A__bugzilla.yoctoproject.org_show-5Fbug.cgi-3Fid-3D15325&d=DwIFaQ&c=ncDTmphkJTvjIDPh0hpF_4vCHvabgGkICC2epckfdiw&r=AhkbNonVuMIGRfPx_Qj9TsRih1DULJTKUkSGa66m67E&m=qcRut2Wm9dH26YP_YovPl6QVczLOYUxs1xfzA75ZJBiHj4dWwxbAS-2JjGPlyiyS&s=_WTBsDroHfmiIIyCOXRV2CAId9PmKZ4sN3bRO3EOcyU&e=
>> >
>> > Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
>> > ---
>> >  meta/classes-recipe/kernel.bbclass | 5 +++++
>> >  1 file changed, 5 insertions(+)
>> >
>> > diff --git a/meta/classes-recipe/kernel.bbclass b/meta/classes-recipe/kernel.bbclass
>> > index 9ff37f5c38..130bedd901 100644
>> > --- a/meta/classes-recipe/kernel.bbclass
>> > +++ b/meta/classes-recipe/kernel.bbclass
>> > @@ -194,6 +194,11 @@ python do_symlink_kernsrc () {
>> >              os.symlink(s, kernsrc)
>> >          else:
>> >              import shutil
>> > +            if os.path.islink(s):
>> > +                # this happens for instance when a poky update forces symlink_kernsrc to run again
>> > +                # after s was already moved to kernsrc
>> > +                bb.warn("%s is already a symlink! Not symlinking kernel sources" % s)
>> > +                return 0
>> >              shutil.move(s, kernsrc)
>> >              os.symlink(kernsrc, s)
>> >  }
>>
>> Usually what we recommend is that the first pass does something if "if
>> not exists X.org; cp X X.orig; fi", then you can always copy from
>> X.orig.
>>
>> As Bruce says, it definitely shouldn't be a warning, this can happen
>> quite normally.
>>
>> Cheers,
>>
>> Richard
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#192635): https://lists.openembedded.org/g/openembedded-core/message/192635
> Mute This Topic: https://lists.openembedded.org/mt/103208527/1050810
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [bruce.ashfield@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>


--
- Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end
- "Use the force Harry" - Gandalf, Star Trek II
Etienne Cordonnier Dec. 18, 2023, 5:39 p.m. UTC | #5
Hi Bruce,
can you please clarify? Are you saying that you prefer the version of
the patch which I pasted with shutil.copytree?

The condition to trigger the issue is not that rare, e.g. anybody updating
from kirkstone 4.0.12 to 4.0.13 and doing an incremental build will get a
build failure if S doesn't have the default value (in my case the BSP layer
overrides S). In the same way, if we merge the version with
shutil.copytree, people will need to perform a manual clean, or they may
get build failures.

Etienne

On Mon, Dec 18, 2023 at 3:25 PM Bruce Ashfield <bruce.ashfield@gmail.com>
wrote:

> On Mon, Dec 18, 2023 at 6:45 AM Etienne Cordonnier via
> lists.openembedded.org <ecordonnier=snap.com@lists.openembedded.org>
> wrote:
> >
> > My thinking was that in my local build I was updating from a build
> without
> https://github.com/yoctoproject/poky/commit/3b8d0acca30c806fb69fc3096d41593cc76ed22c
> to a build containing this commit, so the behavior of do_symlink_kernsrc
> got modified, but my incremental build is not executing the new version of
> the code since it detects that the symlink already exists and then the rest
> of the function gets skipped, so I thought this justified a warning.
> >
> > I'll lower the warning to info, but then this assumes that we will never
> modify do_symlink_kernsrc in a way which is not backwards-compatible.
> >
> > @Richard: the reason I didn't go for the copy to "orig" is that I don't
> see a way to add this without breaking incremental builds (where s is a
> symlink to kernsrc which is potentially modified already by do_patch etc.).
> However I think it would be a cleaner solution than simply skipping the
> code like I did:
>
> If the only way to trigger the issue is through really rare pre-<some
> commit> to post
> that commit that happens to modify the detection/manipulation/other of S
> and the
> symlink, then it is rare enough to just drop an info message breadcrumb
> and keep
> moving.
>
> But if it really is a rare situation like you ran into, or some sort
> of forced execution
> of the task, I don't think that a copy would be an unexpected thing to
> happen.
>
> Bruce
>
> >
> > -        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
> > +            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)
> >
> > Etienne
> >
> >
> > On Sun, Dec 17, 2023 at 8:52 PM Richard Purdie <
> richard.purdie@linuxfoundation.org> wrote:
> >>
> >> On Sat, 2023-12-16 at 14:53 +0100, Etienne Cordonnier via
> >> lists.openembedded.org wrote:
> >> > From: Etienne Cordonnier <ecordonnier@snap.com>
> >> >
> >> > 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://urldefense.proofpoint.com/v2/url?u=https-3A__bugzilla.yoctoproject.org_show-5Fbug.cgi-3Fid-3D15325&d=DwIFaQ&c=ncDTmphkJTvjIDPh0hpF_4vCHvabgGkICC2epckfdiw&r=AhkbNonVuMIGRfPx_Qj9TsRih1DULJTKUkSGa66m67E&m=qcRut2Wm9dH26YP_YovPl6QVczLOYUxs1xfzA75ZJBiHj4dWwxbAS-2JjGPlyiyS&s=_WTBsDroHfmiIIyCOXRV2CAId9PmKZ4sN3bRO3EOcyU&e=
> >> >
> >> > Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
> >> > ---
> >> >  meta/classes-recipe/kernel.bbclass | 5 +++++
> >> >  1 file changed, 5 insertions(+)
> >> >
> >> > diff --git a/meta/classes-recipe/kernel.bbclass
> b/meta/classes-recipe/kernel.bbclass
> >> > index 9ff37f5c38..130bedd901 100644
> >> > --- a/meta/classes-recipe/kernel.bbclass
> >> > +++ b/meta/classes-recipe/kernel.bbclass
> >> > @@ -194,6 +194,11 @@ python do_symlink_kernsrc () {
> >> >              os.symlink(s, kernsrc)
> >> >          else:
> >> >              import shutil
> >> > +            if os.path.islink(s):
> >> > +                # this happens for instance when a poky update
> forces symlink_kernsrc to run again
> >> > +                # after s was already moved to kernsrc
> >> > +                bb.warn("%s is already a symlink! Not symlinking
> kernel sources" % s)
> >> > +                return 0
> >> >              shutil.move(s, kernsrc)
> >> >              os.symlink(kernsrc, s)
> >> >  }
> >>
> >> Usually what we recommend is that the first pass does something if "if
> >> not exists X.org; cp X X.orig; fi", then you can always copy from
> >> X.orig.
> >>
> >> As Bruce says, it definitely shouldn't be a warning, this can happen
> >> quite normally.
> >>
> >> Cheers,
> >>
> >> Richard
> >
> >
> > -=-=-=-=-=-=-=-=-=-=-=-
> > Links: You receive all messages sent to this group.
> > View/Reply Online (#192635):
> https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_g_openembedded-2Dcore_message_192635&d=DwIFaQ&c=ncDTmphkJTvjIDPh0hpF_4vCHvabgGkICC2epckfdiw&r=AhkbNonVuMIGRfPx_Qj9TsRih1DULJTKUkSGa66m67E&m=82QaxN_7mSeykh83DV-qNXJc9JezHaPCHv4jG2rrq55pywmZCA6Nz75KaUoSuFn8&s=xGE3OScznEMBXLhPR_DdKU6FPE6dbxsHXhKnfksbT8U&e=
> > Mute This Topic:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_mt_103208527_1050810&d=DwIFaQ&c=ncDTmphkJTvjIDPh0hpF_4vCHvabgGkICC2epckfdiw&r=AhkbNonVuMIGRfPx_Qj9TsRih1DULJTKUkSGa66m67E&m=82QaxN_7mSeykh83DV-qNXJc9JezHaPCHv4jG2rrq55pywmZCA6Nz75KaUoSuFn8&s=GX9x-WmhPnkZRNBnirDhR76l6Laww76WDH7ZwKCFSKQ&e=
> > Group Owner: openembedded-core+owner@lists.openembedded.org
> > Unsubscribe:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_g_openembedded-2Dcore_unsub&d=DwIFaQ&c=ncDTmphkJTvjIDPh0hpF_4vCHvabgGkICC2epckfdiw&r=AhkbNonVuMIGRfPx_Qj9TsRih1DULJTKUkSGa66m67E&m=82QaxN_7mSeykh83DV-qNXJc9JezHaPCHv4jG2rrq55pywmZCA6Nz75KaUoSuFn8&s=roqLGNR0ewaxjmAl_ZE8nSZf_6sCh3yj7LXuITei5EA&e=
> [bruce.ashfield@gmail.com]
> > -=-=-=-=-=-=-=-=-=-=-=-
> >
>
>
> --
> - Thou shalt not follow the NULL pointer, for chaos and madness await
> thee at its end
> - "Use the force Harry" - Gandalf, Star Trek II
>
Bruce Ashfield Dec. 18, 2023, 6:22 p.m. UTC | #6
On Mon, Dec 18, 2023 at 12:39 PM Etienne Cordonnier
<ecordonnier@snap.com> wrote:
>
> Hi Bruce,
> can you please clarify? Are you saying that you prefer the version of the patch which I pasted with shutil.copytree?
>
> The condition to trigger the issue is not that rare, e.g. anybody updating from kirkstone 4.0.12 to 4.0.13 and doing an incremental build will get a build failure if S doesn't have the default value (in my case the BSP layer overrides S). In the same way, if we merge the version with shutil.copytree, people will need to perform a manual clean, or they may get build failures.

For my rarity comment, I meant that it isn't within a typical flow
of bitbaking an image, forcing a task, and bitbaking again. If someone is
doing a meta-layer update, and re-using their build (I have quite literally
7 year old directories like this) then they will run into some issues from time
to time (and folks doing this, normally know how to get themselves out
of trouble).

Taking that into consideration, I just mean that I'd be ok with a copy of the
files, as it is really an update to  "the latest structure" and if you are doing
it on an existing build, that's one of the consequences.

Bruce

>
> Etienne
>
> On Mon, Dec 18, 2023 at 3:25 PM Bruce Ashfield <bruce.ashfield@gmail.com> wrote:
>>
>> On Mon, Dec 18, 2023 at 6:45 AM Etienne Cordonnier via
>> lists.openembedded.org <ecordonnier=snap.com@lists.openembedded.org>
>> wrote:
>> >
>> > My thinking was that in my local build I was updating from a build without https://github.com/yoctoproject/poky/commit/3b8d0acca30c806fb69fc3096d41593cc76ed22c to a build containing this commit, so the behavior of do_symlink_kernsrc got modified, but my incremental build is not executing the new version of the code since it detects that the symlink already exists and then the rest of the function gets skipped, so I thought this justified a warning.
>> >
>> > I'll lower the warning to info, but then this assumes that we will never modify do_symlink_kernsrc in a way which is not backwards-compatible.
>> >
>> > @Richard: the reason I didn't go for the copy to "orig" is that I don't see a way to add this without breaking incremental builds (where s is a symlink to kernsrc which is potentially modified already by do_patch etc.). However I think it would be a cleaner solution than simply skipping the code like I did:
>>
>> If the only way to trigger the issue is through really rare pre-<some
>> commit> to post
>> that commit that happens to modify the detection/manipulation/other of S and the
>> symlink, then it is rare enough to just drop an info message breadcrumb and keep
>> moving.
>>
>> But if it really is a rare situation like you ran into, or some sort
>> of forced execution
>> of the task, I don't think that a copy would be an unexpected thing to happen.
>>
>> Bruce
>>
>> >
>> > -        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
>> > +            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)
>> >
>> > Etienne
>> >
>> >
>> > On Sun, Dec 17, 2023 at 8:52 PM Richard Purdie <richard.purdie@linuxfoundation.org> wrote:
>> >>
>> >> On Sat, 2023-12-16 at 14:53 +0100, Etienne Cordonnier via
>> >> lists.openembedded.org wrote:
>> >> > From: Etienne Cordonnier <ecordonnier@snap.com>
>> >> >
>> >> > 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://urldefense.proofpoint.com/v2/url?u=https-3A__bugzilla.yoctoproject.org_show-5Fbug.cgi-3Fid-3D15325&d=DwIFaQ&c=ncDTmphkJTvjIDPh0hpF_4vCHvabgGkICC2epckfdiw&r=AhkbNonVuMIGRfPx_Qj9TsRih1DULJTKUkSGa66m67E&m=qcRut2Wm9dH26YP_YovPl6QVczLOYUxs1xfzA75ZJBiHj4dWwxbAS-2JjGPlyiyS&s=_WTBsDroHfmiIIyCOXRV2CAId9PmKZ4sN3bRO3EOcyU&e=
>> >> >
>> >> > Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
>> >> > ---
>> >> >  meta/classes-recipe/kernel.bbclass | 5 +++++
>> >> >  1 file changed, 5 insertions(+)
>> >> >
>> >> > diff --git a/meta/classes-recipe/kernel.bbclass b/meta/classes-recipe/kernel.bbclass
>> >> > index 9ff37f5c38..130bedd901 100644
>> >> > --- a/meta/classes-recipe/kernel.bbclass
>> >> > +++ b/meta/classes-recipe/kernel.bbclass
>> >> > @@ -194,6 +194,11 @@ python do_symlink_kernsrc () {
>> >> >              os.symlink(s, kernsrc)
>> >> >          else:
>> >> >              import shutil
>> >> > +            if os.path.islink(s):
>> >> > +                # this happens for instance when a poky update forces symlink_kernsrc to run again
>> >> > +                # after s was already moved to kernsrc
>> >> > +                bb.warn("%s is already a symlink! Not symlinking kernel sources" % s)
>> >> > +                return 0
>> >> >              shutil.move(s, kernsrc)
>> >> >              os.symlink(kernsrc, s)
>> >> >  }
>> >>
>> >> Usually what we recommend is that the first pass does something if "if
>> >> not exists X.org; cp X X.orig; fi", then you can always copy from
>> >> X.orig.
>> >>
>> >> As Bruce says, it definitely shouldn't be a warning, this can happen
>> >> quite normally.
>> >>
>> >> Cheers,
>> >>
>> >> Richard
>> >
>> >
>> > -=-=-=-=-=-=-=-=-=-=-=-
>> > Links: You receive all messages sent to this group.
>> > View/Reply Online (#192635): https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_g_openembedded-2Dcore_message_192635&d=DwIFaQ&c=ncDTmphkJTvjIDPh0hpF_4vCHvabgGkICC2epckfdiw&r=AhkbNonVuMIGRfPx_Qj9TsRih1DULJTKUkSGa66m67E&m=82QaxN_7mSeykh83DV-qNXJc9JezHaPCHv4jG2rrq55pywmZCA6Nz75KaUoSuFn8&s=xGE3OScznEMBXLhPR_DdKU6FPE6dbxsHXhKnfksbT8U&e=
>> > Mute This Topic: https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_mt_103208527_1050810&d=DwIFaQ&c=ncDTmphkJTvjIDPh0hpF_4vCHvabgGkICC2epckfdiw&r=AhkbNonVuMIGRfPx_Qj9TsRih1DULJTKUkSGa66m67E&m=82QaxN_7mSeykh83DV-qNXJc9JezHaPCHv4jG2rrq55pywmZCA6Nz75KaUoSuFn8&s=GX9x-WmhPnkZRNBnirDhR76l6Laww76WDH7ZwKCFSKQ&e=
>> > Group Owner: openembedded-core+owner@lists.openembedded.org
>> > Unsubscribe: https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.openembedded.org_g_openembedded-2Dcore_unsub&d=DwIFaQ&c=ncDTmphkJTvjIDPh0hpF_4vCHvabgGkICC2epckfdiw&r=AhkbNonVuMIGRfPx_Qj9TsRih1DULJTKUkSGa66m67E&m=82QaxN_7mSeykh83DV-qNXJc9JezHaPCHv4jG2rrq55pywmZCA6Nz75KaUoSuFn8&s=roqLGNR0ewaxjmAl_ZE8nSZf_6sCh3yj7LXuITei5EA&e=  [bruce.ashfield@gmail.com]
>> > -=-=-=-=-=-=-=-=-=-=-=-
>> >
>>
>>
>> --
>> - Thou shalt not follow the NULL pointer, for chaos and madness await
>> thee at its end
>> - "Use the force Harry" - Gandalf, Star Trek II
diff mbox series

Patch

diff --git a/meta/classes-recipe/kernel.bbclass b/meta/classes-recipe/kernel.bbclass
index 9ff37f5c38..130bedd901 100644
--- a/meta/classes-recipe/kernel.bbclass
+++ b/meta/classes-recipe/kernel.bbclass
@@ -194,6 +194,11 @@  python do_symlink_kernsrc () {
             os.symlink(s, kernsrc)
         else:
             import shutil
+            if os.path.islink(s):
+                # this happens for instance when a poky update forces symlink_kernsrc to run again
+                # after s was already moved to kernsrc
+                bb.warn("%s is already a symlink! Not symlinking kernel sources" % s)
+                return 0
             shutil.move(s, kernsrc)
             os.symlink(kernsrc, s)
 }