o
    !g:.                     @   s   d 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
 ddlmZ ddlmZ ddlmZ ddlZd	d
lmZ ejdddd Zejdddd ZG dd dejZdS )z"Tests for distutils.unixccompiler.    N)	sysconfig)consolidate_linker_args)DistutilsPlatformError)support)EnvironmentVarGuard)_clear_cached_macosx_ver   )unixT)autousec                 C   s4   |  tdtj |  tdtj |  tdtj d S )Nplatformget_config_varget_config_vars)setattrsysr   r   r   r   )monkeypatch r   p/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/_distutils/compilers/C/tests/test_unix.pysave_values   s   r   c                 C   s    G dd dt j}| | j_d S )Nc                   @   s   e Zd Zdd ZdS )z)compiler_wrapper.<locals>.CompilerWrapperc                 S   s
   |  dS )Nz/foo)runtime_library_dir_optionselfr   r   r   	rpath_foo   s   
z3compiler_wrapper.<locals>.CompilerWrapper.rpath_fooN)__name__
__module____qualname__r   r   r   r   r   CompilerWrapper   s    r   )r	   Compilerinstancecc)requestr   r   r   r   compiler_wrapper   s   r    c                   @   sx   e Zd Zejddd Zejddd Zejdejddd Z	ejdd	d
 Z
dd Zdd ZdS )TestUnixCCompilerzplatform.system == "Windows"c                    sb  dt _d d}d}d|fd|fd|fd|fd	|fd
|fd|fd|fd|fd|fd|fdg} fdd fdd}|D ]0\}}|\}}|||| |d u rU|d|| |d u r_||d| |d u rm|d u rm|dd| q=tj}	dt _dd }
|
t_j ddgksJ dd }
|
t_j ddgksJ dd }
|
t_j ddgksJ |	t_dt _dd }
|
t_j tddgksJ d d }
|
t_j tddgksJ dt _d!d }
|
t_j d"ksJ dt _d#d }
|
t_j tddgksJ dt _d$d }
|
t_j tddgksJ dt _d%d }
|
t_j d"ks/J d S )&NdarwinMACOSX_DEPLOYMENT_TARGETz-Wl,-rpath,/fooz-L/foo)NN)N11)10N)10.3N)z10.3.1N)10.5N)z10.5.1N)r&   r&   )r&   r'   )r'   r&   )r'   r$   ))z10.4r%   Nc                    s    fdd}|S )Nc                    s   |  krS dS Nxxxr   )var)darwin_ver_varsyscfg_macosx_verr   r   gcvC      zRTestUnixCCompiler.test_runtime_libdir_option.<locals>.make_darwin_gcv.<locals>.gcvr   )r,   r-   )r+   )r,   r   make_darwin_gcvB   s   zETestUnixCCompiler.test_runtime_libdir_option.<locals>.make_darwin_gcvc                    s   t j}d| d|d}tj}| }t  | t_|d ur%|| < n	 |v r.|  |d ur>j |ks=J |nt	j
t d d j  W d    n1 sWw   Y  |d ure|| < n	 |v rn|  |t_t  d S )NzmacOS version = (sysconfig=z, env=)z	 mismatch)match)osenvironr   r   getr   popr   r   pytestraisesr   )r,   env_macosx_verexpected_flagenvmsgold_gcvold_env_macosx_verr+   r/   r   r   r   do_darwin_testJ   s.   






zDTestUnixCCompiler.test_runtime_libdir_option.<locals>.do_darwin_test zhp-uxc                 S      dS r(   r   vr   r   r   r-   {      z9TestUnixCCompiler.test_runtime_libdir_option.<locals>.gcvz+sc                 S   rA   )Ngccr   rB   r   r   r   r-      rD   z-Wl,+sc                 S   rA   )Nzg++r   rB   r   r   r   r-      rD   barc                 S      | dkrdS | dkrdS d S )NCCrE   GNULDyesr   rB   r   r   r   r-      
   z-Wl,--enable-new-dtagsc                 S   rG   )NrH   zgcc -pthread -B /barrI   rJ   r   rB   r   r   r   r-      rK   c                 S   rG   )NrH   rE   rI   nor   rB   r   r   r   r-      rK   z
-Wl,-R/fooc                 S   rG   )NrH   zx86_64-pc-linux-gnu-gcc-4.4.2rI   rJ   r   rB   r   r   r   r-      rK   c                 S   rG   )NrH   r   rI   rJ   r   rB   r   r   r   r-      rK   c                 S   rG   )NrH   r   rI   rL   r   rB   r   r   r   r-      rK   )r   r   r   r   r   r   r   )r   darwin_rpath_flagdarwin_lib_flagdarwin_test_casesr?   macosx_versr9   r,   r8   r<   r-   r   r>   r   test_runtime_libdir_option#   s   !



z,TestUnixCCompiler.test_runtime_libdir_optionc                 C   s|   dd }t jddd}|t _|t _t }d|d< |d= t | j W d    n1 s-w   Y  | jjd	 dks<J d S )
Nc                 S      | dkrdS dS NLDSHARED*gcc-4.2 -bundle -undefined dynamic_lookup gcc-4.2r   rB   r   r   r   r-      r.   z9TestUnixCCompiler.test_cc_overrides_ldshared.<locals>.gcv_origc                 W      |r
t ttj|S |  S Nlistmapr   r   rX   argsr   r   r   gcvs      z:TestUnixCCompiler.test_cc_overrides_ldshared.<locals>.gcvsmy_ccrH   rT   r   r   r   r   r   customize_compilerr   	linker_sor   r-   r`   r:   r   r   r   test_cc_overrides_ldshared   s   z,TestUnixCCompiler.test_cc_overrides_ldshareddisable_macos_customizationc                 C   sx  dd }t jddd}|t _|t _tjj| jddd}tjj| jd	d
ds tjj| jdddY t F}d|d< d|d< |d= t | j | jj	dd ddgksVJ | jj
dg ddd |jd d }g d}|dd |ksuJ W d   n1 sw   Y  W d   n1 sw   Y  W d   n1 sw   Y  W d   dS W d   dS 1 sw   Y  dS )z
        Ensure that setting CC env variable also changes default linker
        correctly when building C++ extensions.

        pypa/distutils#126
        c                 S   s4   | dkrdS | dkrdS | dkrdS | dkrdS d	S )
NrT   rU   LDCXXSHAREDz*g++-4.2 -bundle -undefined dynamic_lookup CXXzg++-4.2rH   rV   r@   r   rB   r   r   r   r-     s   zKTestUnixCCompiler.test_cc_overrides_ldshared_for_cxx_correctly.<locals>.gcvrW   c                 W   rY   rZ   r[   r^   r   r   r   r`     ra   zLTestUnixCCompiler.test_cc_overrides_ldshared_for_cxx_correctly.<locals>.gcvsspawnN)return_value
_need_linkTmkpathzccache my_ccrH   my_cxxrj   rT   r   r   ccacherb   za.outzc++)target_lang)ro   z-bundlez
-undefineddynamic_lookup   )r   r   r   mockpatchobjectr   r   rd   re   link	call_args)r   r-   r`   
mock_spawnr:   rx   expectedr   r   r   ,test_cc_overrides_ldshared_for_cxx_correctly   s8   
 P z>TestUnixCCompiler.test_cc_overrides_ldshared_for_cxx_correctlyc                 C   s~   dd }t jddd}|t _|t _t }d|d< d|d	< t | j W d    n1 s.w   Y  | jjd
 dks=J d S )Nc                 S   rR   rS   r   rB   r   r   r   r-   (  r.   z5TestUnixCCompiler.test_explicit_ldshared.<locals>.gcvrW   c                 W   rY   rZ   r[   r^   r   r   r   r`   -  ra   z6TestUnixCCompiler.test_explicit_ldshared.<locals>.gcvsrb   rH   zmy_ld -bundle -dynamicrT   r   my_ldrc   rf   r   r   r   test_explicit_ldshared#  s   z(TestUnixCCompiler.test_explicit_ldsharedc                 C   s&   d| j _t|   | j d d S )Nscratchabort)r   
output_dirr2   chdirmkdtemphas_functionr   r   r   r   test_has_function:  s   z#TestUnixCCompiler.test_has_functionc                 C   s   t  }dd |_|tjddd  tjdkrdnd}d}||d		d
dd| ks/J |t
|d		d
dd| ksBJ |tjddd  ||d		d
ddksZJ |t
|d		d
ddksjJ d S )Nc                 S   s   | S rZ   r   )dirr   r   r   <lambda>D  s    z:TestUnixCCompiler.test_find_library_file.<locals>.<lambda>existsc                 S   s   d| v S )Nexistingr   dr   r   r   r   E  s    cygwinzlibabc.dylibz
cygabc.dll)z/foo/bar/missingz/foo/bar/existingabc\/z/foo/bar/existing/c                 S   s   d| v od| v od| vS )Nr   z.az.dll.ar   r   r   r   r   r   U  s    z/foo/bar/existing/libabc.a)r	   r   _library_rootr   r2   pathr   r   find_library_filereplacereversed)r   r   compilerlibnamedirsr   r   r   test_find_library_fileB  s,   
z(TestUnixCCompiler.test_find_library_fileN)r   r   r   r6   markskipifrQ   rg   usefixturesr{   r}   r   r   r   r   r   r   r!   "   s    

 
>



*
r!   )__doc__r2   r   unittest.mockrt   	distutilsr   distutils.compatr   distutils.errorsr   distutils.testsr   distutils.tests.compat.py39r   distutils.utilr   r6   r@   r	   fixturer   r    TempdirManagerr!   r   r   r   r   <module>   s"    



