From b8dff0645a6754d6afaf087215d208d3c8c6c307 Mon Sep 17 00:00:00 2001
From: Khalid Masum <khalid.masum.92@gmail.com>
Date: Mon, 24 Feb 2025 17:28:20 +0000
Subject: [PATCH] extras: tools: add python 3.13 support to Ninja

Backport a patch from Ninja 1.12 that adds python 3.13
support. This is necessary because current version of Ninja
does not work with python 3.13 as pipes module is deprecated.
---
 ...replace-pipes-quote-with-shlex-quote.patch | 36 +++++++++++++++++++
 extras/tools/tools.mak                        |  1 +
 2 files changed, 37 insertions(+)
 create mode 100644 extras/tools/ninja-1.11.1-replace-pipes-quote-with-shlex-quote.patch

diff --git a/extras/tools/ninja-1.11.1-replace-pipes-quote-with-shlex-quote.patch b/extras/tools/ninja-1.11.1-replace-pipes-quote-with-shlex-quote.patch
new file mode 100644
index 000000000000..a6366117b4da
--- /dev/null
+++ b/extras/tools/ninja-1.11.1-replace-pipes-quote-with-shlex-quote.patch
@@ -0,0 +1,36 @@
+From 9cf13cd1ecb7ae649394f4133d121a01e191560b Mon Sep 17 00:00:00 2001
+From: Byoungchan Lee <byoungchan.lee@gmx.com>
+Date: Mon, 9 Oct 2023 20:13:20 +0900
+Subject: [PATCH] Replace pipes.quote with shlex.quote in configure.py
+
+Python 3.12 deprecated the pipes module and it will be removed
+in Python 3.13. In configure.py, I have replaced the usage of pipes.quote
+with shlex.quote, which is the exactly same function as pipes.quote.
+
+For more details, refer to PEP 0594: https://peps.python.org/pep-0594
+---
+ configure.py | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/configure.py b/configure.py
+index 588250aa8a..c6973cd1a5 100755
+--- a/configure.py
++++ b/configure.py
+@@ -21,7 +21,7 @@
+ 
+ from optparse import OptionParser
+ import os
+-import pipes
++import shlex
+ import string
+ import subprocess
+ import sys
+@@ -262,7 +262,7 @@ def _run_command(self, cmdline):
+ env_keys = set(['CXX', 'AR', 'CFLAGS', 'CXXFLAGS', 'LDFLAGS'])
+ configure_env = dict((k, os.environ[k]) for k in os.environ if k in env_keys)
+ if configure_env:
+-    config_str = ' '.join([k + '=' + pipes.quote(configure_env[k])
++    config_str = ' '.join([k + '=' + shlex.quote(configure_env[k])
+                            for k in configure_env])
+     n.variable('configure_env', config_str + '$ ')
+ n.newline()
diff --git a/extras/tools/tools.mak b/extras/tools/tools.mak
index 163996ba2936..5ce5351d20a2 100644
--- a/extras/tools/tools.mak
+++ b/extras/tools/tools.mak
@@ -394,6 +394,7 @@ ninja-$(NINJA_VERSION).tar.gz:
 ninja: UNPACK_DIR=ninja-$(NINJA_BUILD_NAME)
 ninja: ninja-$(NINJA_VERSION).tar.gz
 	$(UNPACK)
+	$(APPLY) $(TOOLS)/ninja-1.11.1-replace-pipes-quote-with-shlex-quote.patch
 	$(MOVE)
 
 .buildninja: ninja
-- 
GitLab