3737# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3838# SOFTWARE.
3939import glob
40- import sys
40+ import logging
4141import os
4242import shutil
43- import logging
43+ import sys
4444from distutils .core import setup , Extension
4545from distutils .sysconfig import get_config_var , get_config_vars
46+
4647import _sysconfig
4748
4849__dir__ = __file__ .rpartition ("/" )[0 ]
@@ -390,39 +391,32 @@ def _build_deps(deps):
390391
391392
392393class NativeBuiltinModule :
393- def __init__ (self , name , subdir = "modules" , files = None , deps = [] , ** kwargs ):
394+ def __init__ (self , name , deps = () , ** kwargs ):
394395 self .name = name
395- self .subdir = subdir
396396 self .deps = deps
397- # common case: just a single file which is the module's name plus the file extension
398- if not files :
399- self .files = [name + ".c" ]
400- else :
401- self .files = files
402397 self .kwargs = kwargs
403398
404399 def __call__ (self ):
405- kwargs = self .kwargs
400+ kwargs = dict (self .kwargs )
401+ # common case: just a single file which is the module's name plus the file extension
402+ sources = kwargs .pop ("sources" , [os .path .join ("modules" , self .name + ".c" )])
406403
407404 libs , library_dirs , include_dirs = _build_deps (self .deps )
408- runtime_library_dirs = []
409- extra_link_args = []
410-
411- libs += kwargs .get ("libs" , [])
412- library_dirs += kwargs .get ("library_dirs" , [])
413- runtime_library_dirs += kwargs .get ("runtime_library_dirs" , [])
414- include_dirs += kwargs .get ("include_dirs" , [])
415- extra_link_args += kwargs .get ("extra_link_args" , [])
416405
417- return Extension (self .name ,
418- sources = [os .path .join (__dir__ , self .subdir , f ) for f in self .files ],
419- libraries = libs ,
420- library_dirs = library_dirs ,
421- extra_compile_args = cflags_warnings + kwargs .get ("cflags_warnings" , []),
422- runtime_library_dirs = runtime_library_dirs ,
423- include_dirs = include_dirs ,
424- extra_link_args = extra_link_args ,
425- )
406+ libs += kwargs .pop ("libs" , [])
407+ library_dirs += kwargs .pop ("library_dirs" , [])
408+ include_dirs += kwargs .pop ("include_dirs" , [])
409+ extra_compile_args = cflags_warnings + kwargs .pop ("extra_compile_args" , [])
410+
411+ return Extension (
412+ self .name ,
413+ sources = [os .path .join (__dir__ , f ) for f in sources ],
414+ libraries = libs ,
415+ library_dirs = library_dirs ,
416+ extra_compile_args = extra_compile_args ,
417+ include_dirs = include_dirs ,
418+ ** kwargs ,
419+ )
426420
427421
428422builtin_exts = (
@@ -434,8 +428,27 @@ def __call__(self):
434428 NativeBuiltinModule ("_testmultiphase" ),
435429 NativeBuiltinModule ("_ctypes_test" ),
436430 # the above modules are more core, we need them first to deal with later, more complex modules with dependencies
437- NativeBuiltinModule ("_bz2" , deps = [Bzip2Depedency ("bz2" , "bzip2==1.0.8" , "BZIP2" )], extra_link_args = ["-Wl,-rpath,%s/../lib/%s/" % (relative_rpath , SOABI )]),
438- NativeBuiltinModule ("pyexpat" , deps = [ExpatDependency ("expat" , "expat==2.2.8" , "EXPAT" )], extra_link_args = ["-Wl,-rpath,%s/../lib/%s/" % (relative_rpath , SOABI )]),
431+ NativeBuiltinModule (
432+ "_bz2" ,
433+ deps = [Bzip2Depedency ("bz2" , "bzip2==1.0.8" , "BZIP2" )],
434+ extra_link_args = ["-Wl,-rpath,%s/../lib/%s/" % (relative_rpath , SOABI )],
435+ ),
436+ NativeBuiltinModule (
437+ 'pyexpat' ,
438+ define_macros = [
439+ ('HAVE_EXPAT_CONFIG_H' , '1' ),
440+ # bpo-30947: Python uses best available entropy sources to
441+ # call XML_SetHashSalt(), expat entropy sources are not needed
442+ ('XML_POOR_ENTROPY' , '1' ),
443+ ],
444+ include_dirs = [os .path .join (__dir__ , 'expat' )],
445+ sources = ['modules/pyexpat.c' , 'expat/xmlparse.c' , 'expat/xmlrole.c' , 'expat/xmltok.c' ],
446+ depends = [
447+ 'expat/ascii.h' , 'expat/asciitab.h' , 'expat/expat.h' , 'expat/expat_config.h' , 'expat/expat_external.h' ,
448+ 'expat/internal.h' , 'expat/latin1tab.h' , 'expat/utf8tab.h' , 'expat/xmlrole.h' , 'expat/xmltok.h' ,
449+ 'expat/xmltok_impl.h' ,
450+ ],
451+ ),
439452)
440453
441454
0 commit comments