[meta-python][PATCH v2 3/3] python3-ninja: New recipe


Zoltan Boszormenyi
 

Some python modules rely on "import ninja".

Only build and ship the python parts, and don't download and
build ninja from sources. Use the already built ninja instead.

The CMakeLists.txt file is a crippled copy from this ninja
python module's sources, removing almost everything, and
adding a dummy install target, so do_install() doesn't fail.

The python code is patched so ninja is used from PATH.

Signed-off-by: Zoltán Böszörményi <zboszor@...>
---
.../python/python3-ninja/CMakeLists.txt | 9 +++++
.../python3-ninja/run-ninja-from-path.patch | 11 ++++++
.../python/python3-ninja_1.11.1.bb | 34 +++++++++++++++++++
3 files changed, 54 insertions(+)
create mode 100644 meta-python/recipes-devtools/python/python3-ninja/CMakeLists.txt
create mode 100644 meta-python/recipes-devtools/python/python3-ninja/run-ninja-from-path.patch
create mode 100644 meta-python/recipes-devtools/python/python3-ninja_1.11.1.bb

diff --git a/meta-python/recipes-devtools/python/python3-ninja/CMakeLists.txt b/meta-python/recipes-devtools/python/python3-ninja/CMakeLists.txt
new file mode 100644
index 000000000..04fa451e7
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-ninja/CMakeLists.txt
@@ -0,0 +1,9 @@
+cmake_minimum_required(VERSION 3.15)
+
+project(NinjaPythonDistributions)
+
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_MODULE_PATH})
+
+install(CODE "
+ message(STATUS \"Install ninja project\")
+")
diff --git a/meta-python/recipes-devtools/python/python3-ninja/run-ninja-from-path.patch b/meta-python/recipes-devtools/python/python3-ninja/run-ninja-from-path.patch
new file mode 100644
index 000000000..26bd03737
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-ninja/run-ninja-from-path.patch
@@ -0,0 +1,11 @@
+--- ninja-1.11.1/src/ninja/__init__.py.old 2022-11-05 09:49:23.000000000 +0100
++++ ninja-1.11.1/src/ninja/__init__.py 2023-03-10 09:45:13.452082888 +0100
+@@ -44,7 +44,7 @@
+
+
+ def _program(name, args):
+- return subprocess.call([os.path.join(BIN_DIR, name)] + args, close_fds=False)
++ return subprocess.call([name] + args, close_fds=False)
+
+
+ def ninja():
diff --git a/meta-python/recipes-devtools/python/python3-ninja_1.11.1.bb b/meta-python/recipes-devtools/python/python3-ninja_1.11.1.bb
new file mode 100644
index 000000000..635fd076a
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-ninja_1.11.1.bb
@@ -0,0 +1,34 @@
+SUMMARY = "Ninja is a small build system with a focus on speed"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://LICENSE_Apache_20;md5=19cbd64715b51267a47bf3750cc6a8a5"
+
+DEPENDS = "ninja-native cmake-native python3-scikit-build-native"
+
+PYPI_PACKAGE = "ninja"
+PYPI_ARCHIVE_NAME_PREFIX = "pypi-"
+
+inherit pypi python_setuptools_build_meta
+SRC_URI[sha256sum] = "c833a47d39b2d1eee3f9ca886fa1581efd5be6068b82734ac229961ee8748f90"
+
+SRC_URI += " \
+ file://CMakeLists.txt \
+ file://run-ninja-from-path.patch \
+"
+
+addtask do_patchbuild after do_patch before do_configure
+
+do_patchbuild () {
+ rm -f ${S}/CMakeLists.txt
+ cp ${WORKDIR}/CMakeLists.txt ${S}/
+}
+
+do_install:append () {
+ rm -rf ${D}${bindir}
+}
+
+RDEPENDS:${PN} = " \
+ ninja \
+ python3-scikit-build \
+"
+
+BBCLASSEXTEND = "native nativesdk"
--
2.39.2


Ross Burton
 

The patch is missing an explanation, an Upstream-Status, and your Signed-off-by.

+SUMMARY = "Ninja is a small build system with a focus on speed"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://LICENSE_Apache_20;md5=19cbd64715b51267a47bf3750cc6a8a5"
+
+DEPENDS = "ninja-native cmake-native python3-scikit-build-native”
All of these depends are to build a binary that we immediately delete which is very sad.

+SRC_URI += " \
+ file://CMakeLists.txt \
+ file://run-ninja-from-path.patch \
+"
+
+addtask do_patchbuild after do_patch before do_configure
+
+do_patchbuild () {
+ rm -f ${S}/CMakeLists.txt
+ cp ${WORKDIR}/CMakeLists.txt ${S}/
+}
You can do this by setting subdir in SRC_URI: file://CMakeLists.txt;subdir=${S} will put the file directly into ${S} for you.

+RDEPENDS:${PN} = " \
+ ninja \
+ python3-scikit-build \
+”
This dependency on scikit-build means that anything that wants to use ninja on target pulls cmake into the image too.

This dependency isn’t needed at all because it only happens when the code is being ran in the build tree, which obviously a package won’t ever do.

Did you test this recipe? I believe that nothing you’ve tested actually uses the ‘import ninja’ functionality:

root@qemuarm64:~# python3 -mninja
Traceback (most recent call last):
File "/usr/lib/python3.11/site-packages/ninja/__init__.py", line 13, in <module>
from .ninja_syntax import Writer, escape, expand # noqa: F401
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'ninja.ninja_syntax'


If nothing actually uses the ninja module, then a simple recipe that simply RDEPENDS on ninja and claims the name would work better.

Ross