Skip to content

Commit c0364fc

Browse files
authored
bpo-20210: Support the *disabled* marker in Setup files (GH-132)
Extension modules listed after the *disabled* marker are not built at all, neither by the Makefile nor by setup.py.
1 parent 346cbd3 commit c0364fc

File tree

5 files changed

+79
-29
lines changed

5 files changed

+79
-29
lines changed

Makefile.pre.in

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020

2121
# === Variables set by makesetup ===
2222

23-
MODNAMES= _MODNAMES_
24-
MODOBJS= _MODOBJS_
25-
MODLIBS= _MODLIBS_
23+
MODBUILT_NAMES= _MODBUILT_NAMES_
24+
MODDISABLED_NAMES= _MODDISABLED_NAMES_
25+
MODOBJS= _MODOBJS_
26+
MODLIBS= _MODLIBS_
2627

2728
# === Variables set by configure
2829
VERSION= @VERSION@

Misc/NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,10 @@ Documentation
11221122
Build
11231123
-----
11241124

1125+
- bpo-20210: Support the *disabled* marker in Setup files. Extension modules
1126+
listed after this marker are not built at all, neither by the Makefile nor by
1127+
setup.py.
1128+
11251129
- bpo-29941: Add ``--with-assertions`` configure flag to explicitly enable
11261130
C ``assert()`` checks. Defaults to off. ``--with-pydebug`` implies
11271131
``--with-assertions``.

Modules/Setup.dist

+20-9
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@
1111
# directory.)
1212

1313
# Each line in this file describes one or more optional modules.
14-
# Modules enabled here will not be compiled by the setup.py script,
14+
# Modules configured here will not be compiled by the setup.py script,
1515
# so the file can be used to override setup.py's behavior.
16+
# Tag lines containing just the word "*static*", "*shared*" or "*disabled*"
17+
# (without the quotes but with the stars) are used to tag the following module
18+
# descriptions. Tag lines may alternate throughout this file. Modules are
19+
# built statically when they are preceded by a "*static*" tag line or when
20+
# there is no tag line between the start of the file and the module
21+
# description. Modules are built as a shared library when they are preceded by
22+
# a "*shared*" tag line. Modules are not built at all, not by the Makefile,
23+
# nor by the setup.py script, when they are preceded by a "*disabled*" tag
24+
# line.
1625

1726
# Lines have the following structure:
1827
#
@@ -34,9 +43,7 @@
3443
#
3544
# which defines a Make variable definition inserted into Makefile.in
3645
#
37-
# Finally, if a line contains just the word "*shared*" (without the
38-
# quotes but with the stars), then the following modules will not be
39-
# built statically. The build process works like this:
46+
# The build process works like this:
4047
#
4148
# 1. Build all modules that are declared as static in Modules/Setup,
4249
# combine them into libpythonxy.a, combine that into python.
@@ -57,10 +64,6 @@
5764
# toplevel "make install" target.) (For compatibility,
5865
# *noconfig* has the same effect as *shared*.)
5966
#
60-
# In addition, *static* explicitly declares the following modules to
61-
# be static. Lines containing "*static*" and "*shared*" may thus
62-
# alternate throughout this file.
63-
6467
# NOTE: As a standard policy, as many modules as can be supported by a
6568
# platform should be present. The distribution comes with all modules
6669
# enabled that are supported by most platforms and don't require you
@@ -152,7 +155,7 @@ _symtable symtablemodule.c
152155

153156
# Uncommenting the following line tells makesetup that all following
154157
# modules are to be built as shared libraries (see above for more
155-
# detail; also note that *static* reverses this effect):
158+
# detail; also note that *static* or *disabled* cancels this effect):
156159

157160
#*shared*
158161

@@ -394,3 +397,11 @@ _symtable symtablemodule.c
394397

395398
# Another example -- the 'xxsubtype' module shows C-level subtyping in action
396399
xxsubtype xxsubtype.c
400+
401+
# Uncommenting the following line tells makesetup that all following modules
402+
# are not built (see above for more detail).
403+
#
404+
#*disabled*
405+
#
406+
#_sqlite3 _tkinter _curses pyexpat
407+
#_codecs_jp _codecs_kr _codecs_tw unicodedata

Modules/makesetup

+17-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
#
3030
# Copying Makefile.pre to Makefile:
3131
# - insert an identifying comment at the start
32-
# - replace _MODNAMES_ by the list of modules from Setup
32+
# - replace _MODBUILT_NAMES_ by the list of *static* and *shared* modules
33+
# from Setup
34+
# - replace _MODDISABLED_NAMES_ by the list of *disabled* modules from Setup
3335
# - replace _MODOBJS_ by the list of objects from Setup (except for
3436
# Setup files after a -n option)
3537
# - replace _MODLIBS_ by the list of libraries from Setup
@@ -111,7 +113,8 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
111113
# Rules appended by makedepend
112114
" >$rulesf
113115
DEFS=
114-
NAMES=
116+
BUILT=
117+
DISABLED=
115118
MODS=
116119
SHAREDMODS=
117120
OBJS=
@@ -143,6 +146,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
143146
'*static*') doconfig=yes; continue;;
144147
'*noconfig*') doconfig=no; continue;;
145148
'*shared*') doconfig=no; continue;;
149+
'*disabled*') doconfig=disabled; continue;;
146150
esac
147151
srcs=
148152
cpps=
@@ -183,7 +187,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
183187
*.*) echo 1>&2 "bad word $arg in $line"
184188
exit 1;;
185189
-u) skip=libs; libs="$libs -u";;
186-
[a-zA-Z_]*) NAMES="$NAMES $arg"; mods="$mods $arg";;
190+
[a-zA-Z_]*) mods="$mods $arg";;
187191
*) echo 1>&2 "bad word $arg in $line"
188192
exit 1;;
189193
esac
@@ -192,6 +196,14 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
192196
yes)
193197
LIBS="$LIBS $libs"
194198
MODS="$MODS $mods"
199+
BUILT="$BUILT $mods"
200+
;;
201+
no)
202+
BUILT="$BUILT $mods"
203+
;;
204+
disabled)
205+
DISABLED="$DISABLED $mods"
206+
continue
195207
;;
196208
esac
197209
case $noobjects in
@@ -282,7 +294,8 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
282294
echo "1i\\" >$sedf
283295
str="# Generated automatically from $makepre by makesetup."
284296
echo "$str" >>$sedf
285-
echo "s%_MODNAMES_%$NAMES%" >>$sedf
297+
echo "s%_MODBUILT_NAMES_%$BUILT%" >>$sedf
298+
echo "s%_MODDISABLED_NAMES_%$DISABLED%" >>$sedf
286299
echo "s%_MODOBJS_%$OBJS%" >>$sedf
287300
echo "s%_MODLIBS_%$LIBS%" >>$sedf
288301
echo "/Definitions added by makesetup/a$NL$NL$DEFS" >>$sedf

setup.py

+34-13
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,14 @@ def build_extensions(self):
229229
headers = [sysconfig.get_config_h_filename()]
230230
headers += glob(os.path.join(sysconfig.get_path('include'), "*.h"))
231231

232-
# The sysconfig variable built by makesetup, listing the already
233-
# built modules as configured by the Setup files.
234-
modnames = sysconfig.get_config_var('MODNAMES').split()
235-
236-
removed_modules = []
232+
# The sysconfig variables built by makesetup that list the already
233+
# built modules and the disabled modules as configured by the Setup
234+
# files.
235+
sysconf_built = sysconfig.get_config_var('MODBUILT_NAMES').split()
236+
sysconf_dis = sysconfig.get_config_var('MODDISABLED_NAMES').split()
237+
238+
mods_built = []
239+
mods_disabled = []
237240
for ext in self.extensions:
238241
ext.sources = [ find_module_file(filename, moddirlist)
239242
for filename in ext.sources ]
@@ -245,14 +248,22 @@ def build_extensions(self):
245248
# re-compile extensions if a header file has been changed
246249
ext.depends.extend(headers)
247250

248-
# If a module has already been built by the Makefile,
249-
# don't build it here.
250-
if ext.name in modnames:
251-
removed_modules.append(ext)
251+
# If a module has already been built or has been disabled in the
252+
# Setup files, don't build it here.
253+
if ext.name in sysconf_built:
254+
mods_built.append(ext)
255+
if ext.name in sysconf_dis:
256+
mods_disabled.append(ext)
252257

253-
if removed_modules:
258+
mods_configured = mods_built + mods_disabled
259+
if mods_configured:
254260
self.extensions = [x for x in self.extensions if x not in
255-
removed_modules]
261+
mods_configured]
262+
# Remove the shared libraries built by a previous build.
263+
for ext in mods_configured:
264+
fullpath = self.get_ext_fullpath(ext.name)
265+
if os.path.exists(fullpath):
266+
os.unlink(fullpath)
256267

257268
# When you run "make CC=altcc" or something similar, you really want
258269
# those environment variables passed into the setup.py phase. Here's
@@ -295,12 +306,22 @@ def print_three_column(lst):
295306
" detect_modules() for the module's name.")
296307
print()
297308

298-
if removed_modules:
309+
if mods_built:
310+
print()
299311
print("The following modules found by detect_modules() in"
300312
" setup.py, have been")
301313
print("built by the Makefile instead, as configured by the"
302314
" Setup files:")
303-
print_three_column([ext.name for ext in removed_modules])
315+
print_three_column([ext.name for ext in mods_built])
316+
print()
317+
318+
if mods_disabled:
319+
print()
320+
print("The following modules found by detect_modules() in"
321+
" setup.py have not")
322+
print("been built, they are *disabled* in the Setup files:")
323+
print_three_column([ext.name for ext in mods_disabled])
324+
print()
304325

305326
if self.failed:
306327
failed = self.failed[:]

0 commit comments

Comments
 (0)