o
    5‘ði29  ã                   @   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                   @   sŒ   e Zd Zej d¡d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s†J ‚dd„ }
|
t_ˆj ¡ ddgks˜J ‚dd„ }
|
t_ˆj ¡ ddgksªJ ‚|	t_dt _dd„ }
|
t_ˆj ¡ tddgƒksÄJ ‚d d„ }
|
t_ˆj ¡ tddgƒksØJ ‚dt _d!d„ }
|
t_ˆj ¡ d"ksëJ ‚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_ldsharedc                 C   sº  dd„ }t jdœdd„}|t _|t _tjj| jdd d���5}tjj| jdd	d��� tjj| jd
d d��õ tƒ �á}|d= |d= t  | j¡ | jj	dd… ddgksSJ ‚| jj
dd… ddgksaJ ‚| jjd g ddd� |jd d }g d¢}|d d… |ks€J ‚| jjg ddd� |jd d }ddd| j d¡g}|d d… |ks¤J ‚d|d< d|d< t  | j¡ | jj	dd… ddgksÀJ ‚| jj
dd… ddgksÎJ ‚| jjd g ddd� |jd d }g d¢}|d d… |ksíJ ‚| jjg ddd� |jd d }ddd| j d¡g}|d d… |k�sJ ‚W d   ƒ n	1 �sw   Y  W d   ƒ n	1 �s-w   Y  W d   ƒ n1 �s=w   Y  W d   ƒ d S W d   ƒ d S 1 �sVw   Y  d S )Nc                 S   ó4   | dkrdS | dkrdS | dkrdS | dkrdS d	S )
NrT   z0ccache gcc-4.2 -bundle -undefined dynamic_lookupÚLDCXXSHAREDz0ccache g++-4.2 -bundle -undefined dynamic_lookupÚCXXzccache g++-4.2rH   zccache gcc-4.2r@   r   rB   r   r   r   r-   ù   ó   zATestUnixCCompiler.test_cxx_commands_used_are_correct.<locals>.gcvrW   c                 W   rY   rZ   r[   r^   r   r   r   r`     ra   zBTestUnixCCompiler.test_cxx_commands_used_are_correct.<locals>.gcvsÚspawn©Úreturn_valueÚ
_need_linkTÚmkpathrj   ri   r   r   Úccacheúg++-4.2úa.outúc++©Útarget_lang)rq   rr   ú-bundleú
-undefinedÚdynamic_lookupé   z-oé   z1wrapper g++-4.2 -bundle -undefined dynamic_lookupzwrapper g++-4.2Úwrapper)r|   rr   rw   rx   ry   )r   r   r   ÚmockÚpatchÚobjectr   r   rd   Úlinker_so_cxxÚlinker_exe_cxxÚlinkÚ	call_argsÚlink_executableÚexecutable_filename©r   r-   r`   Ú
mock_spawnr:   rƒ   Úexpectedr   r   r   Ú"test_cxx_commands_used_are_correct÷   sb   ÿþýü
ü×€ €T z4TestUnixCCompiler.test_cxx_commands_used_are_correctÚ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 sŽw   Y  W d  ƒ n1 s�w   Y  W d  ƒ dS W d  ƒ dS 1 sµw   Y  dS )z�
        Ensure that setting CC env variable also changes default linker
        correctly when building C++ extensions.

        pypa/distutils#126
        c                 S   rh   )
NrT   rU   ri   z*g++-4.2 -bundle -undefined dynamic_lookup rj   rr   rH   rV   r@   r   rB   r   r   r   r-   @  rk   zKTestUnixCCompiler.test_cc_overrides_ldshared_for_cxx_correctly.<locals>.gcvrW   c                 W   rY   rZ   r[   r^   r   r   r   r`   K  ra   zLTestUnixCCompiler.test_cc_overrides_ldshared_for_cxx_correctly.<locals>.gcvsrl   Nrm   ro   Trp   zccache my_ccrH   Úmy_cxxrj   rT   r   r   rq   rb   rs   rt   ru   )r‹   rw   rx   ry   r{   )r   r   r   r}   r~   r   r   r   rd   re   r‚   rƒ   r†   r   r   r   Ú,test_cc_overrides_ldshared_for_cxx_correctly6  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-   g  r.   z5TestUnixCCompiler.test_explicit_ldshared.<locals>.gcvrW   c                 W   rY   rZ   r[   r^   r   r   r   r`   l  ra   z6TestUnixCCompiler.test_explicit_ldshared.<locals>.gcvsrb   rH   zmy_ld -bundle -dynamicrT   r   Úmy_ldrc   rf   r   r   r   Útest_explicit_ldsharedb  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_functiony  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>ƒ  s    z:TestUnixCCompiler.test_find_library_file.<locals>.<lambda>Úexistsc                 S   s   d| v S )NÚexistingr   ©Údr   r   r   r—   „  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—   ”  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_file�  s,   
ÿÿýÿÿz(TestUnixCCompiler.test_find_library_fileN)r   r   r   r6   ÚmarkÚskipifrQ   rg   r‰   ÚusefixturesrŒ   rŽ   r•   r¨   r   r   r   r   r!   "   s    

 
>



>

*
r!   )Ú__doc__r2   r   Úunittest.mockr}   Ú	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"    



