diff mbox series

meson.bbclass: Split into meson-common and meson classes

Message ID 20230315080020.2648416-1-zboszor@gmail.com
State New
Headers show
Series meson.bbclass: Split into meson-common and meson classes | expand

Commit Message

Böszörményi Zoltán March 15, 2023, 8 a.m. UTC
The new meson-common class will be used by a new PEP517 python
build class using meson-python a.k.a. mesonpy.

Signed-off-by: Zoltán Böszörményi <zboszor@gmail.com>
---
 meta/classes-recipe/meson-common.bbclass | 141 +++++++++++++++++++++++
 meta/classes-recipe/meson.bbclass        | 136 +---------------------
 2 files changed, 142 insertions(+), 135 deletions(-)
 create mode 100644 meta/classes-recipe/meson-common.bbclass

Comments

Ross Burton March 15, 2023, 4:52 p.m. UTC | #1
On 15 Mar 2023, at 08:00, Zoltan Boszormenyi via lists.openembedded.org <zboszor=gmail.com@lists.openembedded.org> wrote:
> diff --git a/meta/classes-recipe/meson.bbclass b/meta/classes-recipe/meson.bbclass
> index 48688bed75..f1273aa1c0 100644
> --- a/meta/classes-recipe/meson.bbclass
> +++ b/meta/classes-recipe/meson.bbclass
> @@ -4,141 +4,7 @@
> # SPDX-License-Identifier: MIT
> #
> 
> -inherit python3native meson-routines qemu
> -
> -DEPENDS:append = " meson-native ninja-native"
> -
> -EXEWRAPPER_ENABLED:class-native = "False"
> -EXEWRAPPER_ENABLED:class-nativesdk = "False"
> -EXEWRAPPER_ENABLED ?= "${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d)}"
> -DEPENDS:append = "${@' qemu-native' if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ''}"
> -
> -# As Meson enforces out-of-tree builds we can just use cleandirs
> -B = "${WORKDIR}/build"
> -do_configure[cleandirs] = "${B}"
> -
> -# Where the meson.build build configuration is
> -MESON_SOURCEPATH = "${S}"
> -
> -def noprefix(var, d):
> -    return d.getVar(var).replace(d.getVar('prefix') + '/', '', 1)
> -
> -MESON_BUILDTYPE ?= "${@oe.utils.vartrue('DEBUG_BUILD', 'debug', 'plain', d)}"
> -MESON_BUILDTYPE[vardeps] += "DEBUG_BUILD"
> -MESONOPTS = " --prefix ${prefix} \
> -              --buildtype ${MESON_BUILDTYPE} \
> -              --bindir ${@noprefix('bindir', d)} \
> -              --sbindir ${@noprefix('sbindir', d)} \
> -              --datadir ${@noprefix('datadir', d)} \
> -              --libdir ${@noprefix('libdir', d)} \
> -              --libexecdir ${@noprefix('libexecdir', d)} \
> -              --includedir ${@noprefix('includedir', d)} \
> -              --mandir ${@noprefix('mandir', d)} \
> -              --infodir ${@noprefix('infodir', d)} \
> -              --sysconfdir ${sysconfdir} \
> -              --localstatedir ${localstatedir} \
> -              --sharedstatedir ${sharedstatedir} \
> -              --wrap-mode nodownload \
> -              --native-file ${WORKDIR}/meson.native"
> -
> -EXTRA_OEMESON:append = " ${PACKAGECONFIG_CONFARGS}"
> -
> -MESON_CROSS_FILE = ""
> -MESON_CROSS_FILE:class-target = "--cross-file ${WORKDIR}/meson.cross"
> -MESON_CROSS_FILE:class-nativesdk = "--cross-file ${WORKDIR}/meson.cross"
> -
> -# Needed to set up qemu wrapper below
> -export STAGING_DIR_HOST
> -
> -def rust_tool(d, target_var):
> -    rustc = d.getVar('RUSTC')
> -    if not rustc:
> -        return ""
> -    cmd = [rustc, "--target", d.getVar(target_var)] + d.getVar("RUSTFLAGS").split()
> -    return "rust = %s" % repr(cmd)
> -
> -addtask write_config before do_configure
> -do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS RUSTC RUSTFLAGS"
> -do_write_config() {
> -    # This needs to be Py to split the args into single-element lists
> -    cat >${WORKDIR}/meson.cross <<EOF
> -[binaries]
> -c = ${@meson_array('CC', d)}
> -cpp = ${@meson_array('CXX', d)}
> -cython = 'cython3'
> -ar = ${@meson_array('AR', d)}
> -nm = ${@meson_array('NM', d)}
> -strip = ${@meson_array('STRIP', d)}
> -readelf = ${@meson_array('READELF', d)}
> -objcopy = ${@meson_array('OBJCOPY', d)}
> -pkgconfig = 'pkg-config'
> -llvm-config = 'llvm-config'
> -cups-config = 'cups-config'
> -g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper'
> -g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper'
> -${@rust_tool(d, "HOST_SYS")}
> -${@"exe_wrapper = '${WORKDIR}/meson-qemuwrapper'" if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ""}
> -
> -[built-in options]
> -c_args = ${@meson_array('CFLAGS', d)}
> -c_link_args = ${@meson_array('LDFLAGS', d)}
> -cpp_args = ${@meson_array('CXXFLAGS', d)}
> -cpp_link_args = ${@meson_array('LDFLAGS', d)}
> -
> -[properties]
> -needs_exe_wrapper = true
> -
> -[host_machine]
> -system = '${@meson_operating_system('HOST_OS', d)}'
> -cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}'
> -cpu = '${HOST_ARCH}'
> -endian = '${@meson_endian('HOST', d)}'
> -
> -[target_machine]
> -system = '${@meson_operating_system('TARGET_OS', d)}'
> -cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}'
> -cpu = '${TARGET_ARCH}'
> -endian = '${@meson_endian('TARGET', d)}'
> -EOF
> -
> -    cat >${WORKDIR}/meson.native <<EOF
> -[binaries]
> -c = ${@meson_array('BUILD_CC', d)}
> -cpp = ${@meson_array('BUILD_CXX', d)}
> -cython = 'cython3'
> -ar = ${@meson_array('BUILD_AR', d)}
> -nm = ${@meson_array('BUILD_NM', d)}
> -strip = ${@meson_array('BUILD_STRIP', d)}
> -readelf = ${@meson_array('BUILD_READELF', d)}
> -objcopy = ${@meson_array('BUILD_OBJCOPY', d)}
> -pkgconfig = 'pkg-config-native'
> -${@rust_tool(d, "BUILD_SYS")}
> -
> -[built-in options]
> -c_args = ${@meson_array('BUILD_CFLAGS', d)}
> -c_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
> -cpp_args = ${@meson_array('BUILD_CXXFLAGS', d)}
> -cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
> -EOF
> -}
> -
> -do_write_config:append:class-target() {
> -    # Write out a qemu wrapper that will be used as exe_wrapper so that meson
> -    # can run target helper binaries through that.
> -    qemu_binary="${@qemu_wrapper_cmdline(d, '$STAGING_DIR_HOST', ['$STAGING_DIR_HOST/${libdir}','$STAGING_DIR_HOST/${base_libdir}'])}"
> -    cat > ${WORKDIR}/meson-qemuwrapper << EOF
> -#!/bin/sh
> -# Use a modules directory which doesn't exist so we don't load random things
> -# which may then get deleted (or their dependencies) and potentially segfault
> -export GIO_MODULE_DIR=${STAGING_LIBDIR}/gio/modules-dummy
> -
> -# meson sets this wrongly (only to libs in build-dir), qemu_wrapper_cmdline() and GIR_EXTRA_LIBS_PATH take care of it properly
> -unset LD_LIBRARY_PATH
> -
> -$qemu_binary "\$@"
> -EOF
> -    chmod +x ${WORKDIR}/meson-qemuwrapper
> -}
> +inherit meson-common
> 
> # Tell externalsrc that changes to this file require a reconfigure
> CONFIGURE_FILES = “meson.build”

This patch appears to move every line from meson.bbclass to meson-common.bbclass, apart from the CONFIGURE_FILES line which would still be needed in the python-meson case anyway.

I can’t see what is gained here, just inherit meson.

Ross
Böszörményi Zoltán March 15, 2023, 5:20 p.m. UTC | #2
2023. 03. 15. 17:52 keltezéssel, Ross Burton írta:
> On 15 Mar 2023, at 08:00, Zoltan Boszormenyi via lists.openembedded.org <zboszor=gmail.com@lists.openembedded.org> wrote:
>> diff --git a/meta/classes-recipe/meson.bbclass b/meta/classes-recipe/meson.bbclass
>> index 48688bed75..f1273aa1c0 100644
>> --- a/meta/classes-recipe/meson.bbclass
>> +++ b/meta/classes-recipe/meson.bbclass
>> @@ -4,141 +4,7 @@
>> # SPDX-License-Identifier: MIT
>> #
>>
>> -inherit python3native meson-routines qemu
>> -
>> -DEPENDS:append = " meson-native ninja-native"
>> -
>> -EXEWRAPPER_ENABLED:class-native = "False"
>> -EXEWRAPPER_ENABLED:class-nativesdk = "False"
>> -EXEWRAPPER_ENABLED ?= "${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d)}"
>> -DEPENDS:append = "${@' qemu-native' if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ''}"
>> -
>> -# As Meson enforces out-of-tree builds we can just use cleandirs
>> -B = "${WORKDIR}/build"
>> -do_configure[cleandirs] = "${B}"
>> -
>> -# Where the meson.build build configuration is
>> -MESON_SOURCEPATH = "${S}"
>> -
>> -def noprefix(var, d):
>> -    return d.getVar(var).replace(d.getVar('prefix') + '/', '', 1)
>> -
>> -MESON_BUILDTYPE ?= "${@oe.utils.vartrue('DEBUG_BUILD', 'debug', 'plain', d)}"
>> -MESON_BUILDTYPE[vardeps] += "DEBUG_BUILD"
>> -MESONOPTS = " --prefix ${prefix} \
>> -              --buildtype ${MESON_BUILDTYPE} \
>> -              --bindir ${@noprefix('bindir', d)} \
>> -              --sbindir ${@noprefix('sbindir', d)} \
>> -              --datadir ${@noprefix('datadir', d)} \
>> -              --libdir ${@noprefix('libdir', d)} \
>> -              --libexecdir ${@noprefix('libexecdir', d)} \
>> -              --includedir ${@noprefix('includedir', d)} \
>> -              --mandir ${@noprefix('mandir', d)} \
>> -              --infodir ${@noprefix('infodir', d)} \
>> -              --sysconfdir ${sysconfdir} \
>> -              --localstatedir ${localstatedir} \
>> -              --sharedstatedir ${sharedstatedir} \
>> -              --wrap-mode nodownload \
>> -              --native-file ${WORKDIR}/meson.native"
>> -
>> -EXTRA_OEMESON:append = " ${PACKAGECONFIG_CONFARGS}"
>> -
>> -MESON_CROSS_FILE = ""
>> -MESON_CROSS_FILE:class-target = "--cross-file ${WORKDIR}/meson.cross"
>> -MESON_CROSS_FILE:class-nativesdk = "--cross-file ${WORKDIR}/meson.cross"
>> -
>> -# Needed to set up qemu wrapper below
>> -export STAGING_DIR_HOST
>> -
>> -def rust_tool(d, target_var):
>> -    rustc = d.getVar('RUSTC')
>> -    if not rustc:
>> -        return ""
>> -    cmd = [rustc, "--target", d.getVar(target_var)] + d.getVar("RUSTFLAGS").split()
>> -    return "rust = %s" % repr(cmd)
>> -
>> -addtask write_config before do_configure
>> -do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS RUSTC RUSTFLAGS"
>> -do_write_config() {
>> -    # This needs to be Py to split the args into single-element lists
>> -    cat >${WORKDIR}/meson.cross <<EOF
>> -[binaries]
>> -c = ${@meson_array('CC', d)}
>> -cpp = ${@meson_array('CXX', d)}
>> -cython = 'cython3'
>> -ar = ${@meson_array('AR', d)}
>> -nm = ${@meson_array('NM', d)}
>> -strip = ${@meson_array('STRIP', d)}
>> -readelf = ${@meson_array('READELF', d)}
>> -objcopy = ${@meson_array('OBJCOPY', d)}
>> -pkgconfig = 'pkg-config'
>> -llvm-config = 'llvm-config'
>> -cups-config = 'cups-config'
>> -g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper'
>> -g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper'
>> -${@rust_tool(d, "HOST_SYS")}
>> -${@"exe_wrapper = '${WORKDIR}/meson-qemuwrapper'" if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ""}
>> -
>> -[built-in options]
>> -c_args = ${@meson_array('CFLAGS', d)}
>> -c_link_args = ${@meson_array('LDFLAGS', d)}
>> -cpp_args = ${@meson_array('CXXFLAGS', d)}
>> -cpp_link_args = ${@meson_array('LDFLAGS', d)}
>> -
>> -[properties]
>> -needs_exe_wrapper = true
>> -
>> -[host_machine]
>> -system = '${@meson_operating_system('HOST_OS', d)}'
>> -cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}'
>> -cpu = '${HOST_ARCH}'
>> -endian = '${@meson_endian('HOST', d)}'
>> -
>> -[target_machine]
>> -system = '${@meson_operating_system('TARGET_OS', d)}'
>> -cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}'
>> -cpu = '${TARGET_ARCH}'
>> -endian = '${@meson_endian('TARGET', d)}'
>> -EOF
>> -
>> -    cat >${WORKDIR}/meson.native <<EOF
>> -[binaries]
>> -c = ${@meson_array('BUILD_CC', d)}
>> -cpp = ${@meson_array('BUILD_CXX', d)}
>> -cython = 'cython3'
>> -ar = ${@meson_array('BUILD_AR', d)}
>> -nm = ${@meson_array('BUILD_NM', d)}
>> -strip = ${@meson_array('BUILD_STRIP', d)}
>> -readelf = ${@meson_array('BUILD_READELF', d)}
>> -objcopy = ${@meson_array('BUILD_OBJCOPY', d)}
>> -pkgconfig = 'pkg-config-native'
>> -${@rust_tool(d, "BUILD_SYS")}
>> -
>> -[built-in options]
>> -c_args = ${@meson_array('BUILD_CFLAGS', d)}
>> -c_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
>> -cpp_args = ${@meson_array('BUILD_CXXFLAGS', d)}
>> -cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
>> -EOF
>> -}
>> -
>> -do_write_config:append:class-target() {
>> -    # Write out a qemu wrapper that will be used as exe_wrapper so that meson
>> -    # can run target helper binaries through that.
>> -    qemu_binary="${@qemu_wrapper_cmdline(d, '$STAGING_DIR_HOST', ['$STAGING_DIR_HOST/${libdir}','$STAGING_DIR_HOST/${base_libdir}'])}"
>> -    cat > ${WORKDIR}/meson-qemuwrapper << EOF
>> -#!/bin/sh
>> -# Use a modules directory which doesn't exist so we don't load random things
>> -# which may then get deleted (or their dependencies) and potentially segfault
>> -export GIO_MODULE_DIR=${STAGING_LIBDIR}/gio/modules-dummy
>> -
>> -# meson sets this wrongly (only to libs in build-dir), qemu_wrapper_cmdline() and GIR_EXTRA_LIBS_PATH take care of it properly
>> -unset LD_LIBRARY_PATH
>> -
>> -$qemu_binary "\$@"
>> -EOF
>> -    chmod +x ${WORKDIR}/meson-qemuwrapper
>> -}
>> +inherit meson-common
>>
>> # Tell externalsrc that changes to this file require a reconfigure
>> CONFIGURE_FILES = “meson.build”
> This patch appears to move every line from meson.bbclass to meson-common.bbclass,

It's the other way around but git is stupid. What was done is:

git mv meson.bbclass meson-common.bbclass

then moved a few lined from the end of it to the new meson.bbclass file.

Should I do this in two commits to make it reflect what is actually done?

>   apart from the CONFIGURE_FILES line which would still be needed in the python-meson case anyway.
>
> I can’t see what is gained here, just inherit meson.

The problem is that "inherit meson python_pep517" ends up with

do_configure () {
     meson_do_configure
}

do_compile () {
     meson_do_compile
}

when the python_pep517_ prefixed ones are needed.
It has something to do with the fact that both has the line

EXPORT_FUNCTIONS do_configure do_compile do_install

Which one wins may depend on inheritance order but
who's to say for sure and why can't this be order agnostic?

I need most of meson.bbclass for the settings in the new
meta_mesonpy class to pass to meson but using the pep517
machinery.
Böszörményi Zoltán March 15, 2023, 5:34 p.m. UTC | #3
2023. 03. 15. 17:52 keltezéssel, Ross Burton írta:
> ... apart from the CONFIGURE_FILES line which would still be needed in the python-meson case anyway.

Actually, it doesn't seem so.

It is purely a Yocto setting that doesn't influence running meson.

For pep517 projects this would be the correct setting but it's not
present in currently existing bbclasses:

CONFIGURE_FILES = "pyproject.toml"

Patching the meson settings from meson-common through with this line is enough:

PEP517_BUILD_OPTS = ' --config-settings=setup-args="${MESONOPTS} ... " '
Richard Purdie March 15, 2023, 11:08 p.m. UTC | #4
On Wed, 2023-03-15 at 18:20 +0100, Zoltan Boszormenyi wrote:
> 2023. 03. 15. 17:52 keltezéssel, Ross Burton írta:
> > On 15 Mar 2023, at 08:00, Zoltan Boszormenyi via lists.openembedded.org <zboszor=gmail.com@lists.openembedded.org> wrote:
> > 
> >   apart from the CONFIGURE_FILES line which would still be needed in the python-meson case anyway.
> > 
> > I can’t see what is gained here, just inherit meson.
> 
> The problem is that "inherit meson python_pep517" ends up with
> 
> do_configure () {
>      meson_do_configure
> }
> 
> do_compile () {
>      meson_do_compile
> }
> 
> when the python_pep517_ prefixed ones are needed.
> It has something to do with the fact that both has the line
> 
> EXPORT_FUNCTIONS do_configure do_compile do_install
> 
> Which one wins may depend on inheritance order but
> who's to say for sure and why can't this be order agnostic?

Which one wins being due to inheritance order is by design.

The export functions code adds wrappers meaning by default,
XXXX_do_configure is called by do_configure but if needed you can write
a custom function which does something like:

do_configure () {
    pep517_do_configure
    meson_do_configure
    autotools_do_configure
}
    
i.e. call class specific definitions in an order of your choosing. I
appreciate the above wouldn't make much sense but you see the idea
behind it.

> I need most of meson.bbclass for the settings in the new
> meta_mesonpy class to pass to meson but using the pep517
> machinery.

I really dislike these "common" class abstractions and I think we need
to find a better way to handle things. Order does matter to class
inheritance already so we can rely and document that if needed.

Cheers,

Richard
Böszörményi Zoltán March 16, 2023, 5:23 a.m. UTC | #5
2023. 03. 16. 0:08 keltezéssel, Richard Purdie írta:
> On Wed, 2023-03-15 at 18:20 +0100, Zoltan Boszormenyi wrote:
>> 2023. 03. 15. 17:52 keltezéssel, Ross Burton írta:
>>> On 15 Mar 2023, at 08:00, Zoltan Boszormenyi via lists.openembedded.org <zboszor=gmail.com@lists.openembedded.org> wrote:
>>>
>>>    apart from the CONFIGURE_FILES line which would still be needed in the python-meson case anyway.
>>>
>>> I can’t see what is gained here, just inherit meson.
>> The problem is that "inherit meson python_pep517" ends up with
>>
>> do_configure () {
>>       meson_do_configure
>> }
>>
>> do_compile () {
>>       meson_do_compile
>> }
>>
>> when the python_pep517_ prefixed ones are needed.
>> It has something to do with the fact that both has the line
>>
>> EXPORT_FUNCTIONS do_configure do_compile do_install
>>
>> Which one wins may depend on inheritance order but
>> who's to say for sure and why can't this be order agnostic?
> Which one wins being due to inheritance order is by design.
>
> The export functions code adds wrappers meaning by default,
> XXXX_do_configure is called by do_configure but if needed you can write
> a custom function which does something like:
>
> do_configure () {
>      pep517_do_configure
>      meson_do_configure
>      autotools_do_configure
> }
>      
> i.e. call class specific definitions in an order of your choosing. I
> appreciate the above wouldn't make much sense but you see the idea
> behind it.

I saw a similar pattern and I did something like
that for a PyTorch recipe but it's the thing I didn't like
and felt unclean.

But in this case with meson and pep517 with build-backend = mesonpy,
meson setup/build/install would actually be run twice.

While meson setup with the same options and build may not
take much time the second time, installing can.
I am sure someone wouldn't like that.

There is a saying here that goes like "which of my fingers
should I bite to not hurt?"

>> I need most of meson.bbclass for the settings in the new
>> meta_mesonpy class to pass to meson but using the pep517
>> machinery.
> I really dislike these "common" class abstractions and I think we need
> to find a better way to handle things. Order does matter to class
> inheritance already so we can rely and document that if needed.
>
> Cheers,
>
> Richard
>
Böszörményi Zoltán March 16, 2023, 10:22 a.m. UTC | #6
2023. 03. 16. 0:08 keltezéssel, Richard Purdie írta:
> On Wed, 2023-03-15 at 18:20 +0100, Zoltan Boszormenyi wrote:
>> 2023. 03. 15. 17:52 keltezéssel, Ross Burton írta:
>>> On 15 Mar 2023, at 08:00, Zoltan Boszormenyi via lists.openembedded.org <zboszor=gmail.com@lists.openembedded.org> wrote:
>>>
>>>    apart from the CONFIGURE_FILES line which would still be needed in the python-meson case anyway.
>>>
>>> I can’t see what is gained here, just inherit meson.
>> The problem is that "inherit meson python_pep517" ends up with
>>
>> do_configure () {
>>       meson_do_configure
>> }
>>
>> do_compile () {
>>       meson_do_compile
>> }
>>
>> when the python_pep517_ prefixed ones are needed.
>> It has something to do with the fact that both has the line
>>
>> EXPORT_FUNCTIONS do_configure do_compile do_install
>>
>> Which one wins may depend on inheritance order but
>> who's to say for sure and why can't this be order agnostic?
> Which one wins being due to inheritance order is by design.
>
> The export functions code adds wrappers meaning by default,
> XXXX_do_configure is called by do_configure but if needed you can write
> a custom function which does something like:
>
> do_configure () {
>      pep517_do_configure
>      meson_do_configure
>      autotools_do_configure
> }
>      
> i.e. call class specific definitions in an order of your choosing. I
> appreciate the above wouldn't make much sense but you see the idea
> behind it.
>
>> I need most of meson.bbclass for the settings in the new
>> meta_mesonpy class to pass to meson but using the pep517
>> machinery.
> I really dislike these "common" class abstractions and I think we need
> to find a better way to handle things. Order does matter to class
> inheritance already so we can rely and document that if needed.

So, if I were to use this in the new meta_mesonpy class:

inherit python_pep517 meson

then it will do what I need, even without splitting meson.bbclass into two, right?

I will test this.
Böszörményi Zoltán March 16, 2023, 10:37 a.m. UTC | #7
2023. 03. 16. 11:22 keltezéssel, Zoltan Boszormenyi via lists.openembedded.org írta:
> 2023. 03. 16. 0:08 keltezéssel, Richard Purdie írta:
>> On Wed, 2023-03-15 at 18:20 +0100, Zoltan Boszormenyi wrote:
>>> 2023. 03. 15. 17:52 keltezéssel, Ross Burton írta:
>>>> On 15 Mar 2023, at 08:00, Zoltan Boszormenyi via lists.openembedded.org 
>>>> <zboszor=gmail.com@lists.openembedded.org> wrote:
>>>>
>>>>    apart from the CONFIGURE_FILES line which would still be needed in the 
>>>> python-meson case anyway.
>>>>
>>>> I can’t see what is gained here, just inherit meson.
>>> The problem is that "inherit meson python_pep517" ends up with
>>>
>>> do_configure () {
>>>       meson_do_configure
>>> }
>>>
>>> do_compile () {
>>>       meson_do_compile
>>> }
>>>
>>> when the python_pep517_ prefixed ones are needed.
>>> It has something to do with the fact that both has the line
>>>
>>> EXPORT_FUNCTIONS do_configure do_compile do_install
>>>
>>> Which one wins may depend on inheritance order but
>>> who's to say for sure and why can't this be order agnostic?
>> Which one wins being due to inheritance order is by design.
>>
>> The export functions code adds wrappers meaning by default,
>> XXXX_do_configure is called by do_configure but if needed you can write
>> a custom function which does something like:
>>
>> do_configure () {
>>      pep517_do_configure
>>      meson_do_configure
>>      autotools_do_configure
>> }
>>      i.e. call class specific definitions in an order of your choosing. I
>> appreciate the above wouldn't make much sense but you see the idea
>> behind it.
>>
>>> I need most of meson.bbclass for the settings in the new
>>> meta_mesonpy class to pass to meson but using the pep517
>>> machinery.
>> I really dislike these "common" class abstractions and I think we need
>> to find a better way to handle things. Order does matter to class
>> inheritance already so we can rely and document that if needed.
>
> So, if I were to use this in the new meta_mesonpy class:
>
> inherit python_pep517 meson
>
> then it will do what I need, even without splitting meson.bbclass into two, right?
>
> I will test this.

The result is that still meson_do_configure et.al. are generated
into the build scripts.

Something is not right with with EXPORT_FUNCTIONS then,
it doesn't obey inheritance order if meson always wins.
diff mbox series

Patch

diff --git a/meta/classes-recipe/meson-common.bbclass b/meta/classes-recipe/meson-common.bbclass
new file mode 100644
index 0000000000..e02b3e5ab6
--- /dev/null
+++ b/meta/classes-recipe/meson-common.bbclass
@@ -0,0 +1,141 @@ 
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+inherit python3native meson-routines qemu
+
+DEPENDS:append = " meson-native ninja-native"
+
+EXEWRAPPER_ENABLED:class-native = "False"
+EXEWRAPPER_ENABLED:class-nativesdk = "False"
+EXEWRAPPER_ENABLED ?= "${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d)}"
+DEPENDS:append = "${@' qemu-native' if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ''}"
+
+# As Meson enforces out-of-tree builds we can just use cleandirs
+B = "${WORKDIR}/build"
+do_configure[cleandirs] = "${B}"
+
+# Where the meson.build build configuration is
+MESON_SOURCEPATH = "${S}"
+
+def noprefix(var, d):
+    return d.getVar(var).replace(d.getVar('prefix') + '/', '', 1)
+
+MESON_BUILDTYPE ?= "${@oe.utils.vartrue('DEBUG_BUILD', 'debug', 'plain', d)}"
+MESON_BUILDTYPE[vardeps] += "DEBUG_BUILD"
+MESONOPTS = " --prefix ${prefix} \
+              --buildtype ${MESON_BUILDTYPE} \
+              --bindir ${@noprefix('bindir', d)} \
+              --sbindir ${@noprefix('sbindir', d)} \
+              --datadir ${@noprefix('datadir', d)} \
+              --libdir ${@noprefix('libdir', d)} \
+              --libexecdir ${@noprefix('libexecdir', d)} \
+              --includedir ${@noprefix('includedir', d)} \
+              --mandir ${@noprefix('mandir', d)} \
+              --infodir ${@noprefix('infodir', d)} \
+              --sysconfdir ${sysconfdir} \
+              --localstatedir ${localstatedir} \
+              --sharedstatedir ${sharedstatedir} \
+              --wrap-mode nodownload \
+              --native-file ${WORKDIR}/meson.native"
+
+EXTRA_OEMESON:append = " ${PACKAGECONFIG_CONFARGS}"
+
+MESON_CROSS_FILE = ""
+MESON_CROSS_FILE:class-target = "--cross-file ${WORKDIR}/meson.cross"
+MESON_CROSS_FILE:class-nativesdk = "--cross-file ${WORKDIR}/meson.cross"
+
+# Needed to set up qemu wrapper below
+export STAGING_DIR_HOST
+
+def rust_tool(d, target_var):
+    rustc = d.getVar('RUSTC')
+    if not rustc:
+        return ""
+    cmd = [rustc, "--target", d.getVar(target_var)] + d.getVar("RUSTFLAGS").split()
+    return "rust = %s" % repr(cmd)
+
+addtask write_config before do_configure
+do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS RUSTC RUSTFLAGS"
+do_write_config() {
+    # This needs to be Py to split the args into single-element lists
+    cat >${WORKDIR}/meson.cross <<EOF
+[binaries]
+c = ${@meson_array('CC', d)}
+cpp = ${@meson_array('CXX', d)}
+cython = 'cython3'
+ar = ${@meson_array('AR', d)}
+nm = ${@meson_array('NM', d)}
+strip = ${@meson_array('STRIP', d)}
+readelf = ${@meson_array('READELF', d)}
+objcopy = ${@meson_array('OBJCOPY', d)}
+pkgconfig = 'pkg-config'
+llvm-config = 'llvm-config'
+cups-config = 'cups-config'
+g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper'
+g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper'
+${@rust_tool(d, "HOST_SYS")}
+${@"exe_wrapper = '${WORKDIR}/meson-qemuwrapper'" if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ""}
+
+[built-in options]
+c_args = ${@meson_array('CFLAGS', d)}
+c_link_args = ${@meson_array('LDFLAGS', d)}
+cpp_args = ${@meson_array('CXXFLAGS', d)}
+cpp_link_args = ${@meson_array('LDFLAGS', d)}
+
+[properties]
+needs_exe_wrapper = true
+
+[host_machine]
+system = '${@meson_operating_system('HOST_OS', d)}'
+cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}'
+cpu = '${HOST_ARCH}'
+endian = '${@meson_endian('HOST', d)}'
+
+[target_machine]
+system = '${@meson_operating_system('TARGET_OS', d)}'
+cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}'
+cpu = '${TARGET_ARCH}'
+endian = '${@meson_endian('TARGET', d)}'
+EOF
+
+    cat >${WORKDIR}/meson.native <<EOF
+[binaries]
+c = ${@meson_array('BUILD_CC', d)}
+cpp = ${@meson_array('BUILD_CXX', d)}
+cython = 'cython3'
+ar = ${@meson_array('BUILD_AR', d)}
+nm = ${@meson_array('BUILD_NM', d)}
+strip = ${@meson_array('BUILD_STRIP', d)}
+readelf = ${@meson_array('BUILD_READELF', d)}
+objcopy = ${@meson_array('BUILD_OBJCOPY', d)}
+pkgconfig = 'pkg-config-native'
+${@rust_tool(d, "BUILD_SYS")}
+
+[built-in options]
+c_args = ${@meson_array('BUILD_CFLAGS', d)}
+c_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
+cpp_args = ${@meson_array('BUILD_CXXFLAGS', d)}
+cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
+EOF
+}
+
+do_write_config:append:class-target() {
+    # Write out a qemu wrapper that will be used as exe_wrapper so that meson
+    # can run target helper binaries through that.
+    qemu_binary="${@qemu_wrapper_cmdline(d, '$STAGING_DIR_HOST', ['$STAGING_DIR_HOST/${libdir}','$STAGING_DIR_HOST/${base_libdir}'])}"
+    cat > ${WORKDIR}/meson-qemuwrapper << EOF
+#!/bin/sh
+# Use a modules directory which doesn't exist so we don't load random things
+# which may then get deleted (or their dependencies) and potentially segfault
+export GIO_MODULE_DIR=${STAGING_LIBDIR}/gio/modules-dummy
+
+# meson sets this wrongly (only to libs in build-dir), qemu_wrapper_cmdline() and GIR_EXTRA_LIBS_PATH take care of it properly
+unset LD_LIBRARY_PATH
+
+$qemu_binary "\$@"
+EOF
+    chmod +x ${WORKDIR}/meson-qemuwrapper
+}
diff --git a/meta/classes-recipe/meson.bbclass b/meta/classes-recipe/meson.bbclass
index 48688bed75..f1273aa1c0 100644
--- a/meta/classes-recipe/meson.bbclass
+++ b/meta/classes-recipe/meson.bbclass
@@ -4,141 +4,7 @@ 
 # SPDX-License-Identifier: MIT
 #
 
-inherit python3native meson-routines qemu
-
-DEPENDS:append = " meson-native ninja-native"
-
-EXEWRAPPER_ENABLED:class-native = "False"
-EXEWRAPPER_ENABLED:class-nativesdk = "False"
-EXEWRAPPER_ENABLED ?= "${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d)}"
-DEPENDS:append = "${@' qemu-native' if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ''}"
-
-# As Meson enforces out-of-tree builds we can just use cleandirs
-B = "${WORKDIR}/build"
-do_configure[cleandirs] = "${B}"
-
-# Where the meson.build build configuration is
-MESON_SOURCEPATH = "${S}"
-
-def noprefix(var, d):
-    return d.getVar(var).replace(d.getVar('prefix') + '/', '', 1)
-
-MESON_BUILDTYPE ?= "${@oe.utils.vartrue('DEBUG_BUILD', 'debug', 'plain', d)}"
-MESON_BUILDTYPE[vardeps] += "DEBUG_BUILD"
-MESONOPTS = " --prefix ${prefix} \
-              --buildtype ${MESON_BUILDTYPE} \
-              --bindir ${@noprefix('bindir', d)} \
-              --sbindir ${@noprefix('sbindir', d)} \
-              --datadir ${@noprefix('datadir', d)} \
-              --libdir ${@noprefix('libdir', d)} \
-              --libexecdir ${@noprefix('libexecdir', d)} \
-              --includedir ${@noprefix('includedir', d)} \
-              --mandir ${@noprefix('mandir', d)} \
-              --infodir ${@noprefix('infodir', d)} \
-              --sysconfdir ${sysconfdir} \
-              --localstatedir ${localstatedir} \
-              --sharedstatedir ${sharedstatedir} \
-              --wrap-mode nodownload \
-              --native-file ${WORKDIR}/meson.native"
-
-EXTRA_OEMESON:append = " ${PACKAGECONFIG_CONFARGS}"
-
-MESON_CROSS_FILE = ""
-MESON_CROSS_FILE:class-target = "--cross-file ${WORKDIR}/meson.cross"
-MESON_CROSS_FILE:class-nativesdk = "--cross-file ${WORKDIR}/meson.cross"
-
-# Needed to set up qemu wrapper below
-export STAGING_DIR_HOST
-
-def rust_tool(d, target_var):
-    rustc = d.getVar('RUSTC')
-    if not rustc:
-        return ""
-    cmd = [rustc, "--target", d.getVar(target_var)] + d.getVar("RUSTFLAGS").split()
-    return "rust = %s" % repr(cmd)
-
-addtask write_config before do_configure
-do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS RUSTC RUSTFLAGS"
-do_write_config() {
-    # This needs to be Py to split the args into single-element lists
-    cat >${WORKDIR}/meson.cross <<EOF
-[binaries]
-c = ${@meson_array('CC', d)}
-cpp = ${@meson_array('CXX', d)}
-cython = 'cython3'
-ar = ${@meson_array('AR', d)}
-nm = ${@meson_array('NM', d)}
-strip = ${@meson_array('STRIP', d)}
-readelf = ${@meson_array('READELF', d)}
-objcopy = ${@meson_array('OBJCOPY', d)}
-pkgconfig = 'pkg-config'
-llvm-config = 'llvm-config'
-cups-config = 'cups-config'
-g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper'
-g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper'
-${@rust_tool(d, "HOST_SYS")}
-${@"exe_wrapper = '${WORKDIR}/meson-qemuwrapper'" if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ""}
-
-[built-in options]
-c_args = ${@meson_array('CFLAGS', d)}
-c_link_args = ${@meson_array('LDFLAGS', d)}
-cpp_args = ${@meson_array('CXXFLAGS', d)}
-cpp_link_args = ${@meson_array('LDFLAGS', d)}
-
-[properties]
-needs_exe_wrapper = true
-
-[host_machine]
-system = '${@meson_operating_system('HOST_OS', d)}'
-cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}'
-cpu = '${HOST_ARCH}'
-endian = '${@meson_endian('HOST', d)}'
-
-[target_machine]
-system = '${@meson_operating_system('TARGET_OS', d)}'
-cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}'
-cpu = '${TARGET_ARCH}'
-endian = '${@meson_endian('TARGET', d)}'
-EOF
-
-    cat >${WORKDIR}/meson.native <<EOF
-[binaries]
-c = ${@meson_array('BUILD_CC', d)}
-cpp = ${@meson_array('BUILD_CXX', d)}
-cython = 'cython3'
-ar = ${@meson_array('BUILD_AR', d)}
-nm = ${@meson_array('BUILD_NM', d)}
-strip = ${@meson_array('BUILD_STRIP', d)}
-readelf = ${@meson_array('BUILD_READELF', d)}
-objcopy = ${@meson_array('BUILD_OBJCOPY', d)}
-pkgconfig = 'pkg-config-native'
-${@rust_tool(d, "BUILD_SYS")}
-
-[built-in options]
-c_args = ${@meson_array('BUILD_CFLAGS', d)}
-c_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
-cpp_args = ${@meson_array('BUILD_CXXFLAGS', d)}
-cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
-EOF
-}
-
-do_write_config:append:class-target() {
-    # Write out a qemu wrapper that will be used as exe_wrapper so that meson
-    # can run target helper binaries through that.
-    qemu_binary="${@qemu_wrapper_cmdline(d, '$STAGING_DIR_HOST', ['$STAGING_DIR_HOST/${libdir}','$STAGING_DIR_HOST/${base_libdir}'])}"
-    cat > ${WORKDIR}/meson-qemuwrapper << EOF
-#!/bin/sh
-# Use a modules directory which doesn't exist so we don't load random things
-# which may then get deleted (or their dependencies) and potentially segfault
-export GIO_MODULE_DIR=${STAGING_LIBDIR}/gio/modules-dummy
-
-# meson sets this wrongly (only to libs in build-dir), qemu_wrapper_cmdline() and GIR_EXTRA_LIBS_PATH take care of it properly
-unset LD_LIBRARY_PATH
-
-$qemu_binary "\$@"
-EOF
-    chmod +x ${WORKDIR}/meson-qemuwrapper
-}
+inherit meson-common
 
 # Tell externalsrc that changes to this file require a reconfigure
 CONFIGURE_FILES = "meson.build"