B � f�v�@s�dZddlZddlZddlZddlZddlmZddlTddlm Z m Z ddlm Z ddl m Z ddlmZdd lmZdd lmZdd lmZe�d �Zd d�ZGdd�de�ZdS)z�distutils.command.build_ext Implements the Distutils 'build_ext' command, for building extension modules (currently limited to C extensions, should accommodate C++ extensions ASAP).�N)�Command)�*)�customize_compiler�get_python_version)�get_config_h_filename)� newer_group)� Extension)� get_platform)�log)� USER_BASEz3^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$cCsddlm}|�dS)Nr)�show_compilers)�distutils.ccompilerr )r �r�@/opt/alt/python37/lib64/python3.7/distutils/command/build_ext.pyr s r c@seZdZdZdejZddddde�fdd d d efd d ddddefddddddddddgZddddd gZ d!d"d#e fgZ d$d%�Z d&d'�Z d(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zejd6d7��Zd8d9�Zd:d;�Zdd?�Zd@dA�ZdBdC�ZdDdE�ZdFdG�Zd"S)H� build_extz8build C/C++ extensions (compile/link to build directory)z (separated by '%s'))z build-lib=�bz(directory for compiled extension modules)z build-temp=�tz1directory for temporary files (build by-products)z plat-name=�pz>platform name to cross-compile for, if supported (default: %s))�inplace�iziignore build-lib and put compiled extensions into the source directory alongside your pure Python modulesz include-dirs=�Iz.list of directories to search for header files)zdefine=�DzC preprocessor macros to define)zundef=�Uz!C preprocessor macros to undefine)z libraries=�lz!external C libraries to link withz library-dirs=�Lz.directories to search for external C libraries)zrpath=�Rz7directories to search for shared C libraries at runtime)z link-objects=�Oz2extra explicit link objects to include in the link)�debug�gz'compile/link with debugging information)�force�fz2forcibly build everything (ignore file timestamps))z compiler=�czspecify the compiler type)z parallel=�jznumber of parallel build jobs)zswig-cppNz)make SWIG create C++ files (default is C))z swig-opts=Nz!list of SWIG command line options)zswig=Nzpath to the SWIG executable)�userNz#add user include, library and rpathrrrzswig-cppr#z help-compilerNzlist available compilerscCs�d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_d|_d|_d|_d|_dS)Nr)� extensions� build_lib� plat_name� build_tempr�package� include_dirs�define�undef� libraries� library_dirs�rpath� link_objectsrr�compiler�swig�swig_cpp� swig_optsr#�parallel)�selfrrr�initialize_optionsjs*zbuild_ext.initialize_optionsc Cs�ddlm}|�ddddddd d �|jdkr8|jj|_|jj|_|��}|jd d �}|j dkrn|jj pjg|_ t |j t �r�|j � t j�|_ tjtjkr�|j �t j�tjd ��|j �|� t jj��||kr�|j �|� t jj��|�d�|�d�|jdk�rg|_|jdk�rg|_nt |jt ��r:|j� t j�|_|jdk�rNg|_nt |jt ��rl|j� t j�|_t jdk�rh|j�t j�tjd��tjtjk�r�|j�t j�tjd��|j�r�t j�|jd�|_nt j�|jd�|_|j �t j�t���t tdd�}|�r|j�|�|j!dk�r*d}n|j!dd�}t j�tjd�}|�r\t j�||�}|j�|�tj"dd�dk�r�tj#�$t j�tjd���r�|j�t j�tjddt%�d��n |j�d�|�&d��r�|j'�s�|j�|�&d ��n |j�d�|j(�r|j(� d!�}d"d#�|D�|_(|j)�r4|j)� d!�|_)|j*dk�rHg|_*n|j*� d$�|_*|j+�r�t j�t,d �}t j�t,d�} t j�-|��r�|j �|�t j�-| ��r�|j�| �|j�| �t |j.t ��r�yt/|j.�|_.Wnt0k �r�t1d%��YnXdS)&Nr)� sysconfigZbuild)r%r%)r'r')r0r0)rr)rr)r4r4)r&r&�)Z plat_specificZincluder,r/�ntZlibsZDebugZRelease�_home�win32�ZPCbuild��cygwin�bin�lib�pythonZconfig�.�Py_ENABLE_SHAREDZLIBDIR�,cSsg|] }|df�qS)�1r)�.0Zsymbolrrr� �sz.build_ext.finalize_options..� zparallel should be an integer)2� distutilsr7Zset_undefined_optionsr(� distributionZ ext_packageZ ext_modulesr$Zget_python_incr)� isinstance�str�split�os�pathsep�sys� exec_prefix�base_exec_prefix�append�path�join�extendZensure_string_listr,r-r.�name�prefixrr'�dirnamer�getattrr&�platform� executable� startswithr�get_config_varZ python_buildr*r+r3r#r �isdirr4�int� ValueErrorZDistutilsOptionError) r5r7Z py_includeZplat_py_includeZ _sys_home�suffixZnew_libZdefinesZ user_includeZuser_librrr�finalize_options�s�                           zbuild_ext.finalize_optionscCsrddlm}|jsdS|j��rL|�d�}|j�|��p:g�|j � |j �||j |j |j|jd�|_ t|j �tjdkr�|jt�kr�|j �|j�|jdk r�|j �|j�|jdk r�x |jD]\}}|j �||�q�W|jdk r�x|jD]}|j �|�q�W|jdk �r|j �|j�|j dk �r2|j �|j �|jdk �rL|j �|j�|j dk �rf|j �!|j �|�"�dS)Nr)� new_compiler� build_clib)r0�verbose�dry_runrr9)#r rdr$rJZhas_c_libraries�get_finalized_commandr,rVZget_library_namesr-rSrer0rfrgrrrNrWr&r Z initializer)Zset_include_dirsr*Z define_macror+Zundefine_macroZ set_librariesZset_library_dirsr.Zset_runtime_library_dirsr/Zset_link_objects�build_extensions)r5rdrerW�value�macrorrr�runs>             z build_ext.runc Cs�t|t�std���xjt|�D�]\\}}t|t�r4qt|t�rJt|�dkrRtd��|\}}t�d|�t|t �rzt � |�s�td��t|t �s�td��t||d�}x*dD]"}|� |�}|d k r�t|||�q�W|� d �|_d |kr�t�d �|� d �}|�rtg|_g|_xj|D]b} t| t��r,t| �dk�s4td��t| �dk�rT|j�| d�nt| �dk�r|j�| ��qW|||<qWd S)a�Ensure that the list of extensions (presumably provided as a command option 'extensions') is valid, i.e. it is a list of Extension objects. We also support the old-style list of 2-tuples, where the tuples are (ext_name, build_info), which are converted to Extension instances here. Raise DistutilsSetupError if the structure is invalid anywhere; just returns otherwise. z:'ext_modules' option must be a list of Extension instances�zMeach element of 'ext_modules' option must be an Extension instance or 2-tuplezvold-style (ext_name, build_info) tuple found in ext_modules for extension '%s' -- please convert to Extension instancezRfirst element of each tuple in 'ext_modules' must be the extension name (a string)zOsecond element of each tuple in 'ext_modules' must be a dictionary (build info)�sources)r)r-r,� extra_objects�extra_compile_args�extra_link_argsNr.Zdef_filez9'def_file' element of build info dict no longer supported�macros)r8rmz9'macros' element of build info dict must be 1- or 2-tupler8r)rK�list�DistutilsSetupError� enumerater�tuple�lenr �warnrL�extension_name_re�match�dict�get�setattr�runtime_library_dirs� define_macros� undef_macrosrS) r5r$r�ext�ext_nameZ build_info�key�valrrrkrrr�check_extensions_listVsP           zbuild_ext.check_extensions_listcCs0|�|j�g}x|jD]}|�|j�qW|S)N)r�r$rVrn)r5� filenamesr�rrr�get_source_files�s   zbuild_ext.get_source_filescCs6|�|j�g}x |jD]}|�|�|j��qW|S)N)r�r$rS�get_ext_fullpathrW)r5Zoutputsr�rrr� get_outputs�s   zbuild_ext.get_outputscCs(|�|j�|jr|��n|��dS)N)r�r$r4�_build_extensions_parallel�_build_extensions_serial)r5rrrri�s  zbuild_ext.build_extensionsc s��j}�jdkrt��}yddlm}Wntk r@d}YnX|dkrV���dS||d��T���fdd��jD�}x6t�j|�D]&\}}�� |��|� �WdQRXq�WWdQRXdS)NTr)�ThreadPoolExecutor)Z max_workerscsg|]}���j|��qSr)Zsubmit�build_extension)rFr�)�executorr5rrrG�sz8build_ext._build_extensions_parallel..) r4rN� cpu_countZconcurrent.futuresr�� ImportErrorr�r$�zip�_filter_build_errors�result)r5Zworkersr�Zfuturesr�Zfutr)r�r5rr��s       z$build_ext._build_extensions_parallelc Cs4x.|jD]$}|�|��|�|�WdQRXqWdS)N)r$r�r�)r5r�rrrr��s  z"build_ext._build_extensions_serialc csTy dVWnDtttfk rN}z |js*�|�d|j|f�Wdd}~XYnXdS)Nz"building extension "%s" failed: %s)ZCCompilerErrorZDistutilsErrorZ CompileErrorZoptionalrxrW)r5r��errrr��s zbuild_ext._filter_build_errorsc CsT|j}|dkst|ttf�s*td|j��t|�}|�|j�}||j}|jslt ||d�slt � d|j�dSt � d|j�|� ||�}|jp�g}|jdd�}x|jD]}|�|f�q�W|jj||j||j|j ||jd�}|dd�|_|jr�|�|j�|j�pg}|j�p|j�|�} |jj|||�|�|j|j||� |�|j |j| d� dS)Nzjin 'ext_modules' option (extension '%s'), 'sources' must be present and must be a list of source filenamesZnewerz$skipping '%s' extension (up-to-date)zbuilding '%s' extension)Z output_dirrrr)r�extra_postargs�depends)r,r-r~r��export_symbolsrr'Z target_lang)!rnrKrsrvrtrWr�r�rrr r�info� swig_sourcesrprr�rSr0�compiler'r)Z_built_objectsrorVrq�languageZdetect_languageZlink_shared_object� get_librariesr-r~�get_export_symbols) r5r�rn�ext_pathr�Z extra_argsrrr+Zobjectsr�rrrr��sN         zbuild_ext.build_extensioncCs0g}g}i}|jrt�d�|js6d|jks6d|jkr        zbuild_ext.swig_sourcescCs`tjdkrdStjdkrNxBdD]&}tj�d|d�}tj�|�r|SqWdSntdtj��dS) z�Return the name of the SWIG executable. On Unix, this is just "swig" -- it should be in the PATH. Tries a bit harder on Windows. �posixr1r9)z1.3z1.2z1.1z c:\swig%szswig.exez>I don't know how to find (much less run) SWIG on platform '%s'N)rNrWrTrU�isfileZDistutilsPlatformError)r5Zvers�fnrrrr�gs    zbuild_ext.find_swigcCs�|�|�}|�d�}|�|d�}|jsRtjj|dd�|g�}tj�|j|�Sd�|dd��}|�d�}tj� |� |��}tj�||�S)z�Returns the path of the filename for a given extension. The file is located in `build_lib` or directly in the package (inplace option). rBr�Nr�build_py) �get_ext_fullnamerM�get_ext_filenamerrNrTrUr%rh�abspathZget_package_dir)r5r��fullnameZmodpath�filenamer(r�Z package_dirrrrr�s   zbuild_ext.get_ext_fullpathcCs |jdkr|S|jd|SdS)zSReturns the fullname of a given extension name. Adds the `package.` prefixNrB)r()r5r�rrrr��s zbuild_ext.get_ext_fullnamecCs.ddlm}|�d�}|d�}tjj|�|S)z�Convert the name of an extension (eg. "foo.bar") into the name of the file from which it will be loaded (eg. "foo/bar.so", or "foo\bar.pyd"). r)r^rBZ EXT_SUFFIX)�distutils.sysconfigr^rMrNrTrU)r5r�r^r�Z ext_suffixrrrr��s  zbuild_ext.get_ext_filenamecCs0d|j�d�d}||jkr*|j�|�|jS)aReturn the list of symbols that a shared extension has to export. This either uses 'ext.export_symbols' or, if it's not provided, "PyInit_" + module_name. Only relevant on Windows, where the .pyd file (DLL) must export the module "PyInit_" function. ZPyInit_rBr�)rWrMr�rS)r5r�Z initfunc_namerrrr��s  zbuild_ext.get_export_symbolscCs�tjdkrdddlm}t|j|�s\d}|jr4|d}|tjd?tjd?d@f}|j|gS|jSnttjd krt|jStjd d �d kr�|jSdd l m }|� d�r�d� tjd?tjd?d@|� d��}|j|gS|jSd S)z�Return the list of libraries to link against when building a shared extension. On most platforms, this is just 'ext.libraries'; on Windows, we add the Python library (eg. python20.dll). r;r)� MSVCCompilerz python%d%dZ_d�����darwinN�Zaix)r7rCz python{}.{}{}ZABIFLAGS) rPr[Zdistutils._msvccompilerr�rKr0r� hexversionr,rIr7r^�format)r5r�r��templateZ pythonlibr7rrrr��s*         zbuild_ext.get_libraries) �__name__� __module__� __qualname__Z descriptionrNrOZsep_byr Z user_optionsZboolean_optionsr Z help_optionsr6rcrlr�r�r�rir�r�� contextlib�contextmanagerr�r�r�r�r�r�r�r�r�rrrrr!s^  @N  K6   r)�__doc__r�rN�rerPZdistutils.corerZdistutils.errorsr�rrrZdistutils.dep_utilrZdistutils.extensionrZdistutils.utilr rIr Zsiter r�ryr rrrrr�s"