python-semanage: fix cross-compilation, add test.sh
authorAlexandru Ardelean <redacted>
Fri, 3 Apr 2026 10:53:03 +0000 (13:53 +0300)
committerAlexandru Ardelean <redacted>
Sat, 25 Apr 2026 04:48:58 +0000 (07:48 +0300)
Add HOST_PYTHON3_PIP_VARS and --no-build-isolation to MAKE_VARS.
Without --no-build-isolation, pip creates an isolated build environment
which fails during cross-compilation because _sysconfigdata is missing.
Aligns with python-selinux which already has this fix.

The libsemanage pywrap uses the host Python's EXT_SUFFIX to name the
C extension, so we will use the PYCEXT env-var to correct that.

Add basic test.sh to verify the semanage Python bindings load correctly
in environments without SELinux kernel support.

Signed-off-by: Alexandru Ardelean <redacted>
lang/python/python-semanage/Makefile
lang/python/python-semanage/test.sh [new file with mode: 0755]

index c1b253300b96091865d5306503259ffedf40fb72..5f443e958cee57b9df5061a218ded8d433518271 100644 (file)
@@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=python-semanage
 PKG_VERSION:=3.9
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 SRC_NAME:=libsemanage
 PKG_SOURCE:=$(SRC_NAME)-$(PKG_VERSION).tar.gz
@@ -51,7 +51,10 @@ define Package/python3-semanage/description
 endef
 
 MAKE_VARS += \
-       $(PYTHON3_VARS)
+       $(PYTHON3_VARS) \
+       $(HOST_PYTHON3_PIP_VARS) \
+       PYCEXT=.cpython-$(PYTHON3_VERSION_MAJOR)$(PYTHON3_VERSION_MINOR)$(ABIFLAGS)-$(MULTIARCH).so \
+       PYTHON_SETUP_ARGS="--no-compile --no-build-isolation"
 
 define Build/Compile
        $(call Build/Compile/Default,pywrap)
diff --git a/lang/python/python-semanage/test.sh b/lang/python/python-semanage/test.sh
new file mode 100755 (executable)
index 0000000..a586ad0
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+[ "$1" = python3-semanage ] || exit 0
+
+python3 - <<'EOF'
+import semanage
+
+# Verify the C extension loaded and key functions/constants are available
+assert hasattr(semanage, 'semanage_handle_create'), "semanage_handle_create missing"
+assert hasattr(semanage, 'SEMANAGE_CON_DIRECT'), "SEMANAGE_CON_DIRECT missing"
+assert hasattr(semanage, 'SEMANAGE_CON_INVALID'), "SEMANAGE_CON_INVALID missing"
+assert hasattr(semanage, 'SEMANAGE_FCONTEXT_ALL'), "SEMANAGE_FCONTEXT_ALL missing"
+assert hasattr(semanage, 'SEMANAGE_FCONTEXT_REG'), "SEMANAGE_FCONTEXT_REG missing"
+
+print("python3-semanage OK")
+EOF
git clone https://git.99rst.org/PROJECT