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.
This commit is contained in:
xdegaye 2017-05-27 18:25:03 +02:00 committed by GitHub
parent 346cbd351e
commit c0364fc7c2
5 changed files with 78 additions and 28 deletions

View File

@ -20,7 +20,8 @@
# === Variables set by makesetup === # === Variables set by makesetup ===
MODNAMES= _MODNAMES_ MODBUILT_NAMES= _MODBUILT_NAMES_
MODDISABLED_NAMES= _MODDISABLED_NAMES_
MODOBJS= _MODOBJS_ MODOBJS= _MODOBJS_
MODLIBS= _MODLIBS_ MODLIBS= _MODLIBS_

View File

@ -1122,6 +1122,10 @@ Documentation
Build Build
----- -----
- bpo-20210: Support the *disabled* marker in Setup files. Extension modules
listed after this marker are not built at all, neither by the Makefile nor by
setup.py.
- bpo-29941: Add ``--with-assertions`` configure flag to explicitly enable - bpo-29941: Add ``--with-assertions`` configure flag to explicitly enable
C ``assert()`` checks. Defaults to off. ``--with-pydebug`` implies C ``assert()`` checks. Defaults to off. ``--with-pydebug`` implies
``--with-assertions``. ``--with-assertions``.

View File

@ -11,8 +11,17 @@
# directory.) # directory.)
# Each line in this file describes one or more optional modules. # Each line in this file describes one or more optional modules.
# Modules enabled here will not be compiled by the setup.py script, # Modules configured here will not be compiled by the setup.py script,
# so the file can be used to override setup.py's behavior. # so the file can be used to override setup.py's behavior.
# Tag lines containing just the word "*static*", "*shared*" or "*disabled*"
# (without the quotes but with the stars) are used to tag the following module
# descriptions. Tag lines may alternate throughout this file. Modules are
# built statically when they are preceded by a "*static*" tag line or when
# there is no tag line between the start of the file and the module
# description. Modules are built as a shared library when they are preceded by
# a "*shared*" tag line. Modules are not built at all, not by the Makefile,
# nor by the setup.py script, when they are preceded by a "*disabled*" tag
# line.
# Lines have the following structure: # Lines have the following structure:
# #
@ -34,9 +43,7 @@
# #
# which defines a Make variable definition inserted into Makefile.in # which defines a Make variable definition inserted into Makefile.in
# #
# Finally, if a line contains just the word "*shared*" (without the # The build process works like this:
# quotes but with the stars), then the following modules will not be
# built statically. The build process works like this:
# #
# 1. Build all modules that are declared as static in Modules/Setup, # 1. Build all modules that are declared as static in Modules/Setup,
# combine them into libpythonxy.a, combine that into python. # combine them into libpythonxy.a, combine that into python.
@ -57,10 +64,6 @@
# toplevel "make install" target.) (For compatibility, # toplevel "make install" target.) (For compatibility,
# *noconfig* has the same effect as *shared*.) # *noconfig* has the same effect as *shared*.)
# #
# In addition, *static* explicitly declares the following modules to
# be static. Lines containing "*static*" and "*shared*" may thus
# alternate throughout this file.
# NOTE: As a standard policy, as many modules as can be supported by a # NOTE: As a standard policy, as many modules as can be supported by a
# platform should be present. The distribution comes with all modules # platform should be present. The distribution comes with all modules
# enabled that are supported by most platforms and don't require you # enabled that are supported by most platforms and don't require you
@ -152,7 +155,7 @@ _symtable symtablemodule.c
# Uncommenting the following line tells makesetup that all following # Uncommenting the following line tells makesetup that all following
# modules are to be built as shared libraries (see above for more # modules are to be built as shared libraries (see above for more
# detail; also note that *static* reverses this effect): # detail; also note that *static* or *disabled* cancels this effect):
#*shared* #*shared*
@ -394,3 +397,11 @@ _symtable symtablemodule.c
# Another example -- the 'xxsubtype' module shows C-level subtyping in action # Another example -- the 'xxsubtype' module shows C-level subtyping in action
xxsubtype xxsubtype.c xxsubtype xxsubtype.c
# Uncommenting the following line tells makesetup that all following modules
# are not built (see above for more detail).
#
#*disabled*
#
#_sqlite3 _tkinter _curses pyexpat
#_codecs_jp _codecs_kr _codecs_tw unicodedata

View File

@ -29,7 +29,9 @@
# #
# Copying Makefile.pre to Makefile: # Copying Makefile.pre to Makefile:
# - insert an identifying comment at the start # - insert an identifying comment at the start
# - replace _MODNAMES_ by the list of modules from Setup # - replace _MODBUILT_NAMES_ by the list of *static* and *shared* modules
# from Setup
# - replace _MODDISABLED_NAMES_ by the list of *disabled* modules from Setup
# - replace _MODOBJS_ by the list of objects from Setup (except for # - replace _MODOBJS_ by the list of objects from Setup (except for
# Setup files after a -n option) # Setup files after a -n option)
# - replace _MODLIBS_ by the list of libraries from Setup # - replace _MODLIBS_ by the list of libraries from Setup
@ -111,7 +113,8 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
# Rules appended by makedepend # Rules appended by makedepend
" >$rulesf " >$rulesf
DEFS= DEFS=
NAMES= BUILT=
DISABLED=
MODS= MODS=
SHAREDMODS= SHAREDMODS=
OBJS= OBJS=
@ -143,6 +146,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
'*static*') doconfig=yes; continue;; '*static*') doconfig=yes; continue;;
'*noconfig*') doconfig=no; continue;; '*noconfig*') doconfig=no; continue;;
'*shared*') doconfig=no; continue;; '*shared*') doconfig=no; continue;;
'*disabled*') doconfig=disabled; continue;;
esac esac
srcs= srcs=
cpps= cpps=
@ -183,7 +187,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
*.*) echo 1>&2 "bad word $arg in $line" *.*) echo 1>&2 "bad word $arg in $line"
exit 1;; exit 1;;
-u) skip=libs; libs="$libs -u";; -u) skip=libs; libs="$libs -u";;
[a-zA-Z_]*) NAMES="$NAMES $arg"; mods="$mods $arg";; [a-zA-Z_]*) mods="$mods $arg";;
*) echo 1>&2 "bad word $arg in $line" *) echo 1>&2 "bad word $arg in $line"
exit 1;; exit 1;;
esac esac
@ -192,6 +196,14 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
yes) yes)
LIBS="$LIBS $libs" LIBS="$LIBS $libs"
MODS="$MODS $mods" MODS="$MODS $mods"
BUILT="$BUILT $mods"
;;
no)
BUILT="$BUILT $mods"
;;
disabled)
DISABLED="$DISABLED $mods"
continue
;; ;;
esac esac
case $noobjects in case $noobjects in
@ -282,7 +294,8 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
echo "1i\\" >$sedf echo "1i\\" >$sedf
str="# Generated automatically from $makepre by makesetup." str="# Generated automatically from $makepre by makesetup."
echo "$str" >>$sedf echo "$str" >>$sedf
echo "s%_MODNAMES_%$NAMES%" >>$sedf echo "s%_MODBUILT_NAMES_%$BUILT%" >>$sedf
echo "s%_MODDISABLED_NAMES_%$DISABLED%" >>$sedf
echo "s%_MODOBJS_%$OBJS%" >>$sedf echo "s%_MODOBJS_%$OBJS%" >>$sedf
echo "s%_MODLIBS_%$LIBS%" >>$sedf echo "s%_MODLIBS_%$LIBS%" >>$sedf
echo "/Definitions added by makesetup/a$NL$NL$DEFS" >>$sedf echo "/Definitions added by makesetup/a$NL$NL$DEFS" >>$sedf

View File

@ -229,11 +229,14 @@ class PyBuildExt(build_ext):
headers = [sysconfig.get_config_h_filename()] headers = [sysconfig.get_config_h_filename()]
headers += glob(os.path.join(sysconfig.get_path('include'), "*.h")) headers += glob(os.path.join(sysconfig.get_path('include'), "*.h"))
# The sysconfig variable built by makesetup, listing the already # The sysconfig variables built by makesetup that list the already
# built modules as configured by the Setup files. # built modules and the disabled modules as configured by the Setup
modnames = sysconfig.get_config_var('MODNAMES').split() # files.
sysconf_built = sysconfig.get_config_var('MODBUILT_NAMES').split()
sysconf_dis = sysconfig.get_config_var('MODDISABLED_NAMES').split()
removed_modules = [] mods_built = []
mods_disabled = []
for ext in self.extensions: for ext in self.extensions:
ext.sources = [ find_module_file(filename, moddirlist) ext.sources = [ find_module_file(filename, moddirlist)
for filename in ext.sources ] for filename in ext.sources ]
@ -245,14 +248,22 @@ class PyBuildExt(build_ext):
# re-compile extensions if a header file has been changed # re-compile extensions if a header file has been changed
ext.depends.extend(headers) ext.depends.extend(headers)
# If a module has already been built by the Makefile, # If a module has already been built or has been disabled in the
# don't build it here. # Setup files, don't build it here.
if ext.name in modnames: if ext.name in sysconf_built:
removed_modules.append(ext) mods_built.append(ext)
if ext.name in sysconf_dis:
mods_disabled.append(ext)
if removed_modules: mods_configured = mods_built + mods_disabled
if mods_configured:
self.extensions = [x for x in self.extensions if x not in self.extensions = [x for x in self.extensions if x not in
removed_modules] mods_configured]
# Remove the shared libraries built by a previous build.
for ext in mods_configured:
fullpath = self.get_ext_fullpath(ext.name)
if os.path.exists(fullpath):
os.unlink(fullpath)
# When you run "make CC=altcc" or something similar, you really want # When you run "make CC=altcc" or something similar, you really want
# those environment variables passed into the setup.py phase. Here's # those environment variables passed into the setup.py phase. Here's
@ -295,12 +306,22 @@ class PyBuildExt(build_ext):
" detect_modules() for the module's name.") " detect_modules() for the module's name.")
print() print()
if removed_modules: if mods_built:
print()
print("The following modules found by detect_modules() in" print("The following modules found by detect_modules() in"
" setup.py, have been") " setup.py, have been")
print("built by the Makefile instead, as configured by the" print("built by the Makefile instead, as configured by the"
" Setup files:") " Setup files:")
print_three_column([ext.name for ext in removed_modules]) print_three_column([ext.name for ext in mods_built])
print()
if mods_disabled:
print()
print("The following modules found by detect_modules() in"
" setup.py have not")
print("been built, they are *disabled* in the Setup files:")
print_three_column([ext.name for ext in mods_disabled])
print()
if self.failed: if self.failed:
failed = self.failed[:] failed = self.failed[:]