U
    uis.                     @   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mZmZ ddlmZ ddlmZ ddlmZ dd	lmZm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   )CCompilerErrorCompileErrorDistutilsExecErrorDistutilsPlatformError)
write_file)get_config_vars)UnixCCompiler)LooseVersionsuppress_known_deprecationc                   C   s   g S )z6No longer needed, but kept for backward compatibility. r   r   r   I/tmp/pip-unpacked-wheel-9osl9suo/setuptools/_distutils/cygwinccompiler.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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.exeFc                    s  t  ||| t \}}| d| d| d |tk	rL| d| d tdd\| _| _t	j
d| jpnd| _t	j
d| jpd	| _| j| _| j| _d
}| j| j d| j d| j d| j d| j d| j d| | j d| j d| d t | _d S )Nz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verbosedry_runforcestatusdetailsshared_option	__class__r   r   r    5   s0    







zCygwinCCompiler.__init__c              
   C   s6   t jdtdd t  tdW  5 Q R  S Q R X 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   r.   r   r   r   gcc_versionY   s    zCygwinCCompiler.gcc_versionc              
   C   s   |dkrNz|  dd|d|g W q tk
rJ } zt|W 5 d}~X Y qX n|zP| |dkr~|  | j| |d|g |  n|  | j| |d|g |  W n* tk
r } zt|W 5 d}~X Y nX dS )z:Compiles the source by spawning GCC and windres if needed.).rc.resZwindresz-iz-oNzc++)spawnr   r   Zdetect_languager   r   )r.   objsrcextZcc_argsextra_postargsZpp_optsmsgr   r   r   _compileh   s*    zCygwinCCompiler._compileNc                 C   s  t  |
p
g }
t  |pg }t  |p&g }|r8| t || j |dk	r|| jks`| jdkrtj	|d }tj
tj|\}}tj||d }dtj| dg}|| | t||fd|  || |	s|
d t| |||||||d|	|
||| dS )	zLink the objects.Nr   r   z.defzLIBRARY ZEXPORTSzwriting z-s)copyr$   _runtime_library_dirs_msgextendr-   Z
EXECUTABLEr*   r'   pathdirnamesplitextbasenamejoinexecuter   appendr
   link)r.   Ztarget_descZobjectsZoutput_filename
output_dir	librarieslibrary_dirsruntime_library_dirsexport_symbolsdebugZextra_preargsrC   
build_tempZtarget_langtemp_dirZdll_nameZdll_extensionZdef_filecontentsr   r   r   rP      sL    




zCygwinCCompiler.linkc                 C   s   |  t g S N)r$   rG   r.   dirr   r   r   runtime_library_dir_option   s    
z*CygwinCCompiler.runtime_library_dir_optionc                    s   t j|}t |||S rZ   )r'   rI   normcaser   _make_out_path)r.   rQ   Z	strip_dirsrc_nameZnorm_src_namer5   r   r   r_      s    zCygwinCCompiler._make_out_pathc                    s   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).0rB   r;   r   r   
<dictcomp>   s      z2CygwinCCompiler.out_extensions.<locals>.<dictcomp>)r>   r=   )r   out_extensionsr;   r5   r;   r   rd      s    zCygwinCCompiler.out_extensions)FFF)
NNNNNFNNNN)__name__
__module____qualname____doc__compiler_typera   Zstatic_lib_extensionshared_lib_extensionZdylib_lib_extensionZstatic_lib_formatZshared_lib_formatZdylib_lib_formatZexe_extensionr    propertyr<   rE   rP   r]   r_   rd   __classcell__r   r   r5   r   r   (   s:   $
          
Y	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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+   )r.   r/   r0   r1   r4   r5   r   r   r       s    




zMingw32CCompiler.__init__c                 C   s   t td S rZ   )r   rG   r[   r   r   r   r]     s    z+Mingw32CCompiler.runtime_library_dir_option)FFF)re   rf   rg   rh   ri   r    r]   rl   r   r   r5   r   rm      s   rm   okznot okZ	uncertainc               
   C   s   ddl m}  dtjkrtdfS dtjkr0tdfS |  }zt|jdd}W n< t	k
r } zt
d	| d
|j f W Y S d}~X Y n8X d}||krt}d}nt}d}||d| d|fS d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   )	sysconfigZGCCzsys.version mentions 'GCC'ZClangzsys.version mentions 'Clang'zutf-8)encodingzcouldn't read 'z': NZ__GNUC__Zmentionszdoes not mentionrn   )	distutilsrq   sysversionr#   get_config_h_filenamepathlibPath	read_textOSErrorCONFIG_H_UNCERTAINstrerrorCONFIG_H_NOTOK)rq   fnconfig_hexcZ	substringcodeZ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%   Z
out_stringr   r   r   ro   I  s    ro   )!rh   rF   r'   rw   r   rt   r9   
subprocessr   errorsr   r   r   r   	file_utilr   rq   r	   Zunixccompilerr
   ru   r   r   r   rG   r   rm   r#   r}   r{   r!   ro   get_versionsr   r   r   r   <module>   s2    L 1