o
    Wªod˜J  ã                   @  s6  d dl mZ 	 d dlZd dlZd dlZddlmZ ddlmZ ddlm	Z	 ej
r;ddlmZ ddlmZ d	d
lmZ neZdgdgdgdgdgdgdgdgddœ	Zdgdgdgdgdgdgdgdgdgddœ
Zg dgg dgdgddgddgdœZg dgdœZG dd„ deejdZG dd„ deƒZG dd„ deƒZdS )é    )ÚannotationsNé   )Úarglist)Úmesonlib)Úmlog)ÚEnvironment)Ú
Dependencyé   )ÚCLikeCompilerz	/arch:SSEz
/arch:SSE2z	/arch:AVXz
/arch:AVX2)	ÚmmxÚsseÚsse2Ússe3Ússe41Ússe42ÚavxÚavx2Úneon)
r   r   r   r   Zssse3r   r   r   r   r   ú/Odz/O1ú/O2ú/Gw)ÚplainÚ0ÚgÚ1Ú2Ú3Úsz/Zi)FTc                   @  sä  e Zd ZdZdgZdgZejdg Zg Z	g dgdgdgdgd	œZ
g d
¢Zg dgdgdgdgdœZdZd}dd„Zd~dd„Zddd„Zd€dd„Zd€dd„Zdd d!„Zd~d"d#„Zd~d$d%„Zd~d&d'„Zd~d(d)„Zd‚d+d,„Zdƒd-d.„Zd„d0d1„Zd…d4d5„Zd†d7d8„Zd‡d:d;„Zd~d<d=„Zdˆd?d@„Zd‰dDdE„Z d~dFdG„Z!d~dHdI„Z"dŠdLdM„Z#e$d‡dNdO„ƒZ%e$d‡dPdQ„ƒZ&d~dRdS„Z'd‹dVdW„Z(dŒdZd[„Z)dd_d`„Z*dŽddcdd„Z+ddgdh„Z,d‘dldm„Z-d’dndo„Z.d~dpdq„Z/d“dsdt„Z0d”dvdw„Z1ddxdy„Z2d•dzd{„Z3d|S )–ÚVisualStudioLikeCompilera&  A common interface for all compilers implementing an MSVC-style
    interface.

    A number of compilers attempt to mimic MSVC, with varying levels of
    success, such as Clang-CL and ICL (the Intel C/C++ Compiler for Windows).
    This class implements as much common logic as possible.
    z/W3r   Zexecinfoz/MDz/MDdz/MTz/MTd)ÚnoneÚmdÚmddÚmtÚmtd)z/nologoz/showIncludesú/utf-8z/W2z/W4z/Wall)r   r   r   r   Z
everythingFÚtargetÚstrc                 C  sª   dd„ dD ƒ| _ || _d|v pd|v | _d|v rd| _nd|v r$d| _nd|v r,d	| _nd
|v r4d
| _n|| _t | jd¡rG| j  t d¡¡ | j	d usNJ ‚| j| j	_d S )Nc                 S  s   h | ]}t  |¡’qS © )r   Ú	OptionKey)Ú.0Úor'   r'   ú‡home/ych/rk3568/buildroot/output/rockchip_rk3568_recovery/host/lib/python3.10/site-packages/mesonbuild/compilers/mixins/visualstudio.pyÚ	<setcomp>z   s    z4VisualStudioLikeCompiler.__init__.<locals>.<setcomp>)Zb_pchZb_ndebugZb_vscrtÚx64Úx86_64Z86Úx86Úaarch64Úarm64Úarmz>=19.28.29910Z
b_sanitize)
Zbase_optionsr%   Úis_64Úmachiner   Úversion_compareÚversionÚaddr(   Zlinker©Úselfr%   r'   r'   r+   Ú__init__y   s    z!VisualStudioLikeCompiler.__init__ÚreturnúT.List[str]c                 C  s
   | j  ¡ S ©N)Úalways_argsÚcopy©r9   r'   r'   r+   Úget_always_argsŽ   s   
z(VisualStudioLikeCompiler.get_always_argsc                 C  ó   dS )NÚpchr'   r@   r'   r'   r+   Úget_pch_suffix’   ó   z'VisualStudioLikeCompiler.get_pch_suffixÚheaderc                 C  s6   t j |¡ d¡d d… }| |  ¡ ¡ d |¡}|S )NÚ.éÿÿÿÿ)ÚosÚpathÚbasenameÚsplitÚappendrD   Újoin)r9   rF   ZchoppedÚpchnamer'   r'   r+   Úget_pch_name•   s   
z%VisualStudioLikeCompiler.get_pch_namec                 C  s   t ‚r=   )ÚNotImplementedError©r9   rF   r'   r'   r+   Úget_pch_base_name›   ó   z*VisualStudioLikeCompiler.get_pch_base_nameÚpch_dirc                 C  s4   |   |¡}|  |¡}d| d| dtj ||¡ gS )Nz/FIz/Yuú/Fp)rS   rP   rI   rJ   rN   )r9   rU   rF   ÚbaserO   r'   r'   r+   Úget_pch_use_argsŸ   s   

 z)VisualStudioLikeCompiler.get_pch_use_argsc                 C  ó   dgS )Nú/EPr'   r@   r'   r'   r+   Úget_preprocess_only_args¤   ó   z1VisualStudioLikeCompiler.get_preprocess_only_argsc                 C  ó   ddgS )NrZ   z/Pr'   r@   r'   r'   r+   Úget_preprocess_to_file_args§   ó   z4VisualStudioLikeCompiler.get_preprocess_to_file_argsc                 C  rY   )Nz/cr'   r@   r'   r'   r+   Úget_compile_only_argsª   r\   z.VisualStudioLikeCompiler.get_compile_only_argsc                 C  r]   )Nr   z/Oi-r'   r@   r'   r'   r+   Úget_no_optimization_args­   r_   z1VisualStudioLikeCompiler.get_no_optimization_argsÚvaluec                 C  s$   |dkrg S |dkrt  d¡‚dgS )Nr   Úaddressz1VS only supports address sanitizer at the moment.z/fsanitize=address)r   ZMesonException)r9   rb   r'   r'   r+   Úsanitizer_compile_args°   s
   
z/VisualStudioLikeCompiler.sanitizer_compile_argsc                 C  s2   | j dkr
d| gS | d¡rd| gS d| gS )NZPREPROCESSORz/Fiz.exez/Feú/Fo)ÚmodeÚendswithr8   r'   r'   r+   Úget_output_args·   s
   




z(VisualStudioLikeCompiler.get_output_argsÚ	buildtypec                 C  ó   g S r=   r'   )r9   ri   r'   r'   r+   Úget_buildtype_args¾   rE   z+VisualStudioLikeCompiler.get_buildtype_argsÚis_debugÚboolc                 C  s   t | S r=   )Úmsvc_debug_args)r9   rl   r'   r'   r+   Úget_debug_argsÁ   r_   z'VisualStudioLikeCompiler.get_debug_argsÚoptimization_levelc                 C  s(   t | }t | jd¡rdd„ |D ƒ}|S )Nz<18.0c                 S  ó   g | ]}|d kr|‘qS )r   r'   )r)   Úargr'   r'   r+   Ú
<listcomp>Ç   ó    zBVisualStudioLikeCompiler.get_optimization_args.<locals>.<listcomp>)Úmsvc_optimization_argsr   r5   r6   )r9   rp   Úargsr'   r'   r+   Úget_optimization_argsÄ   s   z.VisualStudioLikeCompiler.get_optimization_argsrv   c                 C  s
   dg| S )Nz/linkr'   )r9   rv   r'   r'   r+   Úlinker_to_compiler_argsÊ   s   
z0VisualStudioLikeCompiler.linker_to_compiler_argsc                 C  rj   r=   r'   r@   r'   r'   r+   Úget_pic_argsÍ   rE   z%VisualStudioLikeCompiler.get_pic_argsÚdefsfilec                 C  s   t |tƒs	tdƒ‚d| gS )Nz%Module definitions file should be strz/DEF:)Ú
isinstancer&   ÚRuntimeError)r9   rz   r'   r'   r+   Úgen_vs_module_defs_argsÐ   s   

z0VisualStudioLikeCompiler.gen_vs_module_defs_argsÚsourcerO   úT.Tuple[str, T.List[str]]c                 C  s.   t j |¡d d }|d| d| d| gfS )Nr   z.objz/YcrV   re   )rI   rJ   Úsplitext)r9   rF   r~   rO   Zobjnamer'   r'   r+   Úgen_pch_args×   s   z%VisualStudioLikeCompiler.gen_pch_argsc                 C  rY   )Nz/openmpr'   r@   r'   r'   r+   Úopenmp_flagsÛ   r\   z%VisualStudioLikeCompiler.openmp_flagsc                 C  rj   r=   r'   r@   r'   r'   r+   Úopenmp_link_flagsÞ   rE   z*VisualStudioLikeCompiler.openmp_link_flagsÚenvú'Environment'c                 C  rj   r=   r'   )r9   r„   r'   r'   r+   Úthread_flagsâ   rE   z%VisualStudioLikeCompiler.thread_flagsc              	   C  sB  g }|D ]š}|dv rq|  d¡rd|dd …  }n€|  d¡r'd|dd …  }nr|  d¡r=|dd … }|| jv r8q|d }n\|  d	¡rY|  d
¡rPd|dd …  }nId|dd …  }n@|  d¡ru|  d¡rld|dd …  }n-d|dd …  }n$|dkrzq|  d¡sˆ|  d¡sˆ|dkr™z| d¡ W n	 ty˜   Y nw | |¡ q|S )N>   z-mms-bitfieldsú-pthreadú	-LIBPATH:ú	/LIBPATH:é	   ú-Lé   ú-lú.libú-isystemz	-isystem=ú/Ié   z
-idirafterz-idirafter=é   é
   r‡   z/source-charset:z/execution-charset:z/validate-charset-r$   )Ú
startswithÚignore_libsÚremoveÚ
ValueErrorrM   )Úclsrv   ÚresultÚiÚnamer'   r'   r+   Úunix_args_to_nativeå   sF   









ÿþÿz,VisualStudioLikeCompiler.unix_args_to_nativec                 C  sd   g }|D ]+}|  d¡r| d|dd …  ¡ q| d¡r*tj |¡s*| d| ¡ q| |¡ q|S )N)r‰   rˆ   r‹   rŠ   )z.arŽ   r   )r”   rM   rg   rI   rJ   Úisabs)r˜   rv   r™   rr   r'   r'   r+   Únative_args_to_unix  s   
z,VisualStudioLikeCompiler.native_args_to_unixc                 C  rY   )Nz/WXr'   r@   r'   r'   r+   Úget_werror_args!  r\   z(VisualStudioLikeCompiler.get_werror_argsrJ   Ú	is_systemc                 C  s   |dkrd}d| gS )NÚ rG   ú-Ir'   ©r9   rJ   r    r'   r'   r+   Úget_include_args$  s   
z)VisualStudioLikeCompiler.get_include_argsÚparameter_listÚ	build_dirc              
   C  s¤   t |ƒD ]K\}}|d d… dks|d d… dkr0|d d… tj tj ||dd … ¡¡ ||< q|d d… dkrO|d d… tj tj ||dd … ¡¡ ||< q|S )NrŒ   r¢   r   rŠ   r‰   )Ú	enumeraterI   rJ   ÚnormpathrN   )r9   r¥   r¦   Úidxrš   r'   r'   r+   Ú&compute_parameters_with_absolute_paths*  s    0.€z?VisualStudioLikeCompiler.compute_parameters_with_absolute_pathsÚcoderf   úT.Tuple[bool, bool]c                 C  s„   |dkrdnd}| j ||||d'}|jdkr#d|jfW  d   ƒ S ||jv p,||jv  |jfW  d   ƒ S 1 s;w   Y  d S )NÚlinkZ4044Z9002)Ú
extra_argsrf   r   F)Z_build_wrapperÚ
returncodeÚcachedÚstderrÚstdout)r9   rv   r„   r«   rf   Zwarning_textÚpr'   r'   r+   Úhas_arguments6  s   
þ$ýz&VisualStudioLikeCompiler.has_argumentsÚrel_objrC   c                 C  s0   |  d¡d d… }|dg7 }dd |¡ g}|S )NrG   rH   Úpdbz/Fd)rL   rN   )r9   rµ   rC   Zpdbarrrv   r'   r'   r+   Úget_compile_debugfile_args=  s   
z3VisualStudioLikeCompiler.get_compile_debugfile_argsÚinstruction_setúT.Optional[T.List[str]]c                 C  s   | j r	t |d ¡S t |d ¡S r=   )r3   Úvs64_instruction_set_argsÚgetÚvs32_instruction_set_args©r9   r¸   r'   r'   r+   Úget_instruction_set_argsC  s   z1VisualStudioLikeCompiler.get_instruction_set_argsr6   ÚintúT.Optional[str]c                 C  sš   |dk rdS |dk rdS |dk rdS |dk rdS |d	k rd
S |dk r$dS |dk r*dS |dk r0dS |dk r6dS |dk r<dS |dk rBdS t  d| j›¡ d S )Ni  z7.0ix  z7.1iÜ  z8.0i@  z9.0i¤  z10.0i  z11.0il  z12.0iv  z14.0i€  ú14.1iŠ  z14.2i”  z14.3z#Could not find toolset for version )r   Úwarningr6   ©r9   r6   r'   r'   r+   Ú_calculate_toolset_versionH  s0   z3VisualStudioLikeCompiler._calculate_toolset_versionc                 C  sB   zt d | j d¡dd… ¡ƒ}W n
 ty   Y d S w |  |¡S )Nr¡   rG   r   rŒ   )r¿   rN   r6   rL   r—   rÄ   rÃ   r'   r'   r+   Úget_toolset_versionb  s   "ÿ
z,VisualStudioLikeCompiler.get_toolset_versionc                 C  s    dt jvrg S t jd  t j¡S )NZINCLUDE)rI   ÚenvironrL   Úpathsepr@   r'   r'   r+   Úget_default_include_dirsj  s   
z1VisualStudioLikeCompiler.get_default_include_dirsÚcrt_valc                 C  s¢   || j v r
| j | S |dv sJ ‚d}d}|dkrd}d}|dkr"g S |dkr+| j | S |d	kr4| j | S |d
kr=| j | S |dkrF| j | S |dksLJ ‚t d¡‚)N>   Ústatic_from_buildtypeZfrom_buildtyper!   r    rÊ   r#   r"   r   ÚdebugZdebugoptimizedÚreleaseZminsizeZcustomzBRequested C runtime based on buildtype, but buildtype is "custom".)Úcrt_argsr   ZEnvironmentException)r9   rÉ   ri   ZdbgÚrelr'   r'   r+   Úget_crt_compile_argso  s(   






z-VisualStudioLikeCompiler.get_crt_compile_argsr›   c                 C  s   |dv dfS )N>   Z	dllimportZ	dllexportFr'   )r9   r›   r„   r'   r'   r+   Úhas_func_attribute‡  s   z+VisualStudioLikeCompiler.has_func_attributec                 C  rB   )NÚmsvcr'   r@   r'   r'   r+   Úget_argument_syntaxŒ  rE   z,VisualStudioLikeCompiler.get_argument_syntaxc                 C  s    |   |¡}|dur|S |  |¡S )zö
        Check if the compiler prefixes an underscore to global C symbols.

        This overrides the Clike method, as for MSVC checking the
        underscore prefix based on the compiler define never works,
        so do not even try.
        N)Z$_symbols_have_underscore_prefix_listZ)_symbols_have_underscore_prefix_searchbin)r9   r„   r™   r'   r'   r+   Úsymbols_have_underscore_prefix  s   


z7VisualStudioLikeCompiler.symbols_have_underscore_prefixN©r%   r&   ©r;   r<   )r;   r&   ©rF   r&   r;   r&   )rU   r&   rF   r&   r;   r<   )rb   r&   r;   r<   )r%   r&   r;   r<   )ri   r&   r;   r<   )rl   rm   r;   r<   )rp   r&   r;   r<   )rv   r<   r;   r<   )rz   r&   r;   r<   )rF   r&   r~   r&   rO   r&   r;   r   )r„   r…   r;   r<   ©rJ   r&   r    rm   r;   r<   )r¥   r<   r¦   r&   r;   r<   ©
rv   r<   r„   r…   r«   r&   rf   r&   r;   r¬   ©F©rµ   r&   rC   rm   r;   r<   ©r¸   r&   r;   r¹   )r6   r¿   r;   rÀ   ©r;   rÀ   )rÉ   r&   ri   r&   r;   r<   )r›   r&   r„   r…   r;   r¬   )r„   r…   r;   rm   )4Ú__name__Ú
__module__Ú__qualname__Ú__doc__Zstd_warn_argsZstd_opt_argsr   ZUNIXY_COMPILER_INTERNAL_LIBSr•   Zinternal_libsrÍ   r>   Z	warn_argsZINVOKES_LINKERr:   rA   rD   rP   rS   rX   r[   r^   r`   ra   rd   rh   rk   ro   rw   rx   ry   r}   r   r‚   rƒ   r†   Úclassmethodrœ   rž   rŸ   r¤   rª   r´   r·   r¾   rÄ   rÅ   rÈ   rÏ   rÐ   rÒ   rÓ   r'   r'   r'   r+   r   Q   sv    ûû





















/










r   )Ú	metaclassc                      sX   e Zd ZdZdZd‡ fdd„Zdd‡ fdd„Zddd„Zd‡ fdd„Zddd„Z	‡  Z
S )ÚMSVCCompilerz$Specific to the Microsoft Compilers.rÑ   r%   r&   c                   sB   t ƒ  |¡ t | jd¡rd| jv rdd„ | jD ƒ| _d S d S d S )Nz<19.00r$   c                 S  rq   )r$   r'   )r)   Úrr'   r'   r+   rs   ®  rt   z)MSVCCompiler.__init__.<locals>.<listcomp>)Úsuperr:   r   r5   r6   r>   r8   ©Ú	__class__r'   r+   r:   §  s   ÿzMSVCCompiler.__init__Frµ   rC   rm   r;   r<   c                   s.   t ƒ  ||¡}|rt | jd¡rdg| }|S )Nz>=18.0z/FS)rå   r·   r   r5   r6   )r9   rµ   rC   rv   ræ   r'   r+   r·   °  s   
z'MSVCCompiler.get_compile_debugfile_argsc                 C  s   | j S r=   )r>   r@   r'   r'   r+   rA   ¾  r\   zMSVCCompiler.get_always_argsr¸   r¹   c                   s,   | j  d¡d dkr|dkrd S tƒ  |¡S )NrG   r   Z16r   )r6   rL   rå   r¾   r½   ræ   r'   r+   r¾   Á  s   z%MSVCCompiler.get_instruction_set_argsrF   c                 C  s   t j |¡S r=   )rI   rJ   rK   rR   r'   r'   r+   rS   É  s   zMSVCCompiler.get_pch_base_namerÔ   rÙ   rÚ   rÕ   rÛ   rÖ   )rÝ   rÞ   rß   rà   Úidr:   r·   rA   r¾   rS   Ú__classcell__r'   r'   ræ   r+   rã   ¡  s    	
rã   c                      s\   e Zd ZdZdZd ‡ fdd„Zd!‡ fdd„Zd"dd„Zd#dd„Zd$dd„Z	d%dd„Z
‡  ZS )&ÚClangClCompilerzSpecific to Clang-CL.zclang-clr%   r&   c                   s(   t ƒ  |¡ | j d¡ | j d¡ d S )Nr   Zsx)rå   r:   Zcan_compile_suffixesr7   r8   ræ   r'   r+   r:   Ó  s   zClangClCompiler.__init__rv   r<   r„   r…   r«   rf   r;   r¬   c                   s&   |dkr
|ddg }t ƒ  ||||¡S )Nr­   z-Werror=unknown-argumentz-Werror=unknown-warning-option)rå   r´   )r9   rv   r„   r«   rf   ræ   r'   r+   r´   Ú  s   zClangClCompiler.has_argumentsrÀ   c                 C  rB   )NrÁ   r'   r@   r'   r'   r+   rÅ   ß  rT   z#ClangClCompiler.get_toolset_versionrF   c                 C  s   |S r=   r'   rR   r'   r'   r+   rS   ã  rE   z!ClangClCompiler.get_pch_base_namerJ   r    rm   c                 C  s$   |dkrd}|rd| gS d| gS )Nr¡   rG   z/clang:-isystemr¢   r'   r£   r'   r'   r+   r¤   æ  s   z ClangClCompiler.get_include_argsÚdepú'Dependency'c                 C  sN   |  ¡ dkr#g }| ¡ D ]}| d¡r|d| g7 }q||g7 }q|S | ¡ S )NÚsystemr   z/clang:)Zget_include_typeZget_compile_argsr”   )r9   rë   Z	convertedrš   r'   r'   r+   Úget_dependency_compile_argsë  s   
z+ClangClCompiler.get_dependency_compile_argsrÔ   rØ   rÜ   rÖ   r×   )rë   rì   r;   r<   )rÝ   rÞ   rß   rà   rè   r:   r´   rÅ   rS   r¤   rî   ré   r'   r'   ræ   r+   rê   Í  s    


rê   )Ú
__future__r   ÚabcrI   ÚtypingÚTr¡   r   r   r   ÚTYPE_CHECKINGÚenvironmentr   Údependenciesr   Zcliker
   ZCompilerÚobjectr¼   rº   ru   rn   ÚABCMetar   rã   rê   r'   r'   r'   r+   Ú<module>   sd   ÷öùþ  R,