1From 18e19402fab3939223a58481734e685d25c3102b Mon Sep 17 00:00:00 2001
2From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
3Date: Wed, 22 Feb 2017 17:15:31 -0800
4Subject: [PATCH] Add an option to disable lib2to3
5
6lib2to3 is a library to convert Python 2.x code to Python 3.x. As
7such, it is probably not very useful on embedded system targets.
8
9Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
10Signed-off-by: Samuel Martin <s.martin49@gmail.com>
11[ Andrey Smirnov: ported to Python 3.6 ]
12Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
13[ Adam Duskett: ported to Python 3.10.0 ]
14Signed-off-by: Adam Duskett <aduskett@gmail.com>
15[ Bernd Kuhls: ported to Python 3.11.4]
16Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
17---
18 Makefile.pre.in | 17 ++++++++++++-----
19 configure.ac    |  6 ++++++
20 setup.py        |  6 +++---
21 3 files changed, 21 insertions(+), 8 deletions(-)
22
23diff --git a/Makefile.pre.in b/Makefile.pre.in
24index e87bc1fcd32..1a0ab0de426 100644
25--- a/Makefile.pre.in
26+++ b/Makefile.pre.in
27@@ -1881,7 +1881,9 @@ ifeq (@PYDOC@,yes)
28 	(cd $(DESTDIR)$(BINDIR); $(LN) -s pydoc$(VERSION) pydoc3)
29 endif
30 	-rm -f $(DESTDIR)$(BINDIR)/2to3
31+ifeq (@LIB2TO3@,yes)
32 	(cd $(DESTDIR)$(BINDIR); $(LN) -s 2to3-$(VERSION) 2to3)
33+endif
34 	if test "x$(LIPO_32BIT_FLAGS)" != "x" ; then \
35 		rm -f $(DESTDIR)$(BINDIR)/python3-32$(EXE); \
36 		(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)-32$(EXE) python3-32$(EXE)) \
37@@ -1927,7 +1929,6 @@ LIBSUBDIRS=	asyncio \
38 		idlelib idlelib/Icons \
39 		importlib importlib/resources importlib/metadata \
40 		json \
41-		lib2to3 lib2to3/fixes lib2to3/pgen2 \
42 		logging \
43 		multiprocessing multiprocessing/dummy \
44 		re \
45@@ -1947,10 +1948,6 @@ LIBSUBDIRS=	asyncio \
46 TESTSUBDIRS=	ctypes/test \
47 		distutils/tests \
48 		idlelib/idle_test \
49-		lib2to3/tests \
50-		lib2to3/tests/data \
51-		lib2to3/tests/data/fixers \
52-		lib2to3/tests/data/fixers/myfixes \
53 		test \
54 		test/audiodata \
55 		test/certdata \
56@@ -2074,6 +2071,14 @@ ifeq (@PYDOC@,yes)
57 LIBSUBDIRS += pydoc_data
58 endif
59
60+ifeq (@LIB2TO3@,yes)
61+LIBSUBDIRS += lib2to3 lib2to3/fixes lib2to3/pgen2
62+TESTSUBDIRS += lib2to3/tests			\
63+	lib2to3/tests/data			\
64+	lib2to3/tests/data/fixers		\
65+	lib2to3/tests/data/fixers/myfixes
66+endif
67+
68 TEST_MODULES=@TEST_MODULES@
69 libinstall:	all $(srcdir)/Modules/xxmodule.c
70 	@for i in $(SCRIPTDIR) $(LIBDEST); \
71@@ -2176,10 +2181,12 @@ ifeq (@PYC_BUILD@,yes)
72 		-j0 -d $(LIBDEST)/site-packages -f \
73 		-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
74 endif
75+ifeq (@LIB2TO3@,yes)
76 	-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
77 		$(PYTHON_FOR_BUILD) -m lib2to3.pgen2.driver $(DESTDIR)$(LIBDEST)/lib2to3/Grammar.txt
78 	-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
79 		$(PYTHON_FOR_BUILD) -m lib2to3.pgen2.driver $(DESTDIR)$(LIBDEST)/lib2to3/PatternGrammar.txt
80+endif
81
82 # bpo-21536: Misc/python-config.sh is generated in the build directory
83 # from $(srcdir)Misc/python-config.sh.in.
84diff --git a/configure.ac b/configure.ac
85index d56d8f9d1c5..bf91fb2f824 100644
86--- a/configure.ac
87+++ b/configure.ac
88@@ -7147,6 +7147,12 @@ PY_STDLIB_MOD([xxlimited_35], [test "$with_trace_refs" = "no"], [test "$ac_cv_fu
89 # substitute multiline block, must come after last PY_STDLIB_MOD()
90 AC_SUBST([MODULE_BLOCK])
91
92+AC_SUBST(LIB2TO3)
93+
94+AC_ARG_ENABLE(lib2to3,
95+	AS_HELP_STRING([--disable-lib2to3], [disable lib2to3]),
96+	[ LIB2TO3="${enableval}" ], [ LIB2TO3=yes ])
97+
98 # generate output files
99 AC_CONFIG_FILES(Makefile.pre Misc/python.pc Misc/python-embed.pc Misc/python-config.sh)
100 AC_CONFIG_FILES([Modules/Setup.bootstrap Modules/Setup.stdlib])
101diff --git a/setup.py b/setup.py
102index d8647724650..e02591dae10 100644
103--- a/setup.py
104+++ b/setup.py
105@@ -1598,11 +1598,11 @@ class DummyProcess:
106     import warnings
107     warnings.filterwarnings("ignore",category=DeprecationWarning)
108
109-    scripts = ['Tools/scripts/idle3', 'Tools/scripts/2to3',
110-               'Lib/smtpd.py']
111+    scripts = ['Tools/scripts/idle3', 'Lib/smtpd.py']
112     if not '--disable-pydoc' in sysconfig.get_config_var("CONFIG_ARGS"):
113         scripts += [ 'Tools/scripts/pydoc3' ]
114-
115+    if not '--disable-lib2to3' in sysconfig.get_config_var("CONFIG_ARGS"):
116+        scripts += [ 'Tools/scripts/2to3' ]
117     setup(# PyPI Metadata (PEP 301)
118           name = "Python",
119           version = sys.version.split()[0],
120--
1212.44.0
122
123