public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
* Unexpected behavior with class-native and class-target in combination with inherit(_defer)
@ 2024-08-28  9:40 Jasper Orschulko
  2024-08-28 11:01 ` [OE-core] " Richard Purdie
  0 siblings, 1 reply; 2+ messages in thread
From: Jasper Orschulko @ 2024-08-28  9:40 UTC (permalink / raw)
  To: openembedded-core@lists.openembedded.org; +Cc: Erik Schumacher

Hi,

we are on the latest scarthgap and trying to use class-target to do
target specific overrides, as described in
https://docs.yoctoproject.org/4.0.20/singleindex.html#native.

We tried removing python from PACKAGECONFIG:class-target. However, this
breaks the native build of libxml2.

This is due to the following inherit_defer statement not being called
on native:
https://github.com/yoctoproject/poky/blob/cf9d8807f80c5715daed11b5bcbb4378dcbcbd54/meta/recipes-core/libxml/libxml2_2.12.8.bb#L39

We were able to reproduce this with a minimal example consisting of a
.bb file and a .bbclass file:


test.bb:
```
SUMMARY = "Test"
LICENSE = "CLOSED"
LIC_FILES_CHKSUM = ""

SOMEVAR = "foo bar"
SOMEVAR:remove:class-target = "bar"

inherit_defer ${@bb.utils.contains('SOMEVAR', 'bar', 'testclass', '',
d)}

do_install() {
    install -d ${D}/test/
    echo "Value SOMEVAR: ${SOMEVAR}" >> ${D}/test/output
    echo "Value TESTCLASSVAR: ${TESTCLASSVAR}" >> ${D}/test/output
    echo "SOMEVAR contains 'foo'? ${@bb.utils.contains('SOMEVAR',
'foo', 'true', 'false', d)}" >> ${D}/test/output
    echo "SOMEVAR contains 'bar'? ${@bb.utils.contains('SOMEVAR',
'bar', 'true', 'false', d)}" >> ${D}/test/output
}

FILES:${PN} += "/test/output"

BBCLASSEXTEND = "native"
```

and testclass.bbclass:
```
TESTCLASSVAR = "foobar"
```

We would expect that the inherit is executed for native, but not for
target, thus the variable TESTCLASSVAR to be set in native. However,
inherit is not called for either of them, as seen in the test output:

Target:
```
Value SOMEVAR: foo 
Value TESTCLASSVAR: 
SOMEVAR contains 'foo'? true
SOMEVAR contains 'bar'? false
```

Native:
```
Value SOMEVAR: foo bar
Value TESTCLASSVAR:
SOMEVAR contains 'foo'? true
SOMEVAR contains 'bar'? true
```

Vice versa, when removing from class-native the inherit statement is
always called, not only on the target as we would expect.

Is this a known limitation or a bug?

Best,
Jasper

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

* Re: [OE-core] Unexpected behavior with class-native and class-target in combination with inherit(_defer)
  2024-08-28  9:40 Unexpected behavior with class-native and class-target in combination with inherit(_defer) Jasper Orschulko
@ 2024-08-28 11:01 ` Richard Purdie
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Purdie @ 2024-08-28 11:01 UTC (permalink / raw)
  To: Jasper.Orschulko, openembedded-core@lists.openembedded.org
  Cc: Erik Schumacher

On Wed, 2024-08-28 at 09:40 +0000, Jasper Orschulko via lists.openembedded.org wrote:
> we are on the latest scarthgap and trying to use class-target to do
> target specific overrides, as described in
> https://docs.yoctoproject.org/4.0.20/singleindex.html#native.
> 
> We tried removing python from PACKAGECONFIG:class-target. However, this
> breaks the native build of libxml2.
> 
> This is due to the following inherit_defer statement not being called
> on native:
> https://github.com/yoctoproject/poky/blob/cf9d8807f80c5715daed11b5bcbb4378dcbcbd54/meta/recipes-core/libxml/libxml2_2.12.8.bb#L39
> 
> We were able to reproduce this with a minimal example consisting of a
> .bb file and a .bbclass file:
> 
> 
> test.bb:
> ```
> SUMMARY = "Test"
> LICENSE = "CLOSED"
> LIC_FILES_CHKSUM = ""
> 
> SOMEVAR = "foo bar"
> SOMEVAR:remove:class-target = "bar"
> 
> inherit_defer ${@bb.utils.contains('SOMEVAR', 'bar', 'testclass', '',
> d)}
> 
> do_install() {
>     install -d ${D}/test/
>     echo "Value SOMEVAR: ${SOMEVAR}" >> ${D}/test/output
>     echo "Value TESTCLASSVAR: ${TESTCLASSVAR}" >> ${D}/test/output
>     echo "SOMEVAR contains 'foo'? ${@bb.utils.contains('SOMEVAR',
> 'foo', 'true', 'false', d)}" >> ${D}/test/output
>     echo "SOMEVAR contains 'bar'? ${@bb.utils.contains('SOMEVAR',
> 'bar', 'true', 'false', d)}" >> ${D}/test/output
> }
> 
> FILES:${PN} += "/test/output"
> 
> BBCLASSEXTEND = "native"
> ```
> 
> and testclass.bbclass:
> ```
> TESTCLASSVAR = "foobar"
> ```
> 
> We would expect that the inherit is executed for native, but not for
> target, thus the variable TESTCLASSVAR to be set in native. However,
> inherit is not called for either of them, as seen in the test output:
> 
> Target:
> ```
> Value SOMEVAR: foo 
> Value TESTCLASSVAR: 
> SOMEVAR contains 'foo'? true
> SOMEVAR contains 'bar'? false
> ```
> 
> Native:
> ```
> Value SOMEVAR: foo bar
> Value TESTCLASSVAR:
> SOMEVAR contains 'foo'? true
> SOMEVAR contains 'bar'? true
> ```
> 
> Vice versa, when removing from class-native the inherit statement is
> always called, not only on the target as we would expect.
> 
> Is this a known limitation or a bug?

It is a known rather annoying limitation of inherit_defer :(

The trouble is that BBCLASSEXTEND = "native" is also something which
happens at the end of parsing. The expansion of inherit_defer happens
before BBCLASSEXTEND. You can't really swap them since native and other
extensions are meant to happen last. This means overrides that come
from the BBCLASSEXTEND don't function when used with inherit_defer.
Something always has to come last and I'm not sure what we can do to
improve this.

I did wonder about adding logic to set the class override earlier
somehow but it is hard to make work reliably for all cases.

Cheers,

Richard



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

end of thread, other threads:[~2024-08-28 11:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-28  9:40 Unexpected behavior with class-native and class-target in combination with inherit(_defer) Jasper Orschulko
2024-08-28 11:01 ` [OE-core] " Richard Purdie

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