Skip to contentSkip to conversation

python3-evdev: Use Yocto kernel headers instead of host's

PATCH In review [email protected] 2 participants 3 messages Jun 28, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 python3-evdev: Use Yocto kernel headers instead of host's

From: Yoann Congal <[email protected]>

Commit 01ebfecf1c94 ("python3-evdev: switch to PEP-517 build backend") did not update the way build arguments are passed to the build making them unused. In python3-evdev case that meant that the build used host kernel headers instead of Yocto's.

When host's and Yocto's headers were different (currently the case on Debian 12 as seen on AB[0]), that triggered:

| src/evdev/ecodes.c:542:29: error: 'KEY_LINK_PHONE' undeclared (first use in this function); did you mean 'KEY_PICKUP_PHONE'?
|   542 |     PyModule_AddIntMacro(m, KEY_LINK_PHONE);
|       |                             ^~~~~~~~~~~~~~

[...]
ERROR: Task (.../../../layers/meta-openembedded/meta-python/recipes-devtools/python/python3-evdev_1.9.1.bb:do_compile) failed with exit code '1'

To fix this, use PEP517_BUILD_OPTS with the working (but weird looking) escaping.

Now that correct headers are used, their paths end up in the ecode.c file which lead to a buildpaths error, skip the check for this patch. This will be fixed in a following patch.

[0]: https://autobuilder.yoctoproject.org/valkyrie/#/builders/87/builds/40/steps/40/logs/stdio

---
 meta-python/recipes-devtools/python/python3-evdev_1.9.1.bb | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
meta-python/recipes-devtools/python/python3-evdev_1.9.1.bb +3 -1
index c48bc39c1f..b8930c97d5 100644
@@ -11,7 +11,8 @@ do_compile:prepend() {
     rm -rf ${S}/evdev/ecodes.c
 }
 
-SETUPTOOLS_BUILD_ARGS = "build_ecodes --evdev-headers ${STAGING_DIR_TARGET}/usr/include/linux/input.h:${STAGING_DIR_TARGET}/usr/include/linux/input-event-codes.h"
+PEP517_BUILD_OPTS = "--config-setting=--build-option='build_ecodes \
+    --evdev-headers ${STAGING_DIR_TARGET}/usr/include/linux/input.h:${STAGING_DIR_TARGET}/usr/include/linux/input-event-codes.h'"
 
 RDEPENDS:${PN} += "\
     python3-ctypes \
@@ -20,3 +21,4 @@ RDEPENDS:${PN} += "\
     python3-shell \
     python3-stringold \
     "
+INSANE_SKIP:${PN}-src = "buildpaths"
#1 lore raw

PATCH 2/2 python3-evdev: Fix buildpaths errors and reproducibility

From: Yoann Congal <[email protected]>

Add a submitted patch to support the reproducible generation of intermediate file ecodes.c, then, use it to fix the buildpaths errors.

---
 ...ibility-option-for-building-ecodes.c.patch | 116 ++++++++++++++++++
 .../python/python3-evdev_1.9.1.bb             |   5 +-
 2 files changed, 119 insertions(+), 2 deletions(-)
 create mode 100644 meta-python/recipes-devtools/python/python3-evdev/0001-Add-a-reproducibility-option-for-building-ecodes.c.patch
meta-python/recipes-devtools/python/python3-evdev/0001-Add-a-reproducibility-option-for-building-ecodes.c.patch new file +116 -0
new file mode 100644
index 0000000000..e730519884
@@ -0,0 +1,116 @@
+From d05c1c9dd298cb95d7feccbddb5caa043a319a01 Mon Sep 17 00:00:00 2001
+From: Yoann Congal <[email protected]>
+Date: Sun, 13 Apr 2025 00:52:13 +0200
+Subject: [PATCH] Add a reproducibility option for building ecodes.c
+
+ecodes.c currently contains the kernel info of the build machine and the
+full path of the input*.h headers: This is not reproducible as output
+can change even is headers content do not. Downstream distributions
+might package ecodes.c and get non-reproducible output.
+
+To fix this: introduce a --reproducible option in the build:
+- in setup.py build_ecodes command
+- in underlying genecodes_c.py
+
+Note: These options are disabled by default so no change is expected in
+current builds.
+
+Signed-off-by: Yoann Congal <[email protected]>
+Upstream-Status: Submitted [https://github.com/gvalkov/python-evdev/pull/242]
+---
+ setup.py                 | 13 ++++++++++---
+ src/evdev/genecodes_c.py | 17 +++++++++++------
+ 2 files changed, 21 insertions(+), 9 deletions(-)
+
+diff --git a/setup.py b/setup.py
+index 6b721d7..3371199 100755
+--- a/setup.py
++++ b/setup.py
+@@ -14,7 +14,7 @@ curdir = Path(__file__).resolve().parent
+ ecodes_c_path = curdir / "src/evdev/ecodes.c"
+ 
+ 
+-def create_ecodes(headers=None):
++def create_ecodes(headers=None, reproducibility=False):
+     if not headers:
+         include_paths = set()
+         cpath = os.environ.get("CPATH", "").strip()
+@@ -65,7 +65,10 @@ def create_ecodes(headers=None):
+ 
+     print("writing %s (using %s)" % (ecodes_c_path, " ".join(headers)))
+     with ecodes_c_path.open("w") as fh:
+-        cmd = [sys.executable, "src/evdev/genecodes_c.py", "--ecodes", *headers]
++        cmd = [sys.executable, "src/evdev/genecodes_c.py"]
++        if reproducibility:
++            cmd.append("--reproducibility")
++        cmd.extend(["--ecodes", *headers])
+         run(cmd, check=True, stdout=fh)
+ 
+ 
+@@ -74,17 +77,21 @@ class build_ecodes(Command):
+ 
+     user_options = [
+         ("evdev-headers=", None, "colon-separated paths to input subsystem headers"),
++        ("reproducibility", None, "hide host details (host/paths) to create a reproducible output"),
+     ]
+ 
+     def initialize_options(self):
+         self.evdev_headers = None
++        self.reproducibility = False
+ 
+     def finalize_options(self):
+         if self.evdev_headers:
+             self.evdev_headers = self.evdev_headers.split(":")
++        if self.reproducibility is None:
++            self.reproducibility = False
+ 
+     def run(self):
+-        create_ecodes(self.evdev_headers)
++        create_ecodes(self.evdev_headers, reproducibility=self.reproducibility)
+ 
+ 
+ class build_ext(_build_ext.build_ext):
+diff --git a/src/evdev/genecodes_c.py b/src/evdev/genecodes_c.py
+index 5c2d946..24cad27 100644
+--- a/src/evdev/genecodes_c.py
++++ b/src/evdev/genecodes_c.py
+@@ -15,22 +15,27 @@ headers = [
+     "/usr/include/linux/uinput.h",
+ ]
+ 
+-opts, args = getopt.getopt(sys.argv[1:], "", ["ecodes", "stubs"])
++opts, args = getopt.getopt(sys.argv[1:], "", ["ecodes", "stubs", "reproducibility"])
+ if not opts:
+-    print("usage: genecodes.py [--ecodes|--stubs] <headers>")
++    print("usage: genecodes.py [--ecodes|--stubs] [--reproducibility] <headers>")
+     exit(2)
+ 
+ if args:
+     headers = args
+ 
++reproducibility = ("--reproducibility", "") in opts
++
+ 
+ # -----------------------------------------------------------------------------
+ macro_regex = r"#define\s+((?:KEY|ABS|REL|SW|MSC|LED|BTN|REP|SND|ID|EV|BUS|SYN|FF|UI_FF|INPUT_PROP)_\w+)"
+ macro_regex = re.compile(macro_regex)
+ 
+-# Uname without hostname.
+-uname = list(os.uname())
+-uname = " ".join((uname[0], *uname[2:]))
++if reproducibility:
++    uname = "hidden for reproducibility"
++else:
++    # Uname without hostname.
++    uname = list(os.uname())
++    uname = " ".join((uname[0], *uname[2:]))
+ 
+ 
+ # -----------------------------------------------------------------------------
+@@ -138,5 +143,5 @@ elif ("--stubs", "") in opts:
+     template = template_stubs
+ 
+ body = os.linesep.join(body)
+-text = template % (uname, headers, body)
++text = template % (uname, headers if not reproducibility else ["hidden for reproducibility"], body)
+ print(text.strip())
meta-python/recipes-devtools/python/python3-evdev_1.9.1.bb +3 -2
index b8930c97d5..af88770c59 100644
@@ -3,6 +3,7 @@ HOMEPAGE = "https://github.com/gvalkov/python-evdev"
 LICENSE = "BSD-3-Clause"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=d7bd1cc4c71b706c7e2d4053aef50f2a"
 
+SRC_URI += "file://0001-Add-a-reproducibility-option-for-building-ecodes.c.patch"
 SRC_URI[sha256sum] = "dc640a064cb1c9fe1f8b970dc2039945a2a275d7b7ee62284bf427238abe45ee"
 
 inherit pypi python_setuptools_build_meta
@@ -12,7 +13,8 @@ do_compile:prepend() {
 }
 
 PEP517_BUILD_OPTS = "--config-setting=--build-option='build_ecodes \
-    --evdev-headers ${STAGING_DIR_TARGET}/usr/include/linux/input.h:${STAGING_DIR_TARGET}/usr/include/linux/input-event-codes.h'"
+    --evdev-headers ${STAGING_DIR_TARGET}/usr/include/linux/input.h:${STAGING_DIR_TARGET}/usr/include/linux/input-event-codes.h \
+    --reproducibility'"
 
 RDEPENDS:${PN} += "\
     python3-ctypes \
@@ -21,4 +23,3 @@ RDEPENDS:${PN} += "\
     python3-shell \
     python3-stringold \
     "
-INSANE_SKIP:${PN}-src = "buildpaths"
#2 lore raw

Re: [meta-oe][walnascar][PATCH 2/2] python3-evdev: Fix buildpaths errors and reproducibility

Hi,

Quoted 42 lines · Le sam. 28 juin 2025 à 18:37, <[email protected]> a écrit :

From: Yoann Congal <[email protected]>

Add a submitted patch to support the reproducible generation of intermediate file ecodes.c, then, use it to fix the buildpaths errors.

---
 ...ibility-option-for-building-ecodes.c.patch | 116 ++++++++++++++++++
 .../python/python3-evdev_1.9.1.bb             |   5 +-
 2 files changed, 119 insertions(+), 2 deletions(-)
 create mode 100644

meta-python/recipes-devtools/python/python3-evdev/0001-Add-a-reproducibility-option-for-building-ecodes.c.patch

diff --git a/meta-python/recipes-devtools/python/python3-evdev/0001-Add-a-reproducibility-option-for-building-ecodes.c.patch b/meta-python/recipes-devtools/python/python3-evdev/0001-Add-a-reproducibility-option-for-building-ecodes.c.patch new file mode 100644
index 0000000000..e730519884
--- /dev/null
+++
b/meta-python/recipes-devtools/python/python3-evdev/0001-Add-a-reproducibility-option-for-building-ecodes.c.patch

meta-python/recipes-devtools/python/python3-evdev/0001-Add-a-reproducibility-option-for-building-ecodes.c.patch new file +19 -0
@@ -0,0 +1,116 @@
+From d05c1c9dd298cb95d7feccbddb5caa043a319a01 Mon Sep 17 00:00:00 2001
+From: Yoann Congal <[email protected]>
+Date: Sun, 13 Apr 2025 00:52:13 +0200
+Subject: [PATCH] Add a reproducibility option for building ecodes.c
+
+ecodes.c currently contains the kernel info of the build machine and the
+full path of the input*.h headers: This is not reproducible as output
+can change even is headers content do not. Downstream distributions
+might package ecodes.c and get non-reproducible output.
+
+To fix this: introduce a --reproducible option in the build:
+- in setup.py build_ecodes command
+- in underlying genecodes_c.py
+
+Note: These options are disabled by default so no change is expected in
+current builds.
+
+Signed-off-by: Yoann Congal <[email protected]>
+Upstream-Status: Submitted [
Quoted 2 lines

https://github.com/gvalkov/python-evdev/pull/242]

For what it's worth, this is now a backport :
https://github.com/gvalkov/python-evdev/commit/6b4e8ef0ee505d9c3d46b1787eac339d8bd0b934
Never sent the update on master since it was release as part of v1.9.2.

Regards,

+---
> + setup.py                 | 13 ++++++++++---
> + src/evdev/genecodes_c.py | 17 +++++++++++------
Quoted 138 lines

+ 2 files changed, 21 insertions(+), 9 deletions(-)

meta-python/recipes-devtools/python/python3-evdev/0001-Add-a-reproducibility-option-for-building-ecodes.c.patch new file +19 -0
+
+diff --git a/setup.py b/setup.py
+index 6b721d7..3371199 100755
+--- a/setup.py
++++ b/setup.py
+@@ -14,7 +14,7 @@ curdir = Path(__file__).resolve().parent
+ ecodes_c_path = curdir / "src/evdev/ecodes.c"
+
+
+-def create_ecodes(headers=None):
++def create_ecodes(headers=None, reproducibility=False):
+     if not headers:
+         include_paths = set()
+         cpath = os.environ.get("CPATH", "").strip()
+@@ -65,7 +65,10 @@ def create_ecodes(headers=None):
+
+     print("writing %s (using %s)" % (ecodes_c_path, " ".join(headers)))
+     with ecodes_c_path.open("w") as fh:
+-        cmd = [sys.executable, "src/evdev/genecodes_c.py", "--ecodes",

*headers]
++ cmd = [sys.executable, "src/evdev/genecodes_c.py"]
++ if reproducibility:
++ cmd.append("--reproducibility")
++ cmd.extend(["--ecodes", *headers])

meta-python/recipes-devtools/python/python3-evdev/0001-Add-a-reproducibility-option-for-building-ecodes.c.patch new file +7 -0
+         run(cmd, check=True, stdout=fh)
+
+
+@@ -74,17 +77,21 @@ class build_ecodes(Command):
+
+     user_options = [
+         ("evdev-headers=", None, "colon-separated paths to input

subsystem headers"),
++ ("reproducibility", None, "hide host details (host/paths) to
create a reproducible output"),

meta-python/recipes-devtools/python/python3-evdev/0001-Add-a-reproducibility-option-for-building-ecodes.c.patch new file +15 -0
+     ]
+
+     def initialize_options(self):
+         self.evdev_headers = None
++        self.reproducibility = False
+
+     def finalize_options(self):
+         if self.evdev_headers:
+             self.evdev_headers = self.evdev_headers.split(":")
++        if self.reproducibility is None:
++            self.reproducibility = False
+
+     def run(self):
+-        create_ecodes(self.evdev_headers)
++        create_ecodes(self.evdev_headers,

reproducibility=self.reproducibility)

meta-python/recipes-devtools/python/python3-evdev/0001-Add-a-reproducibility-option-for-building-ecodes.c.patch new file +13 -0
+
+
+ class build_ext(_build_ext.build_ext):
+diff --git a/src/evdev/genecodes_c.py b/src/evdev/genecodes_c.py
+index 5c2d946..24cad27 100644
+--- a/src/evdev/genecodes_c.py
++++ b/src/evdev/genecodes_c.py
+@@ -15,22 +15,27 @@ headers = [
+     "/usr/include/linux/uinput.h",
+ ]
+
+-opts, args = getopt.getopt(sys.argv[1:], "", ["ecodes", "stubs"])
++opts, args = getopt.getopt(sys.argv[1:], "", ["ecodes", "stubs",

"reproducibility"])
+ if not opts:

+-    print("usage: genecodes.py [--ecodes|--stubs] <headers>")
++    print("usage: genecodes.py [--ecodes|--stubs] [--reproducibility]

<headers>")

meta-python/recipes-devtools/python/python3-evdev/0001-Add-a-reproducibility-option-for-building-ecodes.c.patch new file +10 -1
+     exit(2)
+
+ if args:
+     headers = args
+
++reproducibility = ("--reproducibility", "") in opts
++
+
+ #
-----------------------------------------------------------------------------
+ macro_regex =

r"#define\s+((?:KEY|ABS|REL|SW|MSC|LED|BTN|REP|SND|ID|EV|BUS|SYN|FF|UI_FF|INPUT_PROP)_\w+)"
+ macro_regex = re.compile(macro_regex)

meta-python/recipes-devtools/python/python3-evdev/0001-Add-a-reproducibility-option-for-building-ecodes.c.patch new file +19 -1
+
+-# Uname without hostname.
+-uname = list(os.uname())
+-uname = " ".join((uname[0], *uname[2:]))
++if reproducibility:
++    uname = "hidden for reproducibility"
++else:
++    # Uname without hostname.
++    uname = list(os.uname())
++    uname = " ".join((uname[0], *uname[2:]))
+
+
+ #
-----------------------------------------------------------------------------
+@@ -138,5 +143,5 @@ elif ("--stubs", "") in opts:
+     template = template_stubs
+
+ body = os.linesep.join(body)
+-text = template % (uname, headers, body)
++text = template % (uname, headers if not reproducibility else ["hidden

for reproducibility"], body)
+ print(text.strip())

meta-python/recipes-devtools/python/python3-evdev_1.9.1.bb +1 -0
index b8930c97d5..af88770c59 100644
@@ -3,6 +3,7 @@ HOMEPAGE = "https://github.com/gvalkov/python-evdev"
 LICENSE = "BSD-3-Clause"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=d7bd1cc4c71b706c7e2d4053aef50f2a"
 
+SRC_URI +=

"file://0001-Add-a-reproducibility-option-for-building-ecodes.c.patch"
SRC_URI[sha256sum] =
"dc640a064cb1c9fe1f8b970dc2039945a2a275d7b7ee62284bf427238abe45ee"

inherit pypi python_setuptools_build_meta

meta-python/recipes-devtools/python/python3-evdev_1.9.1.bb +0 -1
@@ -12,7 +13,8 @@ do_compile:prepend() {
 }
 
 PEP517_BUILD_OPTS = "--config-setting=--build-option='build_ecodes \
-    --evdev-headers

${STAGING_DIR_TARGET}/usr/include/linux/input.h:${STAGING_DIR_TARGET}/usr/include/linux/input-event-codes.h'"
+ --evdev-headers
${STAGING_DIR_TARGET}/usr/include/linux/input.h:${STAGING_DIR_TARGET}/usr/include/linux/input-event-codes.h \

meta-python/recipes-devtools/python/python3-evdev_1.9.1.bb +1 -1
+    --reproducibility'"
 
 RDEPENDS:${PN} += "\
     python3-ctypes \
@@ -21,4 +23,3 @@ RDEPENDS:${PN} += "\
     python3-shell \
     python3-stringold \
     "
-INSANE_SKIP:${PN}-src = "buildpaths"
Signature · 2 lines
Yoann Congal
Smile ECS