1From df7c95b4ceecf390b961d843a556c470ac9080b2 Mon Sep 17 00:00:00 2001 2From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> 3Date: Wed, 22 Feb 2017 16:33:22 -0800 4Subject: [PATCH] Add infrastructure to disable the build of certain extensions 5 6Some of the extensions part of the Python core have dependencies on 7external libraries (sqlite, tk, etc.) or are relatively big and not 8necessarly always useful (CJK codecs for example). By extensions, we 9mean part of Python modules that are written in C and therefore 10compiled to binary code. 11 12Therefore, we introduce a small infrastructure that allows to disable 13some of those extensions. This can be done inside the configure.ac by 14adding values to the DISABLED_EXTENSIONS variable (which is a 15word-separated list of extensions). 16 17The implementation works as follow : 18 19 * configure.ac defines a DISABLED_EXTENSIONS variable, which is 20 substituted (so that when Makefile.pre is generated from 21 Makefile.pre.in, the value of the variable is substituted). For 22 now, this DISABLED_EXTENSIONS variable is empty, later patches will 23 use it. 24 25 * Makefile.pre.in passes the DISABLED_EXTENSIONS value down to the 26 variables passed in the environment when calling the setup.py 27 script that actually builds and installs those extensions. 28 29 * setup.py is modified so that the existing "disabled_module_list" is 30 filled with those pre-disabled extensions listed in 31 DISABLED_EXTENSIONS. 32 33Patch ported to python2.7 by Maxime Ripard <ripard@archos.com>, and 34then extended by Thomas Petazzoni 35<thomas.petazzoni@free-electrons.com>. 36 37Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> 38[ Andrey Smirnov: ported to Python 3.6 ] 39Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> 40--- 41 Makefile.pre.in | 6 +++++- 42 configure.ac | 2 ++ 43 setup.py | 5 ++++- 44 3 files changed, 11 insertions(+), 2 deletions(-) 45 46diff --git a/Makefile.pre.in b/Makefile.pre.in 47index 0c809f3d8a..7c3dde8dd4 100644 48--- a/Makefile.pre.in 49+++ b/Makefile.pre.in 50@@ -218,6 +218,8 @@ FILEMODE= 644 51 # configure script arguments 52 CONFIG_ARGS= @CONFIG_ARGS@ 53 54+# disabled extensions 55+DISABLED_EXTENSIONS= @DISABLED_EXTENSIONS@ 56 57 # Subdirectories with code 58 SRCDIRS= @SRCDIRS@ 59@@ -628,6 +630,7 @@ sharedmods: $(BUILDPYTHON) pybuilddir.txt Modules/_math.o 60 esac; \ 61 echo "$(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ 62 _TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \ 63+ DISABLED_EXTENSIONS="$(DISABLED_EXTENSIONS)" \ 64 $(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build"; \ 65 $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ 66 _TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \ 67@@ -1748,7 +1751,8 @@ libainstall: @DEF_MAKE_RULE@ python-config 68 # Install the dynamically loadable modules 69 # This goes into $(exec_prefix) 70 sharedinstall: sharedmods 71- $(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/setup.py install \ 72+ $(RUNSHARED) DISABLED_EXTENSIONS="$(DISABLED_EXTENSIONS)" \ 73+ $(PYTHON_FOR_BUILD) $(srcdir)/setup.py install \ 74 --prefix=$(prefix) \ 75 --install-scripts=$(BINDIR) \ 76 --install-platlib=$(DESTSHARED) \ 77diff --git a/configure.ac b/configure.ac 78index c2445edc88..73d66167de 100644 79--- a/configure.ac 80+++ b/configure.ac 81@@ -3091,6 +3091,8 @@ LIBS="$withval $LIBS" 82 83 PKG_PROG_PKG_CONFIG 84 85+AC_SUBST(DISABLED_EXTENSIONS) 86+ 87 # Check for use of the system expat library 88 AC_MSG_CHECKING(for --with-system-expat) 89 AC_ARG_WITH(system_expat, 90diff --git a/setup.py b/setup.py 91index 770866bca7..b6c829b3a5 100644 92--- a/setup.py 93+++ b/setup.py 94@@ -58,7 +58,10 @@ with warnings.catch_warnings(): 95 TEST_EXTENSIONS = (sysconfig.get_config_var('TEST_MODULES') == 'yes') 96 97 # This global variable is used to hold the list of modules to be disabled. 98-DISABLED_MODULE_LIST = [] 99+try: 100+ DISABLED_MODULE_LIST = sysconfig.get_config_var("DISABLED_EXTENSIONS").split(" ") 101+except KeyError: 102+ DISABLED_MODULE_LIST = list() 103 104 # --list-module-names option used by Tools/scripts/generate_module_names.py 105 LIST_MODULE_NAMES = False 106-- 1072.25.1 108 109