509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3

  \þz  ã               @   s¶   d Z ddlZddlZddlZddlZddlmZ ddlT ddlm	Z	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ejdƒZdd„ ZG dd„ deƒZdS )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]*)*$c              C   s   ddl m}  | ƒ  d S )Nr   )Úshow_compilers)Údistutils.ccompilerr   )r   © r   ú3/usr/lib64/python3.6/distutils/command/build_ext.pyr      s    r   c               @   s  e Zd ZdZdej Zd`dad	d
deƒ  fdcddde fdddedfddde fdgdhdidjdkdldmdndodpgZdd%d(d1d8gZ	d:d2d;e
fgZd<d=„ Zd>d?„ Zd@dA„ ZdBdC„ ZdDdE„ ZdFdG„ ZdHdI„ ZdJdK„ ZdLdM„ ZejdNdO„ ƒZdPdQ„ ZdRdS„ ZdTdU„ ZdVdW„ ZdXdY„ ZdZd[„ Zd\d]„ Zd^d_„ Zd2S )qÚ	build_extz8build C/C++ extensions (compile/link to build directory)z (separated by '%s')ú
build-lib=Úbú(directory for compiled extension modulesúbuild-temp=Útú1directory for temporary files (build by-products)z
plat-name=Úpz>platform name to cross-compile for, if supported (default: %s)ÚinplaceÚiz=ignore build-lib and put compiled extensions into the source z,directory alongside your pure Python moduleszinclude-dirs=ÚIz.list of directories to search for header filesúdefine=ÚDúC preprocessor macros to defineúundef=ÚUú!C preprocessor macros to undefineú
libraries=Úlú!external C libraries to link withzlibrary-dirs=ÚLz.directories to search for external C librariesúrpath=ÚRú7directories to search for shared C libraries at runtimeúlink-objects=ÚOú2extra explicit link objects to include in the linkÚdebugÚgú'compile/link with debugging informationÚforceÚfú2forcibly build everything (ignore file timestamps)ú	compiler=Úcúspecify the compiler typeú	parallel=Újúnumber of parallel build jobsúswig-cppNú)make SWIG create C++ files (default is C)ú
swig-opts=ú!list of SWIG command line optionsúswig=úpath to the SWIG executableÚuserú#add user include, library and rpathzhelp-compilerzlist available compilersc             C   s‚   d | _ d | _d | _d | _d| _d | _d | _d | _d | _d | _	d | _
d | _d | _d | _d | _d | _d | _d | _d | _d | _d | _d S )Nr   )Ú
extensionsÚ	build_libÚ	plat_nameÚ
build_tempr   ÚpackageÚinclude_dirsÚdefineÚundefÚ	librariesÚlibrary_dirsÚrpathÚlink_objectsr+   r.   ÚcompilerÚswigÚswig_cppÚ	swig_optsr=   Úparallel)Úselfr   r   r   Úinitialize_optionsj   s*    zbuild_ext.initialize_optionsc       
      C   sü  ddl m} | jdd'd(d)d*d+d,d-ƒ | jd kr8| jj| _| jj| _|jƒ }|jdd�}| j	d krn| jj	pjg | _	t
| j	tƒrŠ| j	jtjƒ| _	tjtjkr®| j	jtjjtjdƒƒ | j	j|ƒ ||krÎ| j	j|ƒ | jdƒ | jdƒ | jd k� rôg | _| jd k�rg | _nt
| jtƒ�r&| jjtjƒ| _| jd k�r:g | _nt
| jtƒ�rX| jjtjƒ| _tjdk�rT| jjtjjtjdƒƒ tjtjk�r¢| jjtjjtjdƒƒ | j�r¾tjj| jdƒ| _ntjj| jdƒ| _| j	jtjjtƒ ƒƒ ttdd ƒ}|�r| jj|ƒ | j dk�rd}n| j dd … }tjjtjdƒ}|�rHtjj||ƒ}| jj|ƒ tj!d d… dk�s|tj!d d… dk�rÆtj"j#tjjtjdƒƒ�rº| jjtjjtjddt$ƒ  dƒƒ n| jjdƒ |j%d ƒ�rú|j&�sî| jj|j%d!ƒƒ n| jjdƒ | j'�r| j'jd"ƒ}d#d$„ |D ƒ| _'| j(�r4| j(jd"ƒ| _(| j)d k�rHg | _)n| j)jd%ƒ| _)| j*�rºtjjt+dƒ}tjjt+dƒ}	tjj,|ƒ�r”| j	j|ƒ tjj,|	ƒ�rº| jj|	ƒ | jj|	ƒ t
| j-tƒ�røyt.| j-ƒ| _-W n t/k
�rö   t0d&ƒ‚Y nX d S ).Nr   )Ú	sysconfigZbuildr@   rB   rK   r+   r.   rO   rA   é   )Zplat_specificÚincluderG   rJ   ÚntZlibsZDebugZReleaseÚ_homeÚwin32é   ZPCbuildé   ÚcygwinÚatheosÚbinÚlibÚpythonÚconfigÚ.ÚPy_ENABLE_SHAREDÚLIBDIRú,c             S   s   g | ]}|d f‘qS )Ú1r   )Ú.0Zsymbolr   r   r   ú
<listcomp>ø   s    z.build_ext.finalize_options.<locals>.<listcomp>ú zparallel should be an integer)r@   r@   )rB   rB   )rK   rK   )r+   r+   )r.   r.   )rO   rO   )rA   rA   )1Ú	distutilsrR   Zset_undefined_optionsrC   ÚdistributionZext_packageZext_modulesr?   Zget_python_incrD   Ú
isinstanceÚstrÚsplitÚosÚpathsepÚsysÚexec_prefixÚbase_exec_prefixÚappendÚpathÚjoinZensure_string_listrG   rH   rI   ÚnameÚprefixr+   rB   Údirnamer   ÚgetattrrA   ÚplatformÚ
executableÚ
startswithr   Úget_config_varZpython_buildrE   rF   rN   r=   r   ÚisdirrO   ÚintÚ
ValueErrorZDistutilsOptionError)
rP   rR   Z
py_includeZplat_py_includeÚ	_sys_homeÚsuffixZnew_libZdefinesZuser_includeZuser_libr   r   r   Úfinalize_options‚   s¨    





(
zbuild_ext.finalize_optionsc             C   st  ddl m} | jsd S | jjƒ rL| jdƒ}| jj|jƒ p:g ƒ | j	j
|jƒ || j| j| j| jd�| _t| jƒ tjdkr”| jtƒ kr”| jj| jƒ | jd k	r¬| jj| jƒ | jd k	rØx | jD ]\}}| jj||ƒ q¾W | jd k	�r x| jD ]}| jj|ƒ qìW | jd k	�r| jj| jƒ | j	d k	�r4| jj| j	ƒ | jd k	�rN| jj| jƒ | j d k	�rh| jj!| j ƒ | j"ƒ  d S )Nr   )Únew_compilerÚ
build_clib)rK   ÚverboseÚdry_runr.   rU   )#r   rƒ   r?   ri   Zhas_c_librariesÚget_finalized_commandrG   ÚextendZget_library_namesrH   rr   r„   rK   r…   r†   r.   r   rm   ru   rA   r	   Z
initializerD   Zset_include_dirsrE   Zdefine_macrorF   Zundefine_macroZset_librariesZset_library_dirsrI   Zset_runtime_library_dirsrJ   Zset_link_objectsÚbuild_extensions)rP   rƒ   r„   ru   ÚvalueÚmacror   r   r   Úrun  s>    




zbuild_ext.runc       
      C   sˆ  t |tƒstdƒ‚�xnt|ƒD �]`\}}t |tƒr4qt |tƒ sLt|ƒdkrTtdƒ‚|\}}tjd|ƒ t |t	ƒozt
j|ƒs„tdƒ‚t |tƒs–tdƒ‚t||d ƒ}x*dD ]"}|j|ƒ}|dk	rªt|||ƒ qªW |jdƒ|_d|k� rðtjdƒ |jdƒ}|�rxg |_g |_xj|D ]b}	t |	tƒ�o,t|	ƒdk�s8tdƒ‚t|	ƒdk�rX|jj|	d ƒ nt|	ƒdk�r|jj|	ƒ �qW |||< qW d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)ÚsourcesrD   rH   rG   Úextra_objectsÚextra_compile_argsÚextra_link_argsNrI   Zdef_filez9'def_file' element of build info dict no longer supportedÚmacrosrS   z9'macros' element of build info dict must be 1- or 2-tupler   )rD   rH   rG   r�   r�   r‘   )rS   r�   )rj   ÚlistÚDistutilsSetupErrorÚ	enumerater   ÚtupleÚlenr
   Úwarnrk   Úextension_name_reÚmatchÚdictÚgetÚsetattrÚruntime_library_dirsÚdefine_macrosÚundef_macrosrr   )
rP   r?   r   ÚextÚext_nameZ
build_infoÚkeyÚvalr’   r‹   r   r   r   Úcheck_extensions_listU  sT    





 




zbuild_ext.check_extensions_listc             C   s0   | j | jƒ g }x| jD ]}|j|jƒ qW |S )N)r¥   r?   rˆ   rŽ   )rP   Ú	filenamesr¡   r   r   r   Úget_source_files£  s
    zbuild_ext.get_source_filesc             C   s6   | j | jƒ g }x | jD ]}|j| j|jƒƒ qW |S )N)r¥   r?   rr   Úget_ext_fullpathru   )rP   Zoutputsr¡   r   r   r   Úget_outputs¬  s
    zbuild_ext.get_outputsc             C   s(   | j | jƒ | jr| jƒ  n| jƒ  d S )N)r¥   r?   rO   Ú_build_extensions_parallelÚ_build_extensions_serial)rP   r   r   r   r‰   º  s    
zbuild_ext.build_extensionsc                s¾   ˆj }ˆj dkrtjƒ }yddlm} W n tk
r@   d }Y nX |d krVˆjƒ  d S ||d��T‰ ‡ ‡fdd„ˆjD ƒ}x6tˆj|ƒD ]&\}}ˆj	|ƒ� |j
ƒ  W d Q R X q†W W d Q R X d S )NTr   )ÚThreadPoolExecutor)Zmax_workersc                s   g | ]}ˆ j ˆj|ƒ‘qS r   )ZsubmitÚbuild_extension)re   r¡   )ÚexecutorrP   r   r   rf   Ð  s   z8build_ext._build_extensions_parallel.<locals>.<listcomp>)rO   rm   Ú	cpu_countZconcurrent.futuresr¬   ÚImportErrorr«   r?   ÚzipÚ_filter_build_errorsÚresult)rP   Zworkersr¬   Zfuturesr¡   Zfutr   )r®   rP   r   rª   Â  s     


z$build_ext._build_extensions_parallelc          
   C   s4   x.| j D ]$}| j|ƒ� | j|ƒ W d Q R X qW d S )N)r?   r²   r­   )rP   r¡   r   r   r   r«   Ö  s    z"build_ext._build_extensions_serialc             c   sT   y
d V  W nD t ttfk
rN } z"|js*‚ | jd|j|f ƒ W Y d d }~X nX d S )Nz"building extension "%s" failed: %s)ZCCompilerErrorZDistutilsErrorZCompileErrorZoptionalr˜   ru   )rP   r¡   Úer   r   r   r²   Û  s    
zbuild_ext._filter_build_errorsc       
      C   sX  |j }|d kst|ttfƒ r,td|j ƒ‚t|ƒ}| j|jƒ}||j }| jpZt	||dƒsnt
jd|jƒ d S t
jd|jƒ | j||ƒ}|jp�g }|jd d … }x|jD ]}|j|fƒ q¨W | jj|| j||j| j||jd�}|d d … | _|j�r |j|jƒ |j�p
g }|j�p| jj|ƒ}	| jj||| j|ƒ|j|j|| j |ƒ| j| j|	d�
 d S )Nzjin 'ext_modules' option (extension '%s'), 'sources' must be present and must be a list of source filenamesZnewerz$skipping '%s' extension (up-to-date)zbuilding '%s' extension)Z
output_dirr’   rD   r+   Úextra_postargsÚdepends)rG   rH   rž   rµ   Úexport_symbolsr+   rB   Ztarget_lang)!rŽ   rj   r“   r–   r”   ru   r¨   r¶   r.   r   r
   r+   ÚinfoÚswig_sourcesr�   rŸ   r    rr   rK   ÚcompilerB   rD   Z_built_objectsr�   rˆ   r‘   ÚlanguageZdetect_languageZlink_shared_objectÚget_librariesrH   rž   Úget_export_symbols)
rP   r¡   rŽ   Úext_pathr¶   Z
extra_argsr’   rF   Zobjectsr»   r   r   r   r­   å  sN    



zbuild_ext.build_extensionc             C   s2  g }g }i }| j rtjdƒ | j s6d| jks6d|jkr<d}nd}xX|D ]P}tjj|ƒ\}}	|	dkrŒ|j|d | ƒ |j|ƒ |d ||< qF|j|ƒ qFW |s¢|S | jp®| j	ƒ }
|
dg}|j
| jƒ | j rÔ|jdƒ | jsôx|jD ]}|j|ƒ qâW x8|D ]0}|| }tjd	||ƒ | j|d
||g ƒ � qúW |S )züWalk the list of source files in 'sources', looking for SWIG
        interface (.i) files.  Run SWIG on all that are found, and
        return a modified 'sources' list with SWIG source files replaced
        by the generated C (or C++) files.
        z/--swig-cpp is deprecated - use --swig-opts=-c++z-c++z.cppz.cz.iÚ_wraprS   z-pythonzswigging %s to %sz-oéÿÿÿÿ)rM   r
   r˜   rN   rm   rs   Úsplitextrr   rL   Ú	find_swigrˆ   r¸   Zspawn)rP   rŽ   Ú	extensionZnew_sourcesr¹   Zswig_targetsZ
target_extÚsourceÚbaser¡   rL   Zswig_cmdÚoÚtargetr   r   r   r¹   0  s>    





zbuild_ext.swig_sourcesc             C   s`   t jdkrdS t jdkrNxBdD ]&}t jjd| dƒ}t jj|ƒr|S qW dS ntd	t j ƒ‚d
S )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.
        ÚposixrL   rU   ú1.3ú1.2ú1.1z	c:\swig%szswig.exez>I don't know how to find (much less run) SWIG on platform '%s'N)rÉ   rÊ   rË   )rm   ru   rs   rt   ÚisfileZDistutilsPlatformError)rP   ZversÚfnr   r   r   rÂ   f  s    


zbuild_ext.find_swigc             C   sŽ   | j |ƒ}|jdƒ}| j|d ƒ}| jsRtjj|dd… |g Ž }tjj| j|ƒS dj|dd… ƒ}| jdƒ}tjj	|j
|ƒƒ}tjj||ƒ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).
        r`   rS   Nr   Úbuild_pyrÀ   rÀ   rÀ   )Úget_ext_fullnamerl   Úget_ext_filenamer   rm   rs   rt   r@   r‡   ÚabspathZget_package_dir)rP   r¢   ÚfullnameZmodpathÚfilenamerC   rÎ   Zpackage_dirr   r   r   r¨   ~  s    


zbuild_ext.get_ext_fullpathc             C   s    | j dkr|S | j d | S dS )zSReturns the fullname of a given extension name.

        Adds the `package.` prefixNr`   )rC   )rP   r¢   r   r   r   rÏ   ™  s    
zbuild_ext.get_ext_fullnamec             C   s.   ddl m} |jdƒ}|dƒ}tjj|Ž | 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|   r`   Ú
EXT_SUFFIX)Údistutils.sysconfigr|   rl   rm   rs   rt   )rP   r¢   r|   r¾   Z
ext_suffixr   r   r   rÐ   ¢  s    
zbuild_ext.get_ext_filenamec             C   s0   d|j jdƒd  }||jkr*|jj|ƒ |jS )a  Return 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.
        ZPyInit_r`   rS   rÀ   )ru   rl   r·   rr   )rP   r¡   Zinitfunc_namer   r   r   r½   ¬  s    
zbuild_ext.get_export_symbolsc             C   s¼  t jdkrfddlm} t| j|ƒs\d}| jr4|d }|t jd? t jd? d@ f }|j|g S |jS �nRt jd	d
… dkr¤d}|t jd? t jd? d@ f }|j|g S t jd	d
… dk�r>ddl	m
} d}|t jd? t jd? d@ f }g }xB|jdƒjƒ D ]0}|jdƒ�r|j|dd	… ƒ n
|j|ƒ � qøW |j|dg | S t jdk�rP|jS t jd	d… dk�rj|jS ddl	m
} |jdƒ�r²djt jd? t jd? d@ |jdƒƒ}|j|g S |jS d	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).
        rW   r   )ÚMSVCCompilerz
python%d%dZ_dé   é   éÿ   NrY   rZ   zpython%d.%dr[   )rR   ÚSHLIBSz-lr�   ÚmÚdarwiné   Úaixra   zpython{}.{}{}ÚABIFLAGS)ro   ry   Zdistutils._msvccompilerrÖ   rj   rK   r+   Ú
hexversionrG   rh   rR   r|   rl   r{   rr   Úformat)rP   r¡   rÖ   ÚtemplateZ	pythonlibrR   Zextrar]   r   r   r   r¼   ·  sJ    


zbuild_ext.get_libraries)r   r   r   )r   r   r   úiignore build-lib and put compiled extensions into the source directory alongside your pure Python modules)r   r   rã   )r   r   r   )r   r   r    )r!   r"   r#   )r%   r&   r'   )r(   r)   r*   )r+   r,   r-   )r.   r/   r0   )r1   r2   r3   )r4   r5   r6   )r7   Nr8   )r9   Nr:   )r;   Nr<   )r=   Nr>   ) Ú__name__Ú
__module__Ú__qualname__Zdescriptionrm   rn   Zsep_byr	   Zuser_optionsZboolean_optionsr   Zhelp_optionsrQ   r‚   rŒ   r¥   r§   r©   r‰   rª   r«   Ú
contextlibÚcontextmanagerr²   r­   r¹   rÂ   r¨   rÏ   rÐ   r½   r¼   r   r   r   r   r   !   s€   
                 
 @N	
K6	
r   )Ú__doc__rç   rm   Úrero   Zdistutils.corer   Zdistutils.errorsrÕ   r   r   r   Zdistutils.dep_utilr   Zdistutils.extensionr   Zdistutils.utilr	   rh   r
   Zsiter   rº   r™   r   r   r   r   r   r   Ú<module>   s"   