o
    ugC                     @   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'   g/var/www/html/ecg_monitoring/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rdg| _| d d S t | _d S )Nz%Python's GCC status: %s (details: %s)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++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rt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 )zFind 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
/