o
    Ëý°j²C  ã                   @   sê   d Z ddlZddlZddlZddlmZmZmZ ddlZddl	Z
ddlmZ ddlmZ ddlmZmZmZmZ ddl	mZ ddlmZ d	d
„ ZG dd„ deƒZG dd„ deƒZdZdZdZdd„ Ze d¡Zdd„ Z dd„ Z!dd„ Z"dS )a  distutils.cygwinccompiler

Provides the CygwinCCompiler class, a subclass of UnixCCompiler that
handles the Cygwin port of the GNU C compiler to Windows.  It also contains
the Mingw32CCompiler class which handles the mingw32 port of GCC (same as
cygwin in no-cygwin mode).
é    N)ÚPopenÚPIPEÚcheck_output)ÚUnixCCompiler)Ú
write_file)ÚDistutilsExecErrorÚCCompilerErrorÚCompileErrorÚUnknownFileError)ÚLooseVersion)Úfind_executablec                  C   s¼   t j d¡} | dkr\t j| d | d … }|dkrdgS |dkr#dgS |d	kr*d
gS |dkr1dgS |dkr8dgS |dkr?dgS |dkrFdgS dt|ƒ  krUdk rVddgS  td| ƒ‚dS )zaInclude the appropriate MSVC runtime library if Python was built
    with MSVC 7.0 or later.
    zMSC v.éÿÿÿÿé   é
   Ú1300Úmsvcr70Ú1310Úmsvcr71Ú1400Úmsvcr80Ú1500Úmsvcr90Ú1600Úmsvcr100Ú1700Úmsvcr110Ú1800Úmsvcr120il  iÐ  ÚucrtÚvcruntime140zUnknown MS Compiler version %s N)ÚsysÚversionÚfindÚintÚ
ValueError)Úmsc_posÚmsc_ver© r'   ú˜/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/setuptools/_distutils/cygwinccompiler.pyÚ	get_msvcr@   s,   þår)   c                   @   sZ   e Zd ZdZdZdZdZdZdZdZ	dZ
dd
d„Zdd„ Z				ddd„Zddd„ZdS )ÚCygwinCCompilerz? Handles the Cygwin port of the GNU C compiler to Windows.
    Úcygwinz.oú.az.dllzlib%s%sz%s%sz.exer   c                 C   sF  t  | |||¡ tƒ \}}|  d||f ¡ |tur!|  d| ¡ tj dd¡| _	tj dd¡| _
d| j	v rgtƒ \| _| _| _|  | jd| j| j| jf  ¡ | jdkrY| j	| _nd	| _| jd
krdd}n	d}n| j	| _d}| jd| j	 d| j	 d| j
 d| j	 d| j|f d� d| j	v r�| jdkr�dg| _|  d¡ d S tƒ | _d S )Nz%Python's GCC status: %s (details: %s)zƒPython's pyconfig.h doesn't seem to support your compiler. Reason: %s. Compiling may fail because of undefined preprocessor macros.ÚCCÚgccÚCXXzg++z: gcc %s, ld %s, dllwrap %s
z2.10.90Údllwrapú2.13ú-sharedú-mdll -staticz%s -mcygwin -O -Wallz%s -mcygwin -mdll -O -Wallz%s -mcygwinz%s -mcygwin %s©ÚcompilerÚcompiler_soÚcompiler_cxxÚ
linker_exeÚ	linker_soú2.91.57Úmsvcrtz,Consider upgrading to a newer version of gcc)r   Ú__init__Úcheck_config_hÚdebug_printÚCONFIG_H_OKÚwarnÚosÚenvironÚgetÚccÚcxxÚget_versionsÚgcc_versionÚ
ld_versionÚdllwrap_versionÚcompiler_typeÚ
linker_dllÚset_executablesÚdll_librariesr)   )ÚselfÚverboseÚdry_runÚforceÚstatusÚdetailsÚshared_optionr'   r'   r(   r<   n   sX   
ÿýÿ
ÿ
þÿ



ÿüÿzCygwinCCompiler.__init__c              
   C   s’   |dks|dkr&z|   dd|d|g¡ W dS  ty% } zt|ƒ‚d}~ww z|   | j| |d|g | ¡ W dS  tyH } zt|ƒ‚d}~ww )z:Compiles the source by spawning GCC and windres if needed.ú.rcú.resÚwindresz-iz-oN)Úspawnr   r	   r6   )rN   ÚobjÚsrcÚextÚcc_argsÚextra_postargsÚpp_optsÚmsgr'   r'   r(   Ú_compile®   s   €ÿÿ€ÿzCygwinCCompiler._compileNc                 C   sH  t   |
pg ¡}
t   |pg ¡}t   |pg ¡}| | j¡ |dur‰|| jks)| jdkr‰tj |d ¡}tj tj 	|¡¡\}}tj 
||d ¡}tj 
|d| d ¡}dtj 	|¡ dg}|D ]}| |¡ q]|  t||fd	| ¡ | jd
kr„|
 d|g¡ |
 d|g¡ n| |¡ |	s�|
 d¡ t | |||||||d|	|
|||¡ dS )zLink the objects.Nr.   r   z.defÚlibr,   z
LIBRARY %sÚEXPORTSz
writing %sr0   z--output-libz--defz-s)ÚcopyÚextendrM   Ú
EXECUTABLErK   rA   ÚpathÚdirnameÚsplitextÚbasenameÚjoinÚappendÚexecuter   r   Úlink)rN   Útarget_descÚobjectsÚoutput_filenameÚ
output_dirÚ	librariesÚlibrary_dirsÚruntime_library_dirsÚexport_symbolsÚdebugÚextra_preargsr]   Ú
build_tempÚtarget_langÚtemp_dirÚdll_nameÚdll_extensionÚdef_fileÚlib_fileÚcontentsÚsymr'   r'   r(   rm   ½   sB   	
ÿþÿ


ûzCygwinCCompiler.linkÚ c                 C   sª   |du rd}g }|D ]H}t j t j |¡¡\}}|| jddg vr)td||f ƒ‚|r1t j |¡}|dv rE| t j ||| | j	 ¡¡ q
| t j ||| j	 ¡¡ q
|S )z#Adds supports for rc and res files.Nr�   rU   rV   z"unknown file type '%s' (from '%s'))rV   rU   )
rA   rf   rh   ÚnormcaseÚsrc_extensionsr
   ri   rk   rj   Úobj_extension)rN   Úsource_filenamesÚ	strip_dirrq   Ú	obj_namesÚsrc_nameÚbaser[   r'   r'   r(   Úobject_filenames  s&   ÿÿÿz CygwinCCompiler.object_filenames©r   r   r   )
NNNNNr   NNNN)r   r�   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rJ   r„   Ústatic_lib_extensionÚshared_lib_extensionÚstatic_lib_formatÚshared_lib_formatÚexe_extensionr<   r`   rm   rŠ   r'   r'   r'   r(   r*   c   s"    
@
ýNr*   c                   @   s   e Zd ZdZdZddd„ZdS )ÚMingw32CCompilerz@ Handles the Mingw32 port of the GNU C compiler to Windows.
    Úmingw32r   c              	   C   s¨   t  | |||¡ d| jv r| jdk rd}nd}d| jv r$| jdkr$d}nd}t| jƒr/tdƒ‚| jd	| j d
| j d	| j d| j d| j	||f d� g | _
tƒ | _
d S )Nr.   r1   r3   r2   r:   z--entry _DllMain@12r�   z1Cygwin gcc cannot be used with --compiler=mingw32z%s -O -Wallz%s -mdll -O -Wallz%sz%s %s %sr4   )r*   r<   rD   rH   rG   Úis_cygwinccr   rL   rE   rK   rM   r)   )rN   rO   rP   rQ   rT   Úentry_pointr'   r'   r(   r<   '  s.   
ÿÿÿüzMingw32CCompiler.__init__Nr‹   )rŒ   r�   rŽ   r�   rJ   r<   r'   r'   r'   r(   r•   "  s    r•   Úokznot okÚ	uncertainc               
   C   sÀ   ddl m}  dtjv rtdfS dtjv rtdfS |  ¡ }z(t|ƒ}zd| ¡ v r4td| fW | ¡  W S t	d	| fW | ¡  W S | ¡  w  t
y_ } ztd
||jf fW  Y d}~S d}~ww )aw  Check if the current Python installation appears amenable to building
    extensions with GCC.

    Returns a tuple (status, details), where 'status' is one of the following
    constants:

    - CONFIG_H_OK: all is well, go ahead and compile
    - CONFIG_H_NOTOK: doesn't look good
    - CONFIG_H_UNCERTAIN: not sure -- unable to read pyconfig.h

    'details' is a human-readable string explaining the situation.

    Note there are two ways to conclude "OK": either 'sys.version' contains
    the string "GCC" (implying that this Python was built with GCC), or the
    installed "pyconfig.h" contains the string "__GNUC__".
    r   )Ú	sysconfigÚGCCzsys.version mentions 'GCC'ÚClangzsys.version mentions 'Clang'Ú__GNUC__z'%s' mentions '__GNUC__'z '%s' does not mention '__GNUC__'zcouldn't read '%s': %sN)Ú	distutilsr›   r    r!   r?   Úget_config_h_filenameÚopenÚreadÚcloseÚCONFIG_H_NOTOKÚOSErrorÚCONFIG_H_UNCERTAINÚstrerror)r›   ÚfnÚconfig_hÚexcr'   r'   r(   r=   W  s(   

þÿ€ÿr=   s   (\d+\.\d+(\.\d+)*)c                 C   s¦   |   ¡ d }t|ƒdu rdS t| dtd�j}z
| ¡ }W | ¡  n| ¡  w t |¡}|du r1dS | 	d¡ 
¡ }tj ¡ � t|ƒW  d  ƒ S 1 sLw   Y  dS )z¤Find the version of an executable by running `cmd` in the shell.

    If the command is not found, or the output does not match
    `RE_VERSION`, returns None.
    r   NT)ÚshellÚstdouté   )Úsplitr   r   r   r¬   r¢   r£   Ú
RE_VERSIONÚsearchÚgroupÚdecoderŸ   r!   Úsuppress_known_deprecationr   )ÚcmdÚ
executableÚoutÚ
out_stringÚresultÚver_strr'   r'   r(   Ú_find_exe_versionˆ  s   

$ÿrº   c                  C   s   g d¢} t dd„ | D ƒƒS )zg Try to find out the versions of gcc, ld and dllwrap.

    If not possible it returns None for it.
    )zgcc -dumpversionzld -vzdllwrap --versionc                 S   s   g | ]}t |ƒ‘qS r'   )rº   )Ú.0r´   r'   r'   r(   Ú
<listcomp>¤  s    z get_versions.<locals>.<listcomp>)Útuple)Úcommandsr'   r'   r(   rF   ž  s   rF   c                 C   s   t | dgƒ}| ¡  d¡S )zCTry to determine if the compiler that would be used is from cygwin.z-dumpmachines   cygwin)r   ÚstripÚendswith)rD   r·   r'   r'   r(   r—   ¦  s   r—   )#r�   rA   r    rc   Ú
subprocessr   r   r   ÚreÚdistutils.versionrŸ   Údistutils.unixccompilerr   Údistutils.file_utilr   Údistutils.errorsr   r   r	   r
   r   Údistutils.spawnr   r)   r*   r•   r?   r¤   r¦   r=   Úcompiler¯   rº   rF   r—   r'   r'   r'   r(   Ú<module>   s0    1# @1
/