Skip to content

bpo-45573: Use Makefile's dependencies in setup.py (GH-29559) #29559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -2460,7 +2460,7 @@ MODULE_UNICODEDATA_DEPS=$(srcdir)/Modules/unicodedata_db.h $(srcdir)/Modules/uni
MODULE__BLAKE2_DEPS=$(srcdir)/Modules/_blake2/impl/blake2-config.h $(srcdir)/Modules/_blake2/impl/blake2-dispatch.c $(srcdir)/Modules/_blake2/impl/blake2-impl.h $(srcdir)/Modules/_blake2/impl/blake2-kat.h $(srcdir)/Modules/_blake2/impl/blake2.h $(srcdir)/Modules/_blake2/impl/blake2b-load-sse2.h $(srcdir)/Modules/_blake2/impl/blake2b-load-sse41.h $(srcdir)/Modules/_blake2/impl/blake2b-ref.c $(srcdir)/Modules/_blake2/impl/blake2b-round.h $(srcdir)/Modules/_blake2/impl/blake2b-test.c $(srcdir)/Modules/_blake2/impl/blake2b.c $(srcdir)/Modules/_blake2/impl/blake2bp-test.c $(srcdir)/Modules/_blake2/impl/blake2bp.c $(srcdir)/Modules/_blake2/impl/blake2s-load-sse2.h $(srcdir)/Modules/_blake2/impl/blake2s-load-sse41.h $(srcdir)/Modules/_blake2/impl/blake2s-load-xop.h $(srcdir)/Modules/_blake2/impl/blake2s-ref.c $(srcdir)/Modules/_blake2/impl/blake2s-round.h $(srcdir)/Modules/_blake2/impl/blake2s-test.c $(srcdir)/Modules/_blake2/impl/blake2s.c $(srcdir)/Modules/_blake2/impl/blake2sp-test.c $(srcdir)/Modules/_blake2/impl/blake2sp.c $(srcdir)/Modules/hashlib.h
MODULE__CTYPES_DEPS=$(srcdir)/Modules/_ctypes/ctypes.h
MODULE__DECIMAL_DEPS=$(srcdir)/Modules/_decimal/docstrings.h $(LIBMPDEC_HEADERS) @LIBMPDEC_INTERNAL@
MODULE__ELEMENTTREE_DEPS=$(LIBEXPAT_HEADERS) @LIBEXPAT_INTERNAL@
MODULE__ELEMENTTREE_DEPS=$(srcdir)/Modules/pyexpat.c $(LIBEXPAT_HEADERS) @LIBEXPAT_INTERNAL@
MODULE__HASHLIB_DEPS=$(srcdir)/Modules/hashlib.h
MODULE__IO_DEPS=$(srcdir)/Modules/_io/_iomodule.h
MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h
Expand Down
87 changes: 27 additions & 60 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def find_module_file(module, dirlist):
return module
if len(dirs) > 1:
log.info(f"WARNING: multiple copies of {module} found")
return os.path.join(dirs[0], module)
return os.path.abspath(os.path.join(dirs[0], module))


def parse_cflags(flags):
Expand Down Expand Up @@ -454,7 +454,13 @@ def remove_disabled(self):
def update_sources_depends(self):
# Fix up the autodetected modules, prefixing all the source files
# with Modules/.
moddirlist = [os.path.join(self.srcdir, 'Modules')]
# Add dependencies from MODULE_{name}_DEPS variable
moddirlist = [
# files in Modules/ directory
os.path.join(self.srcdir, 'Modules'),
# files relative to build base, e.g. libmpdec.a, libexpat.a
os.getcwd()
]

# Fix up the paths for scripts, too
self.distribution.scripts = [os.path.join(self.srcdir, filename)
Expand All @@ -470,11 +476,16 @@ def update_sources_depends(self):
for ext in self.extensions:
ext.sources = [ find_module_file(filename, moddirlist)
for filename in ext.sources ]
if ext.depends is not None:
ext.depends = [find_module_file(filename, moddirlist)
for filename in ext.depends]
else:
ext.depends = []
# Update dependencies from Makefile
makedeps = sysconfig.get_config_var(f"MODULE_{ext.name.upper()}_DEPS")
if makedeps:
# remove backslashes from line break continuations
ext.depends.extend(
dep for dep in makedeps.split() if dep != "\\"
)
ext.depends = [
find_module_file(filename, moddirlist) for filename in ext.depends
]
# re-compile extensions if a header file has been changed
ext.depends.extend(headers)

Expand Down Expand Up @@ -966,12 +977,10 @@ def detect_simple_extensions(self):

# math library functions, e.g. sin()
self.add(Extension('math', ['mathmodule.c'],
depends=['_math.h'],
libraries=['m']))

# complex math library functions
self.add(Extension('cmath', ['cmathmodule.c'],
depends=['_math.h'],
libraries=['m']))

# time libraries: librt may be needed for clock_gettime()
Expand Down Expand Up @@ -1003,8 +1012,7 @@ def detect_simple_extensions(self):
# profiler (_lsprof is for cProfile.py)
self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']))
# static Unicode character database
self.add(Extension('unicodedata', ['unicodedata.c'],
depends=['unicodedata_db.h', 'unicodename_db.h']))
self.add(Extension('unicodedata', ['unicodedata.c']))
# _opcode module
self.add(Extension('_opcode', ['_opcode.c']))
# asyncio speedups
Expand Down Expand Up @@ -1081,8 +1089,7 @@ def detect_simple_extensions(self):

def detect_test_extensions(self):
# Python C API test module
self.add(Extension('_testcapi', ['_testcapimodule.c'],
depends=['testcapi_long.h']))
self.add(Extension('_testcapi', ['_testcapimodule.c']))

# Python Internal C API test module
self.add(Extension('_testinternalcapi', ['_testinternalcapi.c']))
Expand Down Expand Up @@ -1263,7 +1270,7 @@ def detect_crypt(self):
self.add(Extension('_crypt', ['_cryptmodule.c'], libraries=libs))

def detect_socket(self):
self.add(Extension('_socket', ['socketmodule.c'], depends=['socketmodule.h']))
self.add(Extension('_socket', ['socketmodule.c']))

def detect_dbm_gdbm(self):
# Modules that provide persistent dictionary-like semantics. You will
Expand Down Expand Up @@ -1527,11 +1534,6 @@ def detect_expat_elementtree(self):
ldflags = parse_ldflags(sysconfig.get_config_var("EXPAT_LDFLAGS"))
library_dirs, libraries, extra_link_args = ldflags

expat_depends = []
libexpat_a = sysconfig.get_config_var("LIBEXPAT_A")
if libexpat_a:
expat_depends.append(libexpat_a)

self.add(Extension('pyexpat',
include_dirs=include_dirs,
define_macros=define_macros,
Expand All @@ -1540,8 +1542,7 @@ def detect_expat_elementtree(self):
library_dirs=library_dirs,
libraries=libraries,
extra_link_args=extra_link_args,
sources=['pyexpat.c'],
depends=expat_depends))
sources=['pyexpat.c']))

# Fredrik Lundh's cElementTree module. Note that this also
# uses expat (via the CAPI hook in pyexpat).
Expand All @@ -1551,8 +1552,7 @@ def detect_expat_elementtree(self):
undef_macros=undef_macros,
extra_compile_args=extra_compile_args,
# no EXPAT_LDFLAGS
sources=['_elementtree.c'],
depends=['pyexpat.c', *expat_depends]))
sources=['_elementtree.c']))

def detect_multibytecodecs(self):
# Hye-Shik Chang's CJKCodecs modules.
Expand Down Expand Up @@ -1961,7 +1961,6 @@ def detect_ctypes(self):
'_ctypes/callproc.c',
'_ctypes/stgdict.c',
'_ctypes/cfield.c']
depends = ['_ctypes/ctypes.h']

if MACOS:
sources.append('_ctypes/malloc_closure.c')
Expand All @@ -1988,8 +1987,7 @@ def detect_ctypes(self):
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
libraries=[],
sources=sources,
depends=depends)
sources=sources)
self.add(ext)
if TEST_EXTENSIONS:
# function my_sqrt() needs libm for sqrt()
Expand Down Expand Up @@ -2049,7 +2047,6 @@ def detect_ctypes(self):
def detect_decimal(self):
# Stefan Krah's _decimal module
sources = ['_decimal/_decimal.c']
depends = ['_decimal/docstrings.h']

cflags = parse_cflags(sysconfig.get_config_var("DECIMAL_CFLAGS"))
include_dirs, define_macros, undef_macros, extra_compile_args = cflags
Expand All @@ -2058,10 +2055,6 @@ def detect_decimal(self):
ldflags = parse_ldflags(sysconfig.get_config_var("DECIMAL_LDFLAGS"))
library_dirs, libraries, extra_link_args = ldflags

libmpdec_a = sysconfig.get_config_var("LIBMPDEC_A")
if libmpdec_a:
depends.append(libmpdec_a)

# Uncomment for extra functionality:
#define_macros.append(('EXTRA_FUNCTIONALITY', 1))
self.add(Extension('_decimal',
Expand All @@ -2072,8 +2065,7 @@ def detect_decimal(self):
library_dirs=library_dirs,
libraries=libraries,
extra_link_args=extra_link_args,
sources=sources,
depends=depends))
sources=sources))

def detect_openssl_hashlib(self):
# Detect SSL support for the socket module (via _ssl)
Expand Down Expand Up @@ -2141,24 +2133,13 @@ def split_var(name, sep):
Extension(
'_ssl',
['_ssl.c'],
depends=[
'socketmodule.h',
'_ssl.h',
'_ssl_data_111.h',
'_ssl_data_300.h',
'_ssl_data.h',
'_ssl/debughelpers.c',
'_ssl/misc.c',
'_ssl/cert.c',
],
**openssl_extension_kwargs
)
)
self.add(
Extension(
'_hashlib',
['_hashopenssl.c'],
depends=['hashlib.h'],
**openssl_extension_kwargs,
)
)
Expand All @@ -2182,52 +2163,38 @@ def detect_hash_builtins(self):

if "sha256" in configured:
self.add(Extension(
'_sha256', ['sha256module.c'],
depends=['hashlib.h'],
'_sha256', ['sha256module.c']
))

if "sha512" in configured:
self.add(Extension(
'_sha512', ['sha512module.c'],
depends=['hashlib.h'],
))

if "md5" in configured:
self.add(Extension(
'_md5', ['md5module.c'],
depends=['hashlib.h'],
))

if "sha1" in configured:
self.add(Extension(
'_sha1', ['sha1module.c'],
depends=['hashlib.h'],
))

if "blake2" in configured:
blake2_deps = glob(
os.path.join(escape(self.srcdir), 'Modules/_blake2/impl/*')
)
blake2_deps.append('hashlib.h')
self.add(Extension(
'_blake2',
[
'_blake2/blake2module.c',
'_blake2/blake2b_impl.c',
'_blake2/blake2s_impl.c'
],
depends=blake2_deps,
]
))

if "sha3" in configured:
sha3_deps = glob(
os.path.join(escape(self.srcdir), 'Modules/_sha3/kcp/*')
)
sha3_deps.append('hashlib.h')
self.add(Extension(
'_sha3',
['_sha3/sha3module.c'],
depends=sha3_deps,
))

def detect_nis(self):
Expand Down