o
    wi.                     @   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
mZ ddlmZ ddlmZ ddlmZmZ d	d
lmZ d	dl	mZmZ dd ZdZG dd dej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   )DistutilsExecErrorDistutilsPlatformError)
write_file)get_config_vars)LooseVersionsuppress_known_deprecation   )unix)CompileErrorErrorc                   C   s   g S )z6No longer needed, but kept for backward compatibility. r   r   r   e/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/setuptools/_distutils/compilers/C/cygwin.py	get_msvcr   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 fdd	Zdd Z fddZe fddZ  ZS )Compilerz9Handles the Cygwin port of the GNU C compiler to Windows.cygwinz.oz.az.dll.az.dllzlib%s%szcyg%s%sz.exeFc                    s  t  j||d t \}}| d| d| d |tur&| d| d tdd\| _| _t	j
d| jp7d	| _t	j
d| jpBd
| _| j| _| j| _d}| j| j d| j d| j d| j d| j d| j d| | j d| j d| d t | _d S )N)forcezPython's GCC status: z (details: )zCPython's pyconfig.h doesn't seem to support your compiler. Reason: z>. Compiling may fail because of undefined preprocessor macros.CCCXXgcczg++-sharedz -mcygwin -O -Wallz -mcygwin -mdll -O -Wallz	 -mcygwinz
 -mcygwin )compilercompiler_socompiler_cxxcompiler_so_cxx
linker_exe	linker_solinker_exe_cxxlinker_so_cxx)super__init__check_config_hdebug_printCONFIG_H_OKwarnr   cccxxosenvironget
linker_dlllinker_dll_cxxset_executablesr   dll_libraries)selfverboser   statusdetailsshared_option	__class__r   r   r"   7   s4   






zCompiler.__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   r0   r   r   r   gcc_version[   s   $zCompiler.gcc_versionc              
   C   s   |dv r"z|  dd|d|g W dS  ty! } zt|d}~ww z+| |dkr<|  | j| |d|g |  W dS |  | j| |d|g |  W dS  ty] } zt|d}~ww )z:Compiles the source by spawning GCC and windres if needed.).rc.reswindresz-iz-oNzc++)spawnr   r   detect_languager   r   )r0   objsrcextcc_argsextra_postargspp_optsmsgr   r   r   _compilej   s2   

zCompiler._compileNc                    s  t  |
pg }
t  |pg }t  |pg }|r| t || j |durn|| jks0| jdkrntj	|d }tj
tj|\}}tj||d }dtj| dg}|| | t||fd|  || |	su|
d t |||||||d|	|
||| dS )	zLink the objects.Nr   r   z.defzLIBRARY EXPORTSzwriting z-s)copyr&   _runtime_library_dirs_msgextendr/   
EXECUTABLEr,   r)   pathdirnamesplitextbasenamejoinexecuter   appendr!   link)r0   target_descobjectsoutput_filename
output_dir	librarieslibrary_dirsruntime_library_dirsexport_symbolsdebugextra_preargsrF   
build_temptarget_langtemp_dirdll_namedll_extensiondef_filecontentsr5   r   r   rV      sD   





zCompiler.linkc                 C   s   |  t g S N)r&   rL   r0   dirr   r   r   runtime_library_dir_option   s   
z#Compiler.runtime_library_dir_optionc                    s   t j|}t |||S rh   )r)   rO   normcaser!   _make_out_path)r0   rZ   	strip_dirsrc_namenorm_src_namer5   r   r   rm      s   zCompiler._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).0rD   r;   r   r   
<dictcomp>   s    z+Compiler.out_extensions.<locals>.<dictcomp>)r>   r=   )r!   out_extensionsr;   r5   r;   r   rt      s
   zCompiler.out_extensionsFF)
NNNNNFNNNN)__name__
__module____qualname____doc__compiler_typerq   static_lib_extensionshared_lib_extensiondylib_lib_extensionstatic_lib_formatshared_lib_formatdylib_lib_formatexe_extensionr"   propertyr<   rI   rV   rk   rm   rt   __classcell__r   r   r5   r   r   *   s<    $
X	r   c                       s.   e Zd ZdZdZd fdd	Zdd Z  ZS )	MinGW32Compilerz:Handles the Mingw32 port of the GNU C compiler to Windows.mingw32Fc                    s   t  || d}t| jrtd| j| j d| j d| j d| j d| j | j d| | j | j d| d d S )Nr   z1Cygwin gcc cannot be used with --compiler=mingw32z	 -O -Wallz -shared -O -Wall )r   r   r   r   r   r   r   r    )	r!   r"   is_cygwinccr'   r   r.   r(   r,   r-   )r0   r1   r   r4   r5   r   r   r"      s   





zMinGW32Compiler.__init__c                 C   s   t trh   )r   rL   ri   r   r   r   rk     s   z*MinGW32Compiler.runtime_library_dir_optionru   )rv   rw   rx   ry   rz   r"   rk   r   r   r   r5   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|jdd}W n t	yD } zt
d	| d
|j fW  Y d}~S d}~ww d}||v rPt}d}nt}d}||d| d|fS )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'zutf-8)encodingzcouldn't read 'z': N__GNUC__mentionszdoes not mentionr   )	distutilsr   sysversionr%   get_config_h_filenamepathlibPath	read_textOSErrorCONFIG_H_UNCERTAINstrerrorCONFIG_H_NOTOK)r   fnconfig_hexc	substringcodemention_inflectedr   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)r'   
out_stringr   r   r   r   J  s   r   )!ry   rK   r)   r   r   r   r9   
subprocessr   errorsr   r   	file_utilr   r   r   r   r   r	    r   r   r   r   rL   r   r   r%   r   r   r#   r   get_versionsr   r   r   r   <module>   s6     K 1