Skip to content

Commit c399786

Browse files
authored
bpo-45573: Use Makefile's dependencies in setup.py (GH-29559)
1 parent c2c4fdf commit c399786

File tree

2 files changed

+28
-61
lines changed

2 files changed

+28
-61
lines changed

Makefile.pre.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2460,7 +2460,7 @@ MODULE_UNICODEDATA_DEPS=$(srcdir)/Modules/unicodedata_db.h $(srcdir)/Modules/uni
24602460
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
24612461
MODULE__CTYPES_DEPS=$(srcdir)/Modules/_ctypes/ctypes.h
24622462
MODULE__DECIMAL_DEPS=$(srcdir)/Modules/_decimal/docstrings.h $(LIBMPDEC_HEADERS) @LIBMPDEC_INTERNAL@
2463-
MODULE__ELEMENTTREE_DEPS=$(LIBEXPAT_HEADERS) @LIBEXPAT_INTERNAL@
2463+
MODULE__ELEMENTTREE_DEPS=$(srcdir)/Modules/pyexpat.c $(LIBEXPAT_HEADERS) @LIBEXPAT_INTERNAL@
24642464
MODULE__HASHLIB_DEPS=$(srcdir)/Modules/hashlib.h
24652465
MODULE__IO_DEPS=$(srcdir)/Modules/_io/_iomodule.h
24662466
MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h

setup.py

Lines changed: 27 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def find_module_file(module, dirlist):
361361
return module
362362
if len(dirs) > 1:
363363
log.info(f"WARNING: multiple copies of {module} found")
364-
return os.path.join(dirs[0], module)
364+
return os.path.abspath(os.path.join(dirs[0], module))
365365

366366

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

459465
# Fix up the paths for scripts, too
460466
self.distribution.scripts = [os.path.join(self.srcdir, filename)
@@ -470,11 +476,16 @@ def update_sources_depends(self):
470476
for ext in self.extensions:
471477
ext.sources = [ find_module_file(filename, moddirlist)
472478
for filename in ext.sources ]
473-
if ext.depends is not None:
474-
ext.depends = [find_module_file(filename, moddirlist)
475-
for filename in ext.depends]
476-
else:
477-
ext.depends = []
479+
# Update dependencies from Makefile
480+
makedeps = sysconfig.get_config_var(f"MODULE_{ext.name.upper()}_DEPS")
481+
if makedeps:
482+
# remove backslashes from line break continuations
483+
ext.depends.extend(
484+
dep for dep in makedeps.split() if dep != "\\"
485+
)
486+
ext.depends = [
487+
find_module_file(filename, moddirlist) for filename in ext.depends
488+
]
478489
# re-compile extensions if a header file has been changed
479490
ext.depends.extend(headers)
480491

@@ -966,12 +977,10 @@ def detect_simple_extensions(self):
966977

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

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

977986
# time libraries: librt may be needed for clock_gettime()
@@ -1003,8 +1012,7 @@ def detect_simple_extensions(self):
10031012
# profiler (_lsprof is for cProfile.py)
10041013
self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']))
10051014
# static Unicode character database
1006-
self.add(Extension('unicodedata', ['unicodedata.c'],
1007-
depends=['unicodedata_db.h', 'unicodename_db.h']))
1015+
self.add(Extension('unicodedata', ['unicodedata.c']))
10081016
# _opcode module
10091017
self.add(Extension('_opcode', ['_opcode.c']))
10101018
# asyncio speedups
@@ -1081,8 +1089,7 @@ def detect_simple_extensions(self):
10811089

10821090
def detect_test_extensions(self):
10831091
# Python C API test module
1084-
self.add(Extension('_testcapi', ['_testcapimodule.c'],
1085-
depends=['testcapi_long.h']))
1092+
self.add(Extension('_testcapi', ['_testcapimodule.c']))
10861093

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

12651272
def detect_socket(self):
1266-
self.add(Extension('_socket', ['socketmodule.c'], depends=['socketmodule.h']))
1273+
self.add(Extension('_socket', ['socketmodule.c']))
12671274

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

1530-
expat_depends = []
1531-
libexpat_a = sysconfig.get_config_var("LIBEXPAT_A")
1532-
if libexpat_a:
1533-
expat_depends.append(libexpat_a)
1534-
15351537
self.add(Extension('pyexpat',
15361538
include_dirs=include_dirs,
15371539
define_macros=define_macros,
@@ -1540,8 +1542,7 @@ def detect_expat_elementtree(self):
15401542
library_dirs=library_dirs,
15411543
libraries=libraries,
15421544
extra_link_args=extra_link_args,
1543-
sources=['pyexpat.c'],
1544-
depends=expat_depends))
1545+
sources=['pyexpat.c']))
15451546

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

15571557
def detect_multibytecodecs(self):
15581558
# Hye-Shik Chang's CJKCodecs modules.
@@ -1961,7 +1961,6 @@ def detect_ctypes(self):
19611961
'_ctypes/callproc.c',
19621962
'_ctypes/stgdict.c',
19631963
'_ctypes/cfield.c']
1964-
depends = ['_ctypes/ctypes.h']
19651964

19661965
if MACOS:
19671966
sources.append('_ctypes/malloc_closure.c')
@@ -1988,8 +1987,7 @@ def detect_ctypes(self):
19881987
extra_compile_args=extra_compile_args,
19891988
extra_link_args=extra_link_args,
19901989
libraries=[],
1991-
sources=sources,
1992-
depends=depends)
1990+
sources=sources)
19931991
self.add(ext)
19941992
if TEST_EXTENSIONS:
19951993
# function my_sqrt() needs libm for sqrt()
@@ -2049,7 +2047,6 @@ def detect_ctypes(self):
20492047
def detect_decimal(self):
20502048
# Stefan Krah's _decimal module
20512049
sources = ['_decimal/_decimal.c']
2052-
depends = ['_decimal/docstrings.h']
20532050

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

2061-
libmpdec_a = sysconfig.get_config_var("LIBMPDEC_A")
2062-
if libmpdec_a:
2063-
depends.append(libmpdec_a)
2064-
20652058
# Uncomment for extra functionality:
20662059
#define_macros.append(('EXTRA_FUNCTIONALITY', 1))
20672060
self.add(Extension('_decimal',
@@ -2072,8 +2065,7 @@ def detect_decimal(self):
20722065
library_dirs=library_dirs,
20732066
libraries=libraries,
20742067
extra_link_args=extra_link_args,
2075-
sources=sources,
2076-
depends=depends))
2068+
sources=sources))
20772069

20782070
def detect_openssl_hashlib(self):
20792071
# Detect SSL support for the socket module (via _ssl)
@@ -2141,24 +2133,13 @@ def split_var(name, sep):
21412133
Extension(
21422134
'_ssl',
21432135
['_ssl.c'],
2144-
depends=[
2145-
'socketmodule.h',
2146-
'_ssl.h',
2147-
'_ssl_data_111.h',
2148-
'_ssl_data_300.h',
2149-
'_ssl_data.h',
2150-
'_ssl/debughelpers.c',
2151-
'_ssl/misc.c',
2152-
'_ssl/cert.c',
2153-
],
21542136
**openssl_extension_kwargs
21552137
)
21562138
)
21572139
self.add(
21582140
Extension(
21592141
'_hashlib',
21602142
['_hashopenssl.c'],
2161-
depends=['hashlib.h'],
21622143
**openssl_extension_kwargs,
21632144
)
21642145
)
@@ -2182,52 +2163,38 @@ def detect_hash_builtins(self):
21822163

21832164
if "sha256" in configured:
21842165
self.add(Extension(
2185-
'_sha256', ['sha256module.c'],
2186-
depends=['hashlib.h'],
2166+
'_sha256', ['sha256module.c']
21872167
))
21882168

21892169
if "sha512" in configured:
21902170
self.add(Extension(
21912171
'_sha512', ['sha512module.c'],
2192-
depends=['hashlib.h'],
21932172
))
21942173

21952174
if "md5" in configured:
21962175
self.add(Extension(
21972176
'_md5', ['md5module.c'],
2198-
depends=['hashlib.h'],
21992177
))
22002178

22012179
if "sha1" in configured:
22022180
self.add(Extension(
22032181
'_sha1', ['sha1module.c'],
2204-
depends=['hashlib.h'],
22052182
))
22062183

22072184
if "blake2" in configured:
2208-
blake2_deps = glob(
2209-
os.path.join(escape(self.srcdir), 'Modules/_blake2/impl/*')
2210-
)
2211-
blake2_deps.append('hashlib.h')
22122185
self.add(Extension(
22132186
'_blake2',
22142187
[
22152188
'_blake2/blake2module.c',
22162189
'_blake2/blake2b_impl.c',
22172190
'_blake2/blake2s_impl.c'
2218-
],
2219-
depends=blake2_deps,
2191+
]
22202192
))
22212193

22222194
if "sha3" in configured:
2223-
sha3_deps = glob(
2224-
os.path.join(escape(self.srcdir), 'Modules/_sha3/kcp/*')
2225-
)
2226-
sha3_deps.append('hashlib.h')
22272195
self.add(Extension(
22282196
'_sha3',
22292197
['_sha3/sha3module.c'],
2230-
depends=sha3_deps,
22312198
))
22322199

22332200
def detect_nis(self):

0 commit comments

Comments
 (0)