bpo-42955: Add Python/module_names.h (GH-24258)

Add a private list of all stdlib modules: _Py_module_names.

* Add Tools/scripts/generate_module_names.py script.
* Makefile: Add "make regen-module-names" command.
* setup.py: Add --list-module-names option.
* GitHub Action and Travis CI also runs "make regen-module-names",
  not ony "make regen-all", to ensure that the module names remains
  up to date.
This commit is contained in:
Victor Stinner 2021-01-19 23:04:49 +01:00 committed by GitHub
parent e8e66eab94
commit cad8020cb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 592 additions and 18 deletions

View file

@ -46,6 +46,9 @@ TEST_EXTENSIONS = (sysconfig.get_config_var('TEST_MODULES') == 'yes')
# This global variable is used to hold the list of modules to be disabled.
DISABLED_MODULE_LIST = []
# --list-module-names option used by Tools/scripts/generate_module_names.py
LIST_MODULE_NAMES = False
def get_platform():
# Cross compiling
@ -447,12 +450,20 @@ class PyBuildExt(build_ext):
# Detect which modules should be compiled
self.detect_modules()
self.remove_disabled()
if not LIST_MODULE_NAMES:
self.remove_disabled()
self.update_sources_depends()
mods_built, mods_disabled = self.remove_configured_extensions()
self.set_compiler_executables()
if LIST_MODULE_NAMES:
for ext in self.extensions:
print(ext.name)
for name in self.missing:
print(name)
return
build_ext.build_extensions(self)
if SUBPROCESS_BOOTSTRAP:
@ -1118,6 +1129,7 @@ class PyBuildExt(build_ext):
# bpo-31904: crypt() function is not provided by VxWorks.
# DES_crypt() OpenSSL provides is too weak to implement
# the encryption.
self.missing.append('_crypt')
return
if self.compiler.find_library_file(self.lib_dirs, 'crypt'):
@ -1125,8 +1137,7 @@ class PyBuildExt(build_ext):
else:
libs = []
self.add(Extension('_crypt', ['_cryptmodule.c'],
libraries=libs))
self.add(Extension('_crypt', ['_cryptmodule.c'], libraries=libs))
def detect_socket(self):
# socket(2)
@ -1735,27 +1746,29 @@ class PyBuildExt(build_ext):
if MS_WINDOWS:
multiprocessing_srcs = ['_multiprocessing/multiprocessing.c',
'_multiprocessing/semaphore.c']
else:
multiprocessing_srcs = ['_multiprocessing/multiprocessing.c']
if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
multiprocessing_srcs.append('_multiprocessing/semaphore.c')
if (sysconfig.get_config_var('HAVE_SHM_OPEN') and
sysconfig.get_config_var('HAVE_SHM_UNLINK')):
posixshmem_srcs = ['_multiprocessing/posixshmem.c']
libs = []
if sysconfig.get_config_var('SHM_NEEDS_LIBRT'):
# need to link with librt to get shm_open()
libs.append('rt')
self.add(Extension('_posixshmem', posixshmem_srcs,
define_macros={},
libraries=libs,
include_dirs=["Modules/_multiprocessing"]))
self.add(Extension('_multiprocessing', multiprocessing_srcs,
include_dirs=["Modules/_multiprocessing"]))
if (not MS_WINDOWS and
sysconfig.get_config_var('HAVE_SHM_OPEN') and
sysconfig.get_config_var('HAVE_SHM_UNLINK')):
posixshmem_srcs = ['_multiprocessing/posixshmem.c']
libs = []
if sysconfig.get_config_var('SHM_NEEDS_LIBRT'):
# need to link with librt to get shm_open()
libs.append('rt')
self.add(Extension('_posixshmem', posixshmem_srcs,
define_macros={},
libraries=libs,
include_dirs=["Modules/_multiprocessing"]))
else:
self.missing.append('_posixshmem')
def detect_uuid(self):
# Build the _uuid module if possible
uuid_incs = find_file("uuid.h", self.inc_dirs, ["/usr/include/uuid"])
@ -2549,6 +2562,12 @@ class PyBuildScripts(build_scripts):
def main():
global LIST_MODULE_NAMES
if "--list-module-names" in sys.argv:
LIST_MODULE_NAMES = True
sys.argv.remove("--list-module-names")
set_compiler_flags('CFLAGS', 'PY_CFLAGS_NODIST')
set_compiler_flags('LDFLAGS', 'PY_LDFLAGS_NODIST')