diff mbox series

[meta-python,2/2] python_mesonpy: New class

Message ID 20230607065547.128661-2-zboszor@gmail.com
State Under Review
Headers show
Series [meta-python,1/2] python3-meson-python: New recipe | expand

Commit Message

Böszörményi Zoltán June 7, 2023, 6:55 a.m. UTC
This is a new PEP517 compatible build class for python modules
that use pyproject.toml and this:

[build-system]
build-backend = 'mesonpy'

The new class uses python3-meson-python-native.

Signed-off-by: Zoltán Böszörményi <zboszor@gmail.com>
---
 meta-python/classes/python_mesonpy.bbclass | 54 ++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 meta-python/classes/python_mesonpy.bbclass

Comments

Ross Burton June 7, 2023, 9:57 a.m. UTC | #1
On 7 Jun 2023, at 07:55, Zoltan Boszormenyi via lists.openembedded.org <zboszor=gmail.com@lists.openembedded.org> wrote:
> +# Filter out meson_do_qa_configure from do_configure[postfuncs]
> +DOCONFIGUREPOSTFUNCS := "${@d.getVarFlag('do_configure', 'postfuncs')}"
> +DOCONFIGUREPOSTFUNCS:remove = "meson_do_qa_configure"
> +do_configure[postfuncs] := "${@'' if d.getVar('DOCONFIGUREPOSTFUNCS') is None else d.getVar('DOCONFIGUREPOSTFUNCS') }"

A neater solution would be to just stub out meson_do_qa_configure in this class:

meson_do_qa_configure() { : }

> +# This prevents the meson error:
> +# ERROR: Got argument buildtype as both -Dbuildtype and --buildtype. Pick one.
> +MESONOPTS:remove = "--buildtype ${MESON_BUILDTYPE}"

If mesonpy ever switches to —buildtype then this will break, right?  Might be better to patch mesonpy instead.

> +python_mesonpy_do_bootstrap_install () {
> +    python_pep517_do_bootstrap_install
> +}

This looks redundant and nothing calls it, remove.

Ross
Böszörményi Zoltán June 7, 2023, 11:24 a.m. UTC | #2
2023. 06. 07. 11:57 keltezéssel, Ross Burton írta:
> On 7 Jun 2023, at 07:55, Zoltan Boszormenyi via lists.openembedded.org <zboszor=gmail.com@lists.openembedded.org> wrote:
>> +# Filter out meson_do_qa_configure from do_configure[postfuncs]
>> +DOCONFIGUREPOSTFUNCS := "${@d.getVarFlag('do_configure', 'postfuncs')}"
>> +DOCONFIGUREPOSTFUNCS:remove = "meson_do_qa_configure"
>> +do_configure[postfuncs] := "${@'' if d.getVar('DOCONFIGUREPOSTFUNCS') is None else d.getVar('DOCONFIGUREPOSTFUNCS') }"
> A neater solution would be to just stub out meson_do_qa_configure in this class:
>
> meson_do_qa_configure() { : }

Thanks. I will make this change.

>> +# This prevents the meson error:
>> +# ERROR: Got argument buildtype as both -Dbuildtype and --buildtype. Pick one.
>> +MESONOPTS:remove = "--buildtype ${MESON_BUILDTYPE}"
> If mesonpy ever switches to —buildtype then this will break, right?  Might be better to patch mesonpy instead.

Why would it break? It does not affect what meson-python is adding internally.

This only removes the setting imposed by meson.bbclass
and only needs to change if meson.bbclass switches to -Dbuildtype.

>> +python_mesonpy_do_bootstrap_install () {
>> +    python_pep517_do_bootstrap_install
>> +}
> This looks redundant and nothing calls it, remove.

Ok.
Ross Burton June 7, 2023, 11:26 a.m. UTC | #3
On 7 Jun 2023, at 12:24, Böszörményi Zoltán <zboszor@gmail.com> wrote:
>>> +# This prevents the meson error:
>>> +# ERROR: Got argument buildtype as both -Dbuildtype and --buildtype. Pick one.
>>> +MESONOPTS:remove = "--buildtype ${MESON_BUILDTYPE}"
>> If mesonpy ever switches to —buildtype then this will break, right?  Might be better to patch mesonpy instead.
> 
> Why would it break? It does not affect what meson-python is adding internally.
> 
> This only removes the setting imposed by meson.bbclass
> and only needs to change if meson.bbclass switches to -Dbuildtype.

My understanding is that meson.bbclass is passing —buildtype and then mesonpy is passing -Dbuildtype.

This :remove removes any —buildtype option, so if mesonpy changes to using —buildtype instead of -Dbuildtype then _both_ buildtype options will be removed, which isn’t what you want.

Ross
Böszörményi Zoltán June 7, 2023, 11:41 a.m. UTC | #4
2023. 06. 07. 13:26 keltezéssel, Ross Burton írta:
> On 7 Jun 2023, at 12:24, Böszörményi Zoltán <zboszor@gmail.com> wrote:
>>>> +# This prevents the meson error:
>>>> +# ERROR: Got argument buildtype as both -Dbuildtype and --buildtype. Pick one.
>>>> +MESONOPTS:remove = "--buildtype ${MESON_BUILDTYPE}"
>>> If mesonpy ever switches to —buildtype then this will break, right?  Might be better to patch mesonpy instead.
>> Why would it break? It does not affect what meson-python is adding internally.
>>
>> This only removes the setting imposed by meson.bbclass
>> and only needs to change if meson.bbclass switches to -Dbuildtype.
> My understanding is that meson.bbclass is passing —buildtype and then mesonpy is passing -Dbuildtype.

Correct.

> This :remove removes any —buildtype option, so if mesonpy changes to using —buildtype instead of -Dbuildtype then _both_ buildtype options will be removed, which isn’t what you want.

Wrong.

This only removes the --buildtype setting from MESONOPTS set by meson.bbclass.
This variable is internal to meson.bbclass, not exported.
It it used this way there:

meson setup ${MESONOPTS} ...

mesonpy doesn't use the MESONOPTS variable to set the buildtype
and since this variable is not exported, meson can't see or use it either.
Ross Burton June 7, 2023, 3:35 p.m. UTC | #5
On 7 Jun 2023, at 12:41, Böszörményi Zoltán <zboszor@gmail.com> wrote:
> 
> 2023. 06. 07. 13:26 keltezéssel, Ross Burton írta:
>> On 7 Jun 2023, at 12:24, Böszörményi Zoltán <zboszor@gmail.com> wrote:
>>>>> +# This prevents the meson error:
>>>>> +# ERROR: Got argument buildtype as both -Dbuildtype and --buildtype. Pick one.
>>>>> +MESONOPTS:remove = "--buildtype ${MESON_BUILDTYPE}"
>>>> If mesonpy ever switches to —buildtype then this will break, right?  Might be better to patch mesonpy instead.
>>> Why would it break? It does not affect what meson-python is adding internally.
>>> 
>>> This only removes the setting imposed by meson.bbclass
>>> and only needs to change if meson.bbclass switches to -Dbuildtype.
>> My understanding is that meson.bbclass is passing —buildtype and then mesonpy is passing -Dbuildtype.
> 
> Correct.
> 
>> This :remove removes any —buildtype option, so if mesonpy changes to using —buildtype instead of -Dbuildtype then _both_ buildtype options will be removed, which isn’t what you want.
> 
> Wrong.
> 
> This only removes the --buildtype setting from MESONOPTS set by meson.bbclass.

Okay, I take it back, thanks.

Ross
Böszörményi Zoltán June 8, 2023, 11:30 a.m. UTC | #6
2023. 06. 07. 17:35 keltezéssel, Ross Burton írta:
> On 7 Jun 2023, at 12:41, Böszörményi Zoltán <zboszor@gmail.com> wrote:
>> 2023. 06. 07. 13:26 keltezéssel, Ross Burton írta:
>>> On 7 Jun 2023, at 12:24, Böszörményi Zoltán <zboszor@gmail.com> wrote:
>>>>>> +# This prevents the meson error:
>>>>>> +# ERROR: Got argument buildtype as both -Dbuildtype and --buildtype. Pick one.
>>>>>> +MESONOPTS:remove = "--buildtype ${MESON_BUILDTYPE}"
>>>>> If mesonpy ever switches to —buildtype then this will break, right?  Might be better to patch mesonpy instead.
>>>> Why would it break? It does not affect what meson-python is adding internally.
>>>>
>>>> This only removes the setting imposed by meson.bbclass
>>>> and only needs to change if meson.bbclass switches to -Dbuildtype.
>>> My understanding is that meson.bbclass is passing —buildtype and then mesonpy is passing -Dbuildtype.
>> Correct.
>>
>>> This :remove removes any —buildtype option, so if mesonpy changes to using —buildtype instead of -Dbuildtype then _both_ buildtype options will be removed, which isn’t what you want.
>> Wrong.
>>
>> This only removes the --buildtype setting from MESONOPTS set by meson.bbclass.
> Okay, I take it back, thanks.

Thanks. I will send the updated series shortly.

As a side note, do you know why -I/usr/include/python3.11 may get added
to the build command by meson? It happens on a Fedora 38 build host
but it doesn't happen on a Fedora 33 build host. As a result, building
my in-house python3-scikit-image recipe fails on Fedora 38.
Böszörményi Zoltán June 8, 2023, 11:43 a.m. UTC | #7
2023. 06. 08. 13:30 keltezéssel, Zoltan Boszormenyi via lists.openembedded.org írta:
> 2023. 06. 07. 17:35 keltezéssel, Ross Burton írta:
>> On 7 Jun 2023, at 12:41, Böszörményi Zoltán <zboszor@gmail.com> wrote:
>>> 2023. 06. 07. 13:26 keltezéssel, Ross Burton írta:
>>>> On 7 Jun 2023, at 12:24, Böszörményi Zoltán <zboszor@gmail.com> wrote:
>>>>>>> +# This prevents the meson error:
>>>>>>> +# ERROR: Got argument buildtype as both -Dbuildtype and --buildtype. Pick one.
>>>>>>> +MESONOPTS:remove = "--buildtype ${MESON_BUILDTYPE}"
>>>>>> If mesonpy ever switches to —buildtype then this will break, right?  Might be 
>>>>>> better to patch mesonpy instead.
>>>>> Why would it break? It does not affect what meson-python is adding internally.
>>>>>
>>>>> This only removes the setting imposed by meson.bbclass
>>>>> and only needs to change if meson.bbclass switches to -Dbuildtype.
>>>> My understanding is that meson.bbclass is passing —buildtype and then mesonpy is 
>>>> passing -Dbuildtype.
>>> Correct.
>>>
>>>> This :remove removes any —buildtype option, so if mesonpy changes to using —buildtype 
>>>> instead of -Dbuildtype then _both_ buildtype options will be removed, which isn’t 
>>>> what you want.
>>> Wrong.
>>>
>>> This only removes the --buildtype setting from MESONOPTS set by meson.bbclass.
>> Okay, I take it back, thanks.
>
> Thanks. I will send the updated series shortly.
>
> As a side note, do you know why -I/usr/include/python3.11 may get added
> to the build command by meson? It happens on a Fedora 38 build host
> but it doesn't happen on a Fedora 33 build host. As a result, building
> my in-house python3-scikit-image recipe fails on Fedora 38.

Nevermind, it's fixed by adding "inherit pkgconfig" to the recipe.

>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#103186): https://lists.openembedded.org/g/openembedded-devel/message/103186
> Mute This Topic: https://lists.openembedded.org/mt/99379800/3617728
> Group Owner: openembedded-devel+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [zboszor@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
diff mbox series

Patch

diff --git a/meta-python/classes/python_mesonpy.bbclass b/meta-python/classes/python_mesonpy.bbclass
new file mode 100644
index 000000000..1da8b005a
--- /dev/null
+++ b/meta-python/classes/python_mesonpy.bbclass
@@ -0,0 +1,54 @@ 
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+inherit meson setuptools3-base python3targetconfig python_pep517
+
+# Filter out meson_do_qa_configure from do_configure[postfuncs]
+DOCONFIGUREPOSTFUNCS := "${@d.getVarFlag('do_configure', 'postfuncs')}"
+DOCONFIGUREPOSTFUNCS:remove = "meson_do_qa_configure"
+do_configure[postfuncs] := "${@'' if d.getVar('DOCONFIGUREPOSTFUNCS') is None else d.getVar('DOCONFIGUREPOSTFUNCS') }"
+
+# This prevents the meson error:
+# ERROR: Got argument buildtype as both -Dbuildtype and --buildtype. Pick one.
+MESONOPTS:remove = "--buildtype ${MESON_BUILDTYPE}"
+
+CONFIGURE_FILES = "pyproject.toml"
+
+DEPENDS += "python3-wheel-native python3-meson-python-native"
+
+def mesonpy_get_args(d):
+    vars = ['MESONOPTS', 'MESON_CROSS_FILE', 'EXTRA_OEMESON']
+    varlist = []
+    for var in vars:
+        value = d.getVar(var)
+        vallist = value.split()
+        for elem in vallist:
+            varlist.append("-Csetup-args=" + elem)
+    return ' '.join(varlist)
+
+PEP517_BUILD_OPTS = "-Cbuilddir='${B}' ${@mesonpy_get_args(d)}"
+
+# Python pyx -> c -> so build leaves absolute build paths in the code
+INSANE_SKIP:${PN} += "buildpaths"
+INSANE_SKIP:${PN}-src += "buildpaths"
+
+python_mesonpy_do_configure () {
+    python_pep517_do_configure
+}
+
+python_mesonpy_do_compile () {
+    python_pep517_do_compile
+}
+
+python_mesonpy_do_install () {
+    python_pep517_do_install
+}
+
+python_mesonpy_do_bootstrap_install () {
+    python_pep517_do_bootstrap_install
+}
+
+EXPORT_FUNCTIONS do_configure do_compile do_install