2020from distutils .spawn import find_executable
2121
2222
23+ # Compile extensions used to test Python?
24+ TEST_EXTENSIONS = True
25+
26+ # This global variable is used to hold the list of modules to be disabled.
27+ DISABLED_MODULE_LIST = []
28+
29+
2330def get_platform ():
2431 # Cross compiling
2532 if "_PYTHON_HOST_PLATFORM" in os .environ :
@@ -36,15 +43,8 @@ def get_platform():
3643MS_WINDOWS = (HOST_PLATFORM == 'win32' )
3744CYGWIN = (HOST_PLATFORM == 'cygwin' )
3845MACOS = (HOST_PLATFORM == 'darwin' )
39-
4046VXWORKS = ('vxworks' in HOST_PLATFORM )
4147
42- # Were we compiled --with-pydebug or with #define Py_DEBUG?
43- COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig .get_config_var ("CONFIG_ARGS" ))
44-
45- # This global variable is used to hold the list of modules to be disabled.
46- DISABLED_MODULE_LIST = []
47-
4848
4949SUMMARY = """
5050Python is an interpreted, interactive, object-oriented programming
@@ -242,13 +242,6 @@ def find_library_file(compiler, libname, std_dirs, paths):
242242 assert False , "Internal error: Path not found in std_dirs or paths"
243243
244244
245- def module_enabled (extlist , modname ):
246- """Returns whether the module 'modname' is present in the list
247- of extensions 'extlist'."""
248- extlist = [ext for ext in extlist if ext .name == modname ]
249- return len (extlist )
250-
251-
252245def find_module_file (module , dirlist ):
253246 """Find a module in a set of possible folders. If it is not found
254247 return the unadorned filename"""
@@ -592,18 +585,7 @@ def add_cross_compiling_paths(self):
592585 finally :
593586 os .unlink (tmpfile )
594587
595- def add_compiler_directories (self ):
596- # Ensure that /usr/local is always used, but the local build
597- # directories (i.e. '.' and 'Include') must be first. See issue
598- # 10520.
599- if not CROSS_COMPILING :
600- add_dir_to_list (self .compiler .library_dirs , '/usr/local/lib' )
601- add_dir_to_list (self .compiler .include_dirs , '/usr/local/include' )
602- # only change this for cross builds for 3.3, issues on Mageia
603- if CROSS_COMPILING :
604- self .add_cross_compiling_paths ()
605- self .add_multiarch_paths ()
606-
588+ def add_ldflags_cppflags (self ):
607589 # Add paths specified in the environment variables LDFLAGS and
608590 # CPPFLAGS for header and library files.
609591 # We must get the values from the Makefile and not the environment
@@ -623,6 +605,19 @@ def add_compiler_directories(self):
623605 for directory in reversed (options .dirs ):
624606 add_dir_to_list (dir_list , directory )
625607
608+ def configure_compiler (self ):
609+ # Ensure that /usr/local is always used, but the local build
610+ # directories (i.e. '.' and 'Include') must be first. See issue
611+ # 10520.
612+ if not CROSS_COMPILING :
613+ add_dir_to_list (self .compiler .library_dirs , '/usr/local/lib' )
614+ add_dir_to_list (self .compiler .include_dirs , '/usr/local/include' )
615+ # only change this for cross builds for 3.3, issues on Mageia
616+ if CROSS_COMPILING :
617+ self .add_cross_compiling_paths ()
618+ self .add_multiarch_paths ()
619+ self .add_ldflags_cppflags ()
620+
626621 def init_inc_lib_dirs (self ):
627622 if (not CROSS_COMPILING and
628623 os .path .normpath (sys .base_prefix ) != '/usr' and
@@ -697,13 +692,15 @@ def detect_simple_extensions(self):
697692 self .add (Extension ('_contextvars' , ['_contextvarsmodule.c' ]))
698693
699694 shared_math = 'Modules/_math.o'
700- # complex math library functions
701- self .add (Extension ('cmath' , ['cmathmodule.c' ],
695+
696+ # math library functions, e.g. sin()
697+ self .add (Extension ('math' , ['mathmodule.c' ],
702698 extra_objects = [shared_math ],
703699 depends = ['_math.h' , shared_math ],
704700 libraries = ['m' ]))
705- # math library functions, e.g. sin()
706- self .add (Extension ('math' , ['mathmodule.c' ],
701+
702+ # complex math library functions
703+ self .add (Extension ('cmath' , ['cmathmodule.c' ],
707704 extra_objects = [shared_math ],
708705 depends = ['_math.h' , shared_math ],
709706 libraries = ['m' ]))
@@ -735,15 +732,7 @@ def detect_simple_extensions(self):
735732 self .add (Extension ("_json" , ["_json.c" ],
736733 # pycore_accu.h requires Py_BUILD_CORE_BUILTIN
737734 extra_compile_args = ['-DPy_BUILD_CORE_BUILTIN' ]))
738- # Python C API test module
739- self .add (Extension ('_testcapi' , ['_testcapimodule.c' ],
740- depends = ['testcapi_long.h' ]))
741- # Python PEP-3118 (buffer protocol) test module
742- self .add (Extension ('_testbuffer' , ['_testbuffer.c' ]))
743- # Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421)
744- self .add (Extension ('_testimportmultiple' , ['_testimportmultiple.c' ]))
745- # Test multi-phase extension module init (PEP 489)
746- self .add (Extension ('_testmultiphase' , ['_testmultiphase.c' ]))
735+
747736 # profiler (_lsprof is for cProfile.py)
748737 self .add (Extension ('_lsprof' , ['_lsprof.c' , 'rotatingtree.c' ]))
749738 # static Unicode character database
@@ -794,11 +783,6 @@ def detect_simple_extensions(self):
794783 # syslog daemon interface
795784 self .add (Extension ('syslog' , ['syslogmodule.c' ]))
796785
797- # Fuzz tests.
798- self .add (Extension ('_xxtestfuzz' ,
799- ['_xxtestfuzz/_xxtestfuzz.c' ,
800- '_xxtestfuzz/fuzzer.c' ]))
801-
802786 # Python interface to subinterpreter C-API.
803787 self .add (Extension ('_xxsubinterpreters' ,
804788 ['_xxsubinterpretersmodule.c' ],
@@ -827,6 +811,25 @@ def detect_simple_extensions(self):
827811 # POSIX subprocess module helper.
828812 self .add (Extension ('_posixsubprocess' , ['_posixsubprocess.c' ]))
829813
814+ def detect_test_extensions (self ):
815+ # Python C API test module
816+ self .add (Extension ('_testcapi' , ['_testcapimodule.c' ],
817+ depends = ['testcapi_long.h' ]))
818+
819+ # Python PEP-3118 (buffer protocol) test module
820+ self .add (Extension ('_testbuffer' , ['_testbuffer.c' ]))
821+
822+ # Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421)
823+ self .add (Extension ('_testimportmultiple' , ['_testimportmultiple.c' ]))
824+
825+ # Test multi-phase extension module init (PEP 489)
826+ self .add (Extension ('_testmultiphase' , ['_testmultiphase.c' ]))
827+
828+ # Fuzz tests.
829+ self .add (Extension ('_xxtestfuzz' ,
830+ ['_xxtestfuzz/_xxtestfuzz.c' ,
831+ '_xxtestfuzz/fuzzer.c' ]))
832+
830833 def detect_readline_curses (self ):
831834 # readline
832835 do_readline = self .compiler .find_library_file (self .lib_dirs , 'readline' )
@@ -936,6 +939,7 @@ def detect_readline_curses(self):
936939 curses_defines .append (('HAVE_NCURSESW' , '1' ))
937940 curses_defines .append (('_XOPEN_SOURCE_EXTENDED' , '1' ))
938941
942+ curses_enabled = True
939943 if curses_library .startswith ('ncurses' ):
940944 curses_libs = [curses_library ]
941945 self .add (Extension ('_curses' , ['_cursesmodule.c' ],
@@ -956,10 +960,11 @@ def detect_readline_curses(self):
956960 define_macros = curses_defines ,
957961 libraries = curses_libs ))
958962 else :
963+ curses_enabled = False
959964 self .missing .append ('_curses' )
960965
961966 # If the curses module is enabled, check for the panel module
962- if (module_enabled ( self . extensions , '_curses' ) and
967+ if (curses_enabled and
963968 self .compiler .find_library_file (self .lib_dirs , panel_library )):
964969 self .add (Extension ('_curses_panel' , ['_curses_panel.c' ],
965970 include_dirs = curses_includes ,
@@ -1622,17 +1627,19 @@ def detect_uuid(self):
16221627 uuid_libs = ['uuid' ]
16231628 else :
16241629 uuid_libs = []
1625- self .extensions . append (Extension ('_uuid' , ['_uuidmodule.c' ],
1626- libraries = uuid_libs ,
1627- include_dirs = uuid_incs ))
1630+ self .add (Extension ('_uuid' , ['_uuidmodule.c' ],
1631+ libraries = uuid_libs ,
1632+ include_dirs = uuid_incs ))
16281633 else :
16291634 self .missing .append ('_uuid' )
16301635
16311636 def detect_modules (self ):
1632- self .add_compiler_directories ()
1637+ self .configure_compiler ()
16331638 self .init_inc_lib_dirs ()
16341639
16351640 self .detect_simple_extensions ()
1641+ if TEST_EXTENSIONS :
1642+ self .detect_test_extensions ()
16361643 self .detect_readline_curses ()
16371644 self .detect_crypt ()
16381645 self .detect_socket ()
@@ -1652,13 +1659,11 @@ def detect_modules(self):
16521659 self .detect_uuid ()
16531660
16541661## # Uncomment these lines if you want to play with xxmodule.c
1655- ## ext = Extension('xx', ['xxmodule.c'])
1656- ## self.extensions.append(ext)
1662+ ## self.add(Extension('xx', ['xxmodule.c']))
16571663
16581664 if 'd' not in sysconfig .get_config_var ('ABIFLAGS' ):
1659- ext = Extension ('xxlimited' , ['xxlimited.c' ],
1660- define_macros = [('Py_LIMITED_API' , '0x03050000' )])
1661- self .extensions .append (ext )
1665+ self .add (Extension ('xxlimited' , ['xxlimited.c' ],
1666+ define_macros = [('Py_LIMITED_API' , '0x03050000' )]))
16621667
16631668 def detect_tkinter_explicitly (self ):
16641669 # Build _tkinter using explicit locations for Tcl/Tk.
@@ -1687,12 +1692,10 @@ def detect_tkinter_explicitly(self):
16871692
16881693 extra_compile_args = tcltk_includes .split ()
16891694 extra_link_args = tcltk_libs .split ()
1690- ext = Extension ('_tkinter' , ['_tkinter.c' , 'tkappinit.c' ],
1691- define_macros = [('WITH_APPINIT' , 1 )],
1692- extra_compile_args = extra_compile_args ,
1693- extra_link_args = extra_link_args ,
1694- )
1695- self .extensions .append (ext )
1695+ self .add (Extension ('_tkinter' , ['_tkinter.c' , 'tkappinit.c' ],
1696+ define_macros = [('WITH_APPINIT' , 1 )],
1697+ extra_compile_args = extra_compile_args ,
1698+ extra_link_args = extra_link_args ))
16961699 return True
16971700
16981701 def detect_tkinter_darwin (self ):
@@ -1774,14 +1777,12 @@ def detect_tkinter_darwin(self):
17741777 frameworks .append ('-arch' )
17751778 frameworks .append (a )
17761779
1777- ext = Extension ('_tkinter' , ['_tkinter.c' , 'tkappinit.c' ],
1778- define_macros = [('WITH_APPINIT' , 1 )],
1779- include_dirs = include_dirs ,
1780- libraries = [],
1781- extra_compile_args = frameworks [2 :],
1782- extra_link_args = frameworks ,
1783- )
1784- self .extensions .append (ext )
1780+ self .add (Extension ('_tkinter' , ['_tkinter.c' , 'tkappinit.c' ],
1781+ define_macros = [('WITH_APPINIT' , 1 )],
1782+ include_dirs = include_dirs ,
1783+ libraries = [],
1784+ extra_compile_args = frameworks [2 :],
1785+ extra_link_args = frameworks ))
17851786 return True
17861787
17871788 def detect_tkinter (self ):
@@ -1839,7 +1840,10 @@ def detect_tkinter(self):
18391840
18401841 # OK... everything seems to be present for Tcl/Tk.
18411842
1842- include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
1843+ include_dirs = []
1844+ libs = []
1845+ defs = []
1846+ added_lib_dirs = []
18431847 for dir in tcl_includes + tk_includes :
18441848 if dir not in include_dirs :
18451849 include_dirs .append (dir )
@@ -1895,13 +1899,11 @@ def detect_tkinter(self):
18951899 # *** Uncomment these for TOGL extension only:
18961900 # -lGL -lGLU -lXext -lXmu \
18971901
1898- ext = Extension ('_tkinter' , ['_tkinter.c' , 'tkappinit.c' ],
1899- define_macros = [('WITH_APPINIT' , 1 )] + defs ,
1900- include_dirs = include_dirs ,
1901- libraries = libs ,
1902- library_dirs = added_lib_dirs ,
1903- )
1904- self .extensions .append (ext )
1902+ self .add (Extension ('_tkinter' , ['_tkinter.c' , 'tkappinit.c' ],
1903+ define_macros = [('WITH_APPINIT' , 1 )] + defs ,
1904+ include_dirs = include_dirs ,
1905+ libraries = libs ,
1906+ library_dirs = added_lib_dirs ))
19051907 return True
19061908
19071909 def configure_ctypes_darwin (self , ext ):
@@ -1980,11 +1982,12 @@ def detect_ctypes(self):
19801982 libraries = [],
19811983 sources = sources ,
19821984 depends = depends )
1983- # function my_sqrt() needs libm for sqrt()
1984- ext_test = Extension ('_ctypes_test' ,
1985- sources = ['_ctypes/_ctypes_test.c' ],
1986- libraries = ['m' ])
1987- self .extensions .extend ([ext , ext_test ])
1985+ self .add (ext )
1986+ if TEST_EXTENSIONS :
1987+ # function my_sqrt() needs libm for sqrt()
1988+ self .add (Extension ('_ctypes_test' ,
1989+ sources = ['_ctypes/_ctypes_test.c' ],
1990+ libraries = ['m' ]))
19881991
19891992 ffi_inc_dirs = self .inc_dirs .copy ()
19901993 if MACOS :
0 commit comments