Question: Need advise with providing native Bluetooth sockets for Python
Hi everyone,
I am upgrading a project from Scarthgap to Styhead and am facing a problem again which I somewhat solved before though not properly. And now I want to fix it for good and hopefully have the solution upstream too.
The problem: I have a Python application which needs bluetooth.h header from BlueZ (https://github.com/bluez/bluez/tree/master/lib) at compile time. This is needed by Python's configure script (https://github.com/python/cpython/blob/6293d00e7201f3f28b1f4512e57dc4f03855cabd/configure#L10937) at such that the Python installation includes support for sockets like AF_BLUETOOTH and BTPROTO_RFCOMM.
Without this, a line like the following will simply fail: sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
On Scarthgap I could do this by adding bbappend for Python with: DEPENDS += "${@bb.utils.contains('DISTRO_FEATURES', 'bluetooth', 'bluez5', '', d)}". This however is prone to creating dependency loops.
To fix this properly, I need to somehow provide only the contents of this folder: https://github.com/bluez/bluez/tree/master/lib ( https://github.com/bluez/bluez/tree/master/lib ) to Python at build-time while not depending on building BlueZ package and its dependencies. To my knowledge there is no way to use the current BlueZ recipe to do this, though I may be wrong. I am curious how others would solve this problem. Is a new recipe the best way?
Hmm I found this in BlueZ README, it suggests creating a separate package. If no one is against that idea I will try to create it and submit a patch.
--enable-library
Enable installation of Bluetooth library
By default the Bluetooth library is no longer installed. The user interfaces or command line utilities do not require an installed Bluetooth library anymore. This option is provided for legacy third party applications that still depend on the library.
When the library installation is enabled, it is a good idea to use a separate bluez-library or libbluetooth package for it.
Adding this to bluez5 bbappend:
PACKAGECONFIG:class-native = ""
BBCLASSEXTEND = "native"
And to python3 bbappend:
DEPENDS:append:class-target = " ${@bb.utils.contains('DISTRO_FEATURES', 'bluetooth', 'bluez5-native', '', d)}"
Seems to do the trick.
Quoted 7 lines · Guðni Már Gilbert via lists.openembedded.org
Adding this to bluez5 bbappend:
PACKAGECONFIG:class-native = ""
BBCLASSEXTEND = "native"
And to python3 bbappend:
DEPENDS:append:class-target = " ${@bb.utils.contains('DISTRO_FEATURES', 'bluetooth', 'bluez5-native', '', d)}"
Seems to do the trick.
Adding a PACKAGECONFIG for library that is on by default and then PACKAGECONFIG:class-native = “library” seems like a neat and self-documenting way of handling this.
Ross
I've submitted a patch which builds without any issues on my end. I am testing on latest master branch.