
    -Ph4                        d dl mZ d dlmZ d dlZd dlZd dlZd dlZd dlZ	e	j
        rddlmZ ddlmZ g dZ G d d	ej                  Z G d
 de	j        e                   ZdS )    )annotations)	lru_cacheN   )StaticLinker)Compiler)mcpthreaddlrtexecinfoc                      e Zd ZdZdZdZdZdS )Dedupa  What kind of deduplication can be done to compiler args.

    OVERRIDDEN - Whether an argument can be 'overridden' by a later argument.
        For example, -DFOO defines FOO and -UFOO undefines FOO. In this case,
        we can safely remove the previous occurrence and add a new one. The
        same is true for include paths and library paths with -I and -L.
    UNIQUE - Arguments that once specified cannot be undone, such as `-c` or
        `-pipe`. New instances of these can be completely skipped.
    NO_DEDUP - When it matters where or how many times on the command-line
        a particular argument is present. This can matter for symbol
        resolution in static or shared libraries, so we cannot de-dup or
        reorder them.
    r   r      N)__name__
__module____qualname____doc__NO_DEDUPUNIQUE
OVERRIDDEN     R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mesonbuild/arglist.pyr   r      s)          HFJJJr   r   c                  \   e Zd ZU dZdZded<   dZded<   dZded<   dZded<   dZ	ded<   d	Z
 ej        d
          ZdZded<    ed eD                       Z	 dEdFdZdGdZdHdZej        dId            Zej        dJd            ZdKd!Zej        dLd#            Zej        dMd%            ZdNd'ZdOd(ZdPd)ZdLd*ZdQd,Ze ed-          dRd0                        Ze ed-          dSd2                        Z dTdUd6Z!dVd7Z"dWd8Z#dWd9Z$dXd;Z%dXd<Z&dXd=Z'dYdAZ(dVdBZ)dZdCZ*d[dDZ+dS )\CompilerArgsa  
    List-like class that manages a list of compiler arguments. Should be used
    while constructing compiler arguments from various sources. Can be
    operated with ordinary lists, so this does not need to be used
    everywhere.

    All arguments must be inserted and stored in GCC-style (-lfoo, -Idir, etc)
    and can converted to the native type of each compiler by using the
    .to_native() method to which you must pass an instance of the compiler or
    the compiler class.

    New arguments added to this class (either with .append(), .extend(), or +=)
    are added in a way that ensures that they override previous arguments.
    For example:

    >>> a = ['-Lfoo', '-lbar']
    >>> a += ['-Lpho', '-lbaz']
    >>> print(a)
    ['-Lpho', '-Lfoo', '-lbar', '-lbaz']

    Arguments will also be de-duped if they can be de-duped safely.

    Note that because of all this, this class is not commutative and does not
    preserve the order of arguments if it is safe to not. For example:
    >>> ['-Ifoo', '-Ibar'] + ['-Ifez', '-Ibaz', '-Werror']
    ['-Ifez', '-Ibaz', '-Ifoo', '-Ibar', '-Werror']
    >>> ['-Ifez', '-Ibaz', '-Werror'] + ['-Ifoo', '-Ibar']
    ['-Ifoo', '-Ibar', '-Ifez', '-Ibaz', '-Werror']

    r   zT.Tuple[str, ...]prepend_prefixesdedup2_prefixesdedup2_suffixesdedup2_argsdedup1_prefixes)z.libz.dllz.soz.dylibz.az6([\/\\]|\A)lib.*\.so(\.[0-9]+)?(\.[0-9]+)?(\.[0-9]+)?$dedup1_argsc              #      K   | ]	}d |z   V  
dS )-lNr   ).0libs     r   	<genexpr>zCompilerArgs.<genexpr>_   s&      QQSdSjQQQQQQr   Ncompiler#T.Union['Compiler', 'StaticLinker']iterableT.Optional[T.Iterable[str]]c                    || _         t          |t                    r|                                 |j        }|t          |          ng | _        t          j                    | _        g | _	        d| _
        d S )NF)r(   
isinstancer   flush_pre_post
_containerlistcollectionsdequeprepostneeds_override_check)selfr(   r*   s      r   __init__zCompilerArgs.__init__a   ss     h-- 	+##%%%  *H9A9MtH~~~SU!,!2!4!4!#	*/!!!r   returnNonec                   | j         sr| j        r*| j        | j        dd<   | j                                         | j        r8| j                            | j                   | j                                         d S g }t                      }t          j                    }t                      }| j        D ]S}| 	                    |          }||vr8|
                    |           |t          j        u r|                    |           Tt          | j                  D ]S}| 	                    |          }||vr8|                    |           |t          j        u r|                    |           T| j        D ]}||vr||vr|
                    |            |                    |           || _        | j                                         | j                                         d| _         d S )Nr   F)r5   r3   r/   clearr4   extendsetr1   r2   
_can_dedupappendr   r   addreversed
appendleft)r6   newpre_flush_set
post_flushpost_flush_setadedups          r   r.   zCompilerArgs.flush_pre_postt   s   ( 	x !'+x!$   y "&&ty111	!!!F$'EE#.#4#6#6
%(UU  	) 	)AOOA&&E%%

1E,,,!%%a((($)$$ 	* 	*AOOA&&E&&%%a(((E,,,"&&q)))  	 	A&&1M+A+A

1

:	$)!!!r   T.Iterator[str]c                R    |                                   t          | j                  S N)r.   iterr/   r6   s    r   __iter__zCompilerArgs.__iter__   s$    DO$$$r   indexintstrc                    d S rK   r   r6   rO   s     r   __getitem__zCompilerArgs.__getitem__       r   sliceT.MutableSequence[str]c                    d S rK   r   rS   s     r   rT   zCompilerArgs.__getitem__   rU   r   T.Union[int, slice]$T.Union[str, T.MutableSequence[str]]c                D    |                                   | j        |         S rK   r.   r/   rS   s     r   rT   zCompilerArgs.__getitem__   s!    u%%r   valuec                    d S rK   r   r6   rO   r]   s      r   __setitem__zCompilerArgs.__setitem__   rU   r   T.Iterable[str]c                    d S rK   r   r_   s      r   r`   zCompilerArgs.__setitem__   rU   r   T.Union[str, T.Iterable[str]]c                B    |                                   || j        |<   d S rK   r\   r_   s      r   r`   zCompilerArgs.__setitem__   s&    !&r   c                >    |                                   | j        |= d S rK   r\   rS   s     r   __delitem__zCompilerArgs.__delitem__   s$    OE"""r   c                ~    t          | j                  t          | j                  z   t          | j                  z   S rK   )lenr/   r3   r4   rM   s    r   __len__zCompilerArgs.__len__   s,    4?##c$(mm3c$)nnDDr   c                d    |                                   | j                            ||           d S rK   )r.   r/   insertr_   s      r   rk   zCompilerArgs.insert   s2    ue,,,,,r   'CompilerArgs'c                    |                                    t          |           | j        | j                                                  S rK   )r.   typer(   r/   copyrM   s    r   ro   zCompilerArgs.copy   s<    tDzz$-)=)=)?)?@@@r   )maxsizeargr   c                   || j         v s	|| j        v rt          j        S || j        v s4|                    | j                  s|                    | j                  rt          j        S || j	        v sN|                    | j                   s4|                    | j
                  st          j        | j        |          rt          j        S t          j        S )a<  Returns whether the argument can be safely de-duped.

        In addition to these, we handle library arguments specially.
        With GNU ld, we surround library arguments with -Wl,--start/end-group
        to recursively search for symbols in the libraries. This is not needed
        with other linkers.
        )r!   r   r   r   r    
startswithendswithr   r   r"   dedup1_suffixesresearchdedup1_regexr   clsrq   s     r   r>   zCompilerArgs._can_dedup   s    ( #%%%0C)C)C>!#/!!>>#-.. "<<+,, " ###/!!>>#-.. "<<+,, " 9S%s++ " <~r   boolc                6    |                     | j                  S rK   )rs   r   ry   s     r   _should_prependzCompilerArgs._should_prepend   s     ~~c2333r   Fro   T.List[str]c                    |                                   |r|                                 }n| }| j                            |j                  S rK   )r.   ro   r(   unix_args_to_nativer/   )r6   ro   rC   s      r   	to_nativezCompilerArgs.to_native   sJ    
 	 	))++CCC}00@@@r   c                    |                                   t          j                            |          r|                     |           dS | j                            |           dS )z
        Append the specified argument without any reordering or de-dup except
        for absolute paths to libraries, etc, which can always be de-duped
        safely.
        N)r.   ospathisabsr?   r/   r6   rq   s     r   append_directzCompilerArgs.append_direct   s`     	7== 	(KKO""3'''''r   c                b    |                                   |D ]}|                     |           dS )z
        Extend using the elements in the specified iterable without any
        reordering or de-dup except for absolute paths where the order of
        include search directories is not relevant
        N)r.   r   )r6   r*   elems      r   extend_directzCompilerArgs.extend_direct  sF     	 	% 	%Dt$$$$	% 	%r   c                (   g }g }|D ]`}|| j         vr@|                    d          s|                    d          r|                    |           K|                    |           a|                     |           |                     |           d S )Nr$   z-L)always_dedup_argsrs   r?   r<   r   )r6   r*   normal_flagslflagsis        r   extend_preserving_lflagsz%CompilerArgs.extend_preserving_lflags  s     	' 	'A...ALL4F4F.!,,W[J\J\.a    ##A&&&&L!!!6"""""r   argsc                `    |                                   |                                 }||z  }|S rK   )r.   ro   r6   r   rC   s      r   __add__zCompilerArgs.__add__  s/    iikkt
r   c                   t          j                    }t          |t           j        j                  st          d| d          |D ]}|                     |          }|t          j        u r|| j	        v s|| j
        v s	|| j        v rAn|t          j        u rd| _        |                     |          r|                    |           | j                            |           | j
                            |           | S )z
        Add two CompilerArgs while taking into account overriding of arguments
        and while preserving the order of arguments as much as possible
        z)can only concatenate Iterable[str] (not "z") to CompilerArgsT)r1   r2   r-   abcIterable	TypeErrorr>   r   r   r/   r3   r4   r   r5   r}   rB   r?   
extendleft)r6   r   tmp_prerq   rH   s        r   __iadd__zCompilerArgs.__iadd__"  s   
 !, 1 3 3$ 899 	b````aaa 	& 	&C OOC((E$$$/))SDH__ty@P@P AQ%***,0)##C(( &""3''''	  %%%%G$$$r   c                t    |                                    t          |           | j        |          }|| z  }|S rK   )r.   rn   r(   r   s      r   __radd__zCompilerArgs.__radd__=  s;    d4jj--t
r   otherobjectT.Union[bool]c                    |                                   t          |t                    r | j        |j        k    o| j        |j        k    S t          |t
                    r| j        |k    S t          S rK   )r.   r-   r   r(   r/   r0   NotImplemented)r6   r   s     r   __eq__zCompilerArgs.__eq__C  si    e\** 	,=EN2Zt%JZ7ZZt$$ 	,?e++r   c                    | |gz  } d S rK   r   r   s     r   r?   zCompilerArgs.appendL  s    r   c                    | |z  } d S rK   r   )r6   r   s     r   r<   zCompilerArgs.extendO  s    r   c                P    |                                   d| j        d| j        dS )NzCompilerArgs(z, ))r.   r(   r/   rM   s    r   __repr__zCompilerArgs.__repr__R  s1    Ft}FF$/FFFFr   rK   )r(   r)   r*   r+   )r8   r9   )r8   rI   )rO   rP   r8   rQ   )rO   rV   r8   rW   )rO   rY   r8   rZ   )rO   rP   r]   rQ   r8   r9   )rO   rV   r]   ra   r8   r9   )rO   rY   r]   rc   r8   r9   )rO   rY   r8   r9   )r8   rP   )r8   rl   )rq   rQ   r8   r   )rq   rQ   r8   r{   )F)ro   r{   r8   r~   )rq   rQ   r8   r9   )r*   ra   r8   r9   )r   ra   r8   rl   )r   r   r8   r   )r   ra   r8   r9   )r8   rQ   ),r   r   r   r   r   __annotations__r   r   r    r!   ru   rv   compilerx   r"   tupleUNIXY_COMPILER_INTERNAL_LIBSr   r7   r.   rN   ToverloadrT   r`   rf   ri   rk   ro   classmethodr   r>   r}   r   r   r   r   r   r   r   r   r?   r<   r   r   r   r   r   r   +   ss         > +-,,,, *,O++++)+O++++%'K'''' *,O++++=O 2:WXXL%'K'''' QQ4PQQQQQ :>0 0 0 0 0&'* '* '* '*R% % % %
 Z   Z Z   Z& & & & Z   Z Z   Z' ' ' '# # # #E E E E- - - -A A A A Yt    [> Yt4 4 4  [4
A 
A 
A 
A 
A
( 
( 
( 
(% % % %	# 	# 	# 	#      6            G G G G G Gr   r   )
__future__r   	functoolsr   r1   enumr   rv   typingr   TYPE_CHECKINGlinkers.linkersr   	compilersr   r   Enumr   MutableSequencerQ   r   r   r   r   <module>r      s  
 # " " " " "            				 				    ? $------######  MLL     DI   *iG iG iG iG iG1$S) iG iG iG iG iGr   