o
    JAf.                     @   s  d Z ddlZddl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	m
Z
 ddlmZ ddlmZmZmZmZ ddlmZmZ dd	lmZ ed
gdgdgdgdgdgdgdgejd	Zdd ZdZG dd de
ZG dd deZdZdZdZ dd Z!dd  Z"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)check_output   )UnixCCompiler)
write_file)DistutilsExecErrorDistutilsPlatformErrorCCompilerErrorCompileError)LooseVersionsuppress_known_deprecation)RangeMapZmsvcr70Zmsvcr71Zmsvcr80Zmsvcr90Zmsvcr100Zmsvcr110Zmsvcr120Zvcruntime140)	i  i  ix  i  i@  i  i  il  i  c                  C   s\   t dtj} z	t| d}W n
 ty   Y dS w zt| W S  ty-   t	d| w )zaInclude the appropriate MSVC runtime library if Python was built
    with MSVC 7.0 or later.
    zMSC v\.(\d{4})r   NzUnknown MS Compiler version %s )
researchsysversionintgroupAttributeError_msvcr_lookupKeyError
ValueError)matchZmsc_ver r   g/usr/lib/python3.10/site-packages/setuptools-67.5.1-py3.10.egg/setuptools/_distutils/cygwinccompiler.py	get_msvcr4   s   
r   zxUnable to set runtime library search path on Windows, usually indicated by `runtime_library_dirs` parameter to Extensionc                       s   e Zd ZdZdZdZdZdZdZdZ	dZ
dZd	Zd fdd	Zedd Zdd Z						
				dddZdd Z fddZe fddZ  ZS )CygwinCCompilerz9Handles the Cygwin port of the GNU C compiler to Windows.cygwinz.oz.az.dll.az.dllzlib%s%szcyg%s%sz.exer   c              	      s   t  ||| t \}}| d|| |tur!| d|  tj	dd| _
tj	dd| _| j
| _d}| jd| j
 d	| j
 d| j d
| j
 d| j|d t | _d S )Nz%Python's GCC status: {} (details: {})zPython's pyconfig.h doesn't seem to support your compiler. Reason: %s. Compiling may fail because of undefined preprocessor macros.CCgccCXXzg++-sharedz%s -mcygwin -O -Wallz%s -mcygwin -mdll -O -Wallz%s -mcygwinz{} -mcygwin {}compilercompiler_socompiler_cxx
linker_exe	linker_so)super__init__check_config_hdebug_printformatCONFIG_H_OKwarnosenvirongetcccxx
linker_dllset_executablesr   dll_libraries)selfverbosedry_runforcestatusdetailsshared_option	__class__r   r   r(   V   s.   


zCygwinCCompiler.__init__c                 C   sB   t jdtdd t  tdW  d    S 1 sw   Y  d S )Nzgcc_version attribute of CygwinCCompiler is deprecated. Instead of returning actual gcc version a fixed value 11.2.0 is returned.   )
stacklevelz11.2.0)warningsr-   DeprecationWarningr   r
   r6   r   r   r   gcc_versionv   s   $zCygwinCCompiler.gcc_versionc              
   C   s   |dv r"z|  dd|d|g W dS  ty! } zt|d}~ww z|  | j| |d|g |  W dS  tyD } zt|d}~ww )z:Compiles the source by spawning GCC and windres if needed.).rc.resZwindresz-iz-oN)spawnr   r	   r#   )r6   objsrcextZcc_argsextra_postargsZpp_optsmsgr   r   r   _compile   s   
zCygwinCCompiler._compileNc                 C   s  t  |
pg }
t  |pg }t  |pg }|r| t || j |durq|| jks0| jdkrqtj	|d }tj
tj|\}}tj||d }dtj| dg}|D ]}|| qY| t||fd|  || |	sx|
d t| |||||||d|	|
||| dS )	zLink the objects.Nr   r   z.defz
LIBRARY %sZEXPORTSz
writing %sz-s)copyr-   _runtime_library_dirs_msgextendr5   Z
EXECUTABLEr3   r.   pathdirnamesplitextbasenamejoinappendexecuter   r   link)r6   Ztarget_descobjectsZoutput_filename
output_dir	librarieslibrary_dirsruntime_library_dirsexport_symbolsdebugZextra_preargsrK   
build_tempZtarget_langtemp_dirZdll_nameZdll_extensionZdef_filecontentssymr   r   r   rX      sH   




zCygwinCCompiler.linkc                 C   s   |  t g S N)r-   rO   r6   dirr   r   r   runtime_library_dir_option   s   
z*CygwinCCompiler.runtime_library_dir_optionc                    s   t j|}t |||S rd   )r.   rQ   normcaser'   _make_out_path)r6   rZ   Z	strip_dirsrc_nameZnorm_src_namer=   r   r   ri      s   zCygwinCCompiler._make_out_pathc                    s   i t  j fdddD S )z3
        Add support for rc and res files.
        c                    s   i | ]}|| j  qS r   )obj_extension).0rJ   rC   r   r   
<dictcomp>  s    z2CygwinCCompiler.out_extensions.<locals>.<dictcomp>)rF   rE   )r'   out_extensionsrC   r=   rC   r   rn      s
   zCygwinCCompiler.out_extensionsr   r   r   )
NNNNNr   NNNN)__name__
__module____qualname____doc__compiler_typerk   Zstatic_lib_extensionshared_lib_extensionZdylib_lib_extensionZstatic_lib_formatZshared_lib_formatZdylib_lib_formatZexe_extensionr(   propertyrD   rM   rX   rg   ri   rn   __classcell__r   r   r=   r   r   I   s<     

Z	r   c                       s.   e Zd ZdZdZd fdd	Zdd Z  ZS )	Mingw32CCompilerz:Handles the Mingw32 port of the GNU C compiler to Windows.Zmingw32r   c              	      s`   t  ||| d}t| jrtd| jd| j d| j d| j d| j d| j|d d S )Nr    z1Cygwin gcc cannot be used with --compiler=mingw32z%s -O -Wallz%s -mdll -O -Wallz%sz{} {}r!   )	r'   r(   is_cygwinccr1   r   r4   r2   r+   r3   )r6   r7   r8   r9   r<   r=   r   r   r(     s   

zMingw32CCompiler.__init__c                 C   s   t trd   )r   rO   re   r   r   r   rg     s   z+Mingw32CCompiler.runtime_library_dir_optionro   )rp   rq   rr   rs   rt   r(   rg   rw   r   r   r=   r   rx   	  s
    rx   okznot okZ	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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   )	sysconfigZGCCzsys.version mentions 'GCC'ZClangzsys.version mentions 'Clang'Z__GNUC__z'%s' mentions '__GNUC__'z '%s' does not mention '__GNUC__'zcouldn't read '{}': {}N)	distutilsr{   r   r   r,   get_config_h_filenameopenreadcloseCONFIG_H_NOTOKOSErrorCONFIG_H_UNCERTAINr+   strerror)r{   fnconfig_hexcr   r   r   r)   +  s$   

r)   c                 C   s"   t t| dg }| dS )zCTry to determine if the compiler that would be used is from cygwin.z-dumpmachines   cygwin)r   shlexsplitstripendswith)r1   Z
out_stringr   r   r   ry   Z  s   ry   )$rs   r.   r   r   rN   r   rA   
subprocessr   Zunixccompilerr   	file_utilr   errorsr   r   r   r	   r   r
   r   _collectionsr   leftundefined_valuer   r   rO   r   rx   r,   r   r   r)   ry   Zget_versionsr   r   r   r   <module>   sL     A/