
    -PhP                       U 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	 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ed<   dgdgdgdgdgdgdgdgdgdd
Zded<   g dgg dgdgddgddgdZded<   g dgdZd ed!<    G d" d#eej        $          Z G d% d&e          Z  G d' d(e          Z!dS ))    )annotationsN   )arglist)mesonlib)mlog)CompileCheckMode	OptionKey)ClangClDynamicLinker)Environment)
Dependency   )CLikeCompilerz	/arch:SSEz
/arch:SSE2z	/arch:AVXz
/arch:AVX2)	mmxssesse2sse3sse41sse42avxavx2neonz$T.Dict[str, T.Optional[T.List[str]]]vs32_instruction_set_args)
r   r   r   r   ssse3r   r   r   r   r   vs64_instruction_set_args/Odz/O1/O2/Gw)plain0g123sT.Dict[str, T.List[str]]msvc_optimization_argsz/Zi)FTzT.Dict[bool, T.List[str]]msvc_debug_argsc                     e Zd ZU dZdgZdgZej        dgz   Zg Z	de
d<   g dgdgd	gd
gdZde
d<   g dZg dgdgdgdgdZde
d<   dZd_dZd`dZdadZdbdZdcdZddd Zd`d!Zd`d"Zd`d#Zd`d$Zded&Zdfd(Zdgd+Zdhd-Zdid/Zd`d0Zdjd2Zdkd6Z dld9Z!dld:Z"dmd<Z#e$did=            Z%e$did>            Z&d`d?Z'dndBZ(dodEZ)dpdJZ*dqdrdMZ+dsdPZ,dtdTZ-dudUZ.d`dVZ/dvdYZ0dwdZZ1e2dad[            Z3dxd\Z4d`d]Z5d^S )y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   execinfoT.List[str]internal_libsz/MDz/MDdz/MTz/MTd)nonemdmddmtmtdr&   crt_args)z/nologoz/showIncludes/utf-8z/W2z/W4z/Wall)r    r"   r#   r$   
everything	warn_argsFtargetstrc                t   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 rd	| _        n|| _        t	          j        | j        d
          r'| j                             t          d                     | j	        J | j        | j	        _        d S )Nc                ,    h | ]}t          |          S  r	   ).0os     h/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mesonbuild/compilers/mixins/visualstudio.py	<setcomp>z4VisualStudioLikeCompiler.__init__.<locals>.<setcomp>t   s    TTTaYq\\TTT    )b_pchb_ndebugb_vscrtx64x86_6486x86aarch64arm64armz>=19.28.29910
b_sanitize)
base_optionsr7   is_64machiner   version_compareversionaddr
   linker)selfr7   s     r>   __init__z!VisualStudioLikeCompiler.__init__s   s    TT3STTTvo>8v+=
v DLLV^^ DLL&  "DLLf__ DLL!DL#DL/BB 	;!!)L"9"9:::{&&&"lr@   returnc                4    | j                                         S N)always_argscopyrS   s    r>   get_always_argsz(VisualStudioLikeCompiler.get_always_args   s    $$&&&r@   c                    dS )Npchr;   rZ   s    r>   get_pch_suffixz'VisualStudioLikeCompiler.get_pch_suffix   s    ur@   namec                    t           j                            |                              d          d d         }|                    |                                            d                    |          }|S )N.)ospathbasenamesplitappendr^   join)rS   r_   choppedpchnames       r>   get_pch_namez%VisualStudioLikeCompiler.get_pch_name   sb    '""4((..s33CRC8t**,,---((7##r@   headerc                    t           rW   )NotImplementedErrorrS   rl   s     r>   get_pch_base_namez*VisualStudioLikeCompiler.get_pch_base_name   s    !!r@   pch_dirc                    |                      |          }|                     |          }d|z   d|z   dt          j                            ||          z   gS )Nz/FIz/Yu/Fp)rp   rk   rc   rd   rh   )rS   rq   rl   baserj   s        r>   get_pch_use_argsz)VisualStudioLikeCompiler.get_pch_use_args   sR    %%f--##F++edlEBGLL'4R4R,RSSr@   c                    dgS )N/EPr;   rZ   s    r>   get_preprocess_only_argsz1VisualStudioLikeCompiler.get_preprocess_only_args   	    wr@   c                
    ddgS )Nrw   z/Pr;   rZ   s    r>   get_preprocess_to_file_argsz4VisualStudioLikeCompiler.get_preprocess_to_file_args   s    t}r@   c                    dgS )Nz/cr;   rZ   s    r>   get_compile_only_argsz.VisualStudioLikeCompiler.get_compile_only_args   s	    vr@   c                
    ddgS )Nr   z/Oi-r;   rZ   s    r>   get_no_optimization_argsz1VisualStudioLikeCompiler.get_no_optimization_args   s    vr@   valuec                <    |s|S dd                     |           gS )Nz/fsanitize=,)rh   )rS   r   s     r>   sanitizer_compile_argsz/VisualStudioLikeCompiler.sanitizer_compile_args   s*     	L/chhuoo//00r@   
outputnamec                f    | j         dk    rd|z   gS |                    d          rd|z   gS d|z   gS )NPREPROCESSORz/Fiz.exez/Fe/Fo)modeendswith)rS   r   s     r>   get_output_argsz(VisualStudioLikeCompiler.get_output_args   sO    9&&J&''v&& 	(J&''
"##r@   is_debugboolc                    t           |         S rW   )r(   )rS   r   s     r>   get_debug_argsz'VisualStudioLikeCompiler.get_debug_args   s    x((r@   optimization_levelc                l    t           |         }t          j        | j        d          rd |D             }|S )Nz<18.0c                    g | ]
}|d k    |S )r   r;   )r<   args     r>   
<listcomp>zBVisualStudioLikeCompiler.get_optimization_args.<locals>.<listcomp>   s    888C3%<<C<<<r@   )r'   r   rO   rP   )rS   r   argss      r>   get_optimization_argsz.VisualStudioLikeCompiler.get_optimization_args   s<    %&89#DL':: 	9884888Dr@   r   c                    dg|z   S )Nz/linkr;   )rS   r   s     r>   linker_to_compiler_argsz0VisualStudioLikeCompiler.linker_to_compiler_args   s    y4r@   c                    g S rW   r;   rZ   s    r>   get_pic_argsz%VisualStudioLikeCompiler.get_pic_args       	r@   defsfilec                V    t          |t                    st          d          d|z   gS )Nz%Module definitions file should be strz/DEF:)
isinstancer8   RuntimeError)rS   r   s     r>   gen_vs_module_defs_argsz0VisualStudioLikeCompiler.gen_vs_module_defs_args   s4    (C(( 	HFGGG ("##r@   sourcerj   T.Tuple[str, T.List[str]]c                r    t           j                            |          d         dz   }|d|z   d|z   d|z   gfS )Nr   z.objz/Ycrs   r   )rc   rd   splitext)rS   rl   r   rj   objnames        r>   gen_pch_argsz%VisualStudioLikeCompiler.gen_pch_args   s?    '""6**1-6%'/JJJr@   envr   c                    dgS )Nz/openmpr;   rS   r   s     r>   openmp_flagsz%VisualStudioLikeCompiler.openmp_flags   s
    {r@   c                    g S rW   r;   r   s     r>   openmp_link_flagsz*VisualStudioLikeCompiler.openmp_link_flags   r   r@   'Environment'c                    g S rW   r;   r   s     r>   thread_flagsz%VisualStudioLikeCompiler.thread_flags   r   r@   c                   g }|D ]}|dv r|                     d          rd|dd          z   }n>|                     d          rd|dd          z   }n|                     d          r|dd          }|| j        v ry|dz   }n|                     d	          r1|                     d
          rd|dd          z   }nd|dd          z   }n|                     d          r1|                     d          rd|dd          z   }nmd|dd          z   }n_|dk    r|                     d          s|                     d          s|dk    r'	 |                    d           n# t          $ r Y nw xY w|                    |           |S )N>   -mms-bitfields-pthread	-LIBPATH:	/LIBPATH:	   -L   -l.lib-isystemz	-isystem=/I   z
-idirafterz-idirafter=   
   r   z/source-charset:z/execution-charset:z/validate-charset-r4   )
startswithignore_libsremove
ValueErrorrg   )clsr   resultir_   s        r>   unix_args_to_nativez,VisualStudioLikeCompiler.unix_args_to_native   s     *	 *	A 222||K(( $!ABB%'d## "!ABB%'d## u3?** vAAj)) <<,, %quAAquAAl++ <<.. &qvAAqvAAj ,,122 ||$9::000MM(++++!   DMM!s   	E
E,+E,c                D   g }|D ]}|                     d          r!|                    d|dd          z              8|                    d          r8t          j                            |          s|                    d|z              |                    |           |S )N)r   r   r   r   )z.ar   r   )r   rg   r   rc   rd   isabs)r   r   r   r   s       r>   native_args_to_unixz,VisualStudioLikeCompiler.native_args_to_unix
  s      	# 	#C~~899 #dSWn----n-- #bgmmC6H6H #dSj))))c""""r@   c                    dgS )Nz/WXr;   rZ   s    r>   get_werror_argsz(VisualStudioLikeCompiler.get_werror_args  ry   r@   rd   	is_systemc                    |dk    rd}d|z   gS )N ra   -Ir;   rS   rd   r   s      r>   get_include_argsz)VisualStudioLikeCompiler.get_include_args  s    2::Dt}r@   parameter_list	build_dirc           
        t          |          D ]\  }}|d d         dk    s|d d         dk    rT|d d         t          j                            t          j                            ||dd                              z   ||<   u|d d         dk    rS|d d         t          j                            t          j                            ||dd                              z   ||<   |S )Nr   r   r   r   r   )	enumeraterc   rd   normpathrh   )rS   r   r   idxr   s        r>   &compute_parameters_with_absolute_pathsz?VisualStudioLikeCompiler.compute_parameters_with_absolute_paths  s    // 	_ 	_FC!u}}"1"&'ebg.>.>rw||IWXYZY[Y[W\?]?].^.^&^s##2A2+%%&'ebg.>.>rw||IWXYZY[Y[W\?]?].^.^&^s#r@   coder   r   T.Tuple[bool, bool]c                   |t           j        k    rdnd}|                     ||||          5 }|j        dk    rd|j        fcd d d            S ||j        v p||j        v  |j        fcd d d            S # 1 swxY w Y   d S )N40449002)
extra_argsr   r   F)r   LINK_build_wrapper
returncodecachedstderrstdout)rS   r   r   r   r   warning_textps          r>   has_argumentsz&VisualStudioLikeCompiler.has_arguments+  s   !%)9)>!>!>vvF  st$ GG 	X1|q  ah	X 	X 	X 	X 	X 	X 	X 	X %0LLAH4LMqxW	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	X 	Xs   A5A55A9<A9rel_objr]   c                ~    |                     d          d d         }|dgz  }dd                    |          z   g}|S )Nra   rb   pdbz/Fd)rf   rh   )rS   r   r]   pdbarrr   s        r>   get_compile_debugfile_argsz3VisualStudioLikeCompiler.get_compile_debugfile_args2  sF    s##CRC(5'((()r@   instruction_setT.Optional[T.List[str]]c                |    | j         rt                              |d           S t                              |d           S rW   )rM   r   getr   )rS   r   s     r>   get_instruction_set_argsz1VisualStudioLikeCompiler.get_instruction_set_args8  s9    : 	H,00$GGG(,,_dCCCr@   rP   intT.Optional[str]c                    |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     rdS |dk     rdS |dk     rdS |dk     rdS |dk     rdS t          j        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.3i  z14.4z#Could not find toolset for version )r   warningrP   rS   rP   s     r>   _calculate_toolset_versionz3VisualStudioLikeCompiler._calculate_toolset_version=  s    T>>5t^^5t^^5t^^5t^^6t^^6t^^6t^^6t^^6t^^6t^^6t^^6K4<KKLLLtr@   c                    	 t          d                    | j                            d          dd                             }n# t          $ r Y d S w xY w|                     |          S )Nr   ra   r   r   )r   rh   rP   rf   r   r   r   s     r>   get_toolset_versionz,VisualStudioLikeCompiler.get_toolset_versionY  sq    	"''$,"4"4S"9"9!A#">??@@GG 	 	 	44	..w777s   AA 
AAc                    dt           j        vrg S t           j        d                             t           j                  S )NINCLUDE)rc   environrf   pathseprZ   s    r>   get_default_include_dirsz1VisualStudioLikeCompiler.get_default_include_dirsa  s1    BJ&&Iz)$**2:666r@   crt_val	buildtypec                H    |                      ||          }| j        |         S rW   )get_crt_valr3   )rS   r   r   s      r>   get_crt_compile_argsz-VisualStudioLikeCompiler.get_crt_compile_argsf  s$    ""7I66}W%%r@   c                    |dv dfS )N>   	dllexport	dllimportFr;   )rS   r_   r   s      r>   has_func_attributez+VisualStudioLikeCompiler.has_func_attributej  s     11588r@   c                     dS )Nmsvcr;   r;   r@   r>   get_argument_syntaxz,VisualStudioLikeCompiler.get_argument_syntaxo      vr@   c                ^    |                      |          }||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.
        )$_symbols_have_underscore_prefix_list)_symbols_have_underscore_prefix_searchbin)rS   r   r   s      r>   symbols_have_underscore_prefixz7VisualStudioLikeCompiler.symbols_have_underscore_prefixs  s8     ::3??M ==cBBBr@   c                    g S rW   r;   rZ   s    r>   get_pie_argsz%VisualStudioLikeCompiler.get_pie_args  r   r@   Nr7   r8   rU   r,   )rU   r8   )r_   r8   rU   r8   rl   r8   rU   r8   )rq   r8   rl   r8   rU   r,   )r   r,   rU   r,   )r   r8   rU   r,   )r   r   rU   r,   )r   r8   rU   r,   r   r,   rU   r,   )r   r8   rU   r,   )rl   r8   r   r8   rj   r8   rU   r   r   r   rU   r,   )r   r   rU   r,   rd   r8   r   r   rU   r,   )r   r,   r   r8   rU   r,   
r   r,   r   r   r   r8   r   r   rU   r   Fr   r8   r]   r   rU   r,   r   r8   rU   r   )rP   r   rU   r   rU   r   )r   r8   r   r8   rU   r,   )r_   r8   r   r   rU   r   )r   r   rU   r   )6__name__
__module____qualname____doc__std_warn_argsstd_opt_argsr   UNIXY_COMPILER_INTERNAL_LIBSr   r-   __annotations__r3   rX   r6   INVOKES_LINKERrT   r[   r^   rk   rp   ru   rx   r{   r}   r   r   r   r   r   r   r   r   r   r   r   r   classmethodr   r   r   r   r   r   r   r   r   r   r   r  r  staticmethodr
  r  r  r;   r@   r>   r*   r*   K   s          GM7L6*EK!#M#### gxgx* *H     988KWWWi+ +I     N+ + + +*' ' ' '      " " " "T T T T
            1 1 1 1
$ $ $ $) ) ) )             $ $ $ $K K K K          - - - [-^ 	 	 	 [	         X X X X    D D D D
   88 8 8 87 7 7 7
& & & &9 9 9 9
    \C C C C"     r@   r*   )	metaclassc                  Z     e Zd ZdZdZd fdZdd fdZddZd fdZddZ	ddZ
 xZS )MSVCCompilerz$Specific to the Microsoft Compilers.r	  r7   r8   c                    t                                          |           t          j        | j        d          r!d| j        v rd | j        D             | _        d S d S d S )Nz<19.00r4   c                    g | ]
}|d k    |S )r4   r;   )r<   rs     r>   r   z)MSVCCompiler.__init__.<locals>.<listcomp>  s    MMMaqH}}}}}r@   )superrT   r   rO   rP   rX   rS   r7   	__class__s     r>   rT   zMSVCCompiler.__init__  ss       
 #DL(;; 	NDL\@\@\MM4+;MMMD	N 	N@\@\r@   Fr   r]   r   rU   r,   c                    t                                          ||          }|r t          j        | j        d          rdg|z   }|S )Nz>=18.0z/FS)r.  r   r   rO   rP   )rS   r   r]   r   r0  s       r>   r   z'MSVCCompiler.get_compile_debugfile_args  sL    ww11'3??  	"8+DL(CC 	"7T>Dr@   c                    | j         S rW   )rX   rZ   s    r>   r[   zMSVCCompiler.get_always_args  s    r@   r   r   c                    | j                             d          d         dk    r|dk    rd S t                                          |          S )Nra   r   16r   )rP   rf   r.  r   )rS   r   r0  s     r>   r   z%MSVCCompiler.get_instruction_set_args  sL    <c""1%--/U2J2J 4ww//@@@r@   rl   c                @    t           j                            |          S rW   )rc   rd   re   ro   s     r>   rp   zMSVCCompiler.get_pch_base_name  s    w'''r@   c                    dS )NTr;   rZ   s    r>   should_link_pch_objectz#MSVCCompiler.should_link_pch_object  s    tr@   r  r  r  r  r  r  )rU   r   )r  r  r  r   idrT   r   r[   r   rp   r7  __classcell__r0  s   @r>   r*  r*    s        ..	BN N N N N N
 
 
 
 
 
 
       A A A A A A( ( ( (
       r@   r*  c                       e Zd ZdZdZd+ fdZd, fdZd-dZd.dZd/dZ	e
d0 fd            Zd1 fdZd2dZd3 fd Zd!d"d#d4 fd&Zd!d"d'd(d5d*Z xZS )6ClangClCompilerzSpecific to Clang-CL.zclang-clr7   r8   c           	     r   t                                          |           | j                            t	          d          t	          d          t	          d          t	          d          t	          d          h           | j                            d           | j                            d           d S )Nb_lto_threadsb_lto
b_lto_modeb_thinlto_cacheb_thinlto_cache_dirr%   sx)r.  rT   rL   updater
   can_compile_suffixesrQ   r/  s     r>   rT   zClangClCompiler.__init__  s         ''7););Y|=T=TV_`qVrVr,--/	0 	0 	0
 	!%%c***!%%d+++++r@   r   r,   r   r   r   r   r   rU   r   c                z    |t           j        k    r|ddgz   }t                                          ||||          S )Nz-Werror=unknown-argumentz-Werror=unknown-warning-option)r   r   r.  r   )rS   r   r   r   r   r0  s        r>   r   zClangClCompiler.has_arguments  sA    #(((57WXXDww$$T3d;;;r@   r   c                    dS )Nr   r;   rZ   s    r>   r   z#ClangClCompiler.get_toolset_version  r  r@   rl   c                    |S rW   r;   ro   s     r>   rp   z!ClangClCompiler.get_pch_base_name  s    r@   rd   r   r   c                .    |dk    rd}|rd|z   gnd|z   gS )Nr   ra   z/clang:-isystemr   r;   r   s      r>   r   z ClangClCompiler.get_include_args  s/    2::D-6I!D())TD[MIr@   rR   rP   c                Z    |dk    rdgS t                                          ||          S )Nzlld-linkz-fuse-ld=lld-link)r.  use_linker_args)r   rR   rP   r0  s      r>   rK  zClangClCompiler.use_linker_args  s3     Z'((ww&&vw777r@   c                    t                                          | j        j        d          t                                          d |D                       z   S )Nr   c                P    g | ]#}|                     d           r
|dd         n|$S )z-Wl,   N)r   )r<   flags     r>   r   z;ClangClCompiler.linker_to_compiler_args.<locals>.<listcomp>  sq      ^^  ^^  ^^  QUjnjyjy  {A  kB  kB  _L^bcdcece^f^f  HL  ^^  ^^  ^^r@   )r.  rK  rR   r8  r   )rS   r   r0  s     r>   r   z'ClangClCompiler.linker_to_compiler_args  sn     ww&&t{~r::UWW=\=\  ^^  ^^  Y]  ^^  ^^  ^^  >_  >_  _  	_r@   dep'Dependency'c                    |                                 dk    r@g }|                                D ]'}|                    d          r
|d|z   gz  }!||gz  }(|S |                                S )Nsystemr   z/clang:)get_include_typeget_compile_argsr   )rS   rP  	convertedr   s       r>   get_dependency_compile_argsz+ClangClCompiler.get_dependency_compile_args  s    !!X--%'I))++ % %<<
++ %)a-0II!$II'')))r@   r   c                    |                      d|g           }|t          j        d          t                                          |          |z   S )NlibompzCould not find libomp)find_libraryr   MesonBugExceptionr.  r   )rS   r   libsr0  s      r>   r   z!ClangClCompiler.openmp_link_flags  sN      333<,-DEEEww((--44r@   r   default)threadsr   r^  r   c               J   g }|dk    rTt          | j        t                    s!t          j        d| j        j                   |                    d|            nE|dk    s
J d            |                    t                      	                    |                     |S )Nthinz-LLVM's ThinLTO only works with lld-link, not z-flto=r]  z#someone forgot to wire something up)r^  )
r   rR   r   r   MesonExceptionr8  rg   extendr.  get_lto_compile_args)rS   r^  r   r   r0  s       r>   rc  z$ClangClCompiler.get_lto_compile_args  s    6>>dk+?@@ p-.n^b^i^l.n.noooKK((((9$$$&K$$$KK44W4EEFFFr@   N)r^  r   thinlto_cache_dirrd  c                   g }|dk    r/|-|                     | j                            |                     |dk    r|                    d|            |S )Nr`  r   z	/threads:)rb  rR   get_thinlto_cache_argsrg   )rS   r^  r   rd  r   s        r>   get_lto_link_argsz!ClangClCompiler.get_lto_link_args  sd    6>>/;KK::;LMMNNNQ;; KK-G--...r@   r  r  r  r  r  )rR   r8   rP   r8   rU   r,   r  )rP  rQ  rU   r,   r  )r^  r   r   r8   rU   r,   )r^  r   r   r8   rd  r   rU   r,   )r  r  r  r   r8  rT   r   r   rp   r   r&  rK  r   rW  r   rc  rg  r9  r:  s   @r>   r<  r<    s}       	B	, 	, 	, 	, 	, 	,< < < < < <
      J J J J
 8 8 8 8 8 [8_ _ _ _ _ _

* 
* 
* 
*5 5 5 5 5 5 67I 
 
 
 
 
 
 
 
 34?C
 
 
 
 
 
 
 
 
 
r@   r<  )"
__future__r   abcrc   typingTr   r   r   r   mesonbuild.compilers.compilersr   optionsr
   mesonbuild.linkers.linkersr   TYPE_CHECKINGenvironmentr   dependenciesr   cliker   Compilerobjectr   r$  r   r'   r(   ABCMetar*   r*  r<  r;   r@   r>   <module>rv     s  
 # " " " " " " 


 				                       ; ; ; ; ; ;             ; ; ; ; ; ;? 	************0000000 H ==NM]]=N
C 
C  
 
 
 
 ==MM]]]=NC C      
	



4 4      '. .    z z z z zx3; z z z zx	. . . . .+ . . .`W W W W W. W W W W Wr@   