
    -PhH                       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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mZ e	j        rddlmZ dd	lmZ  G d
 dej                  Z G d de          Z G d de          Z	 	 d!d"d ZdS )#    )annotationsN)Path   )mesonlib)mlog)MachineChoice
OrderedSet)Environment)Interpreterc                  $   e Zd ZdZdZej        Z	 	 	 d1d2dZd3dZ	d4dZ
d4dZd5d6dZed7d            Ze ej        d          d8d                        Zed9d!            Zed:d#            Zd;d$Zd<d(Zd=d*Zd>d+Zd?d,Zd@d.ZdAd/Zd4d0ZdS )BExternalPrograma  A program that is found on the system.
    :param name: The name of the program
    :param command: Optionally, an argument list constituting the command. Used when
              you already know the command and do not want to search.
    :param silent: Whether to print messages when initializing
    :param search_dirs: A list of directories to search in first, followed by PATH
    :param exclude_paths: A list of directories to exclude when searching in PATH)exemsccombatcmdNFnamestrcommandT.Optional[T.List[str]]silentboolsearch_dirs#T.Optional[T.List[T.Optional[str]]]exclude_pathsc           
     z   || _         d | _        d | _        d| _        |t	          j        |          | _        t	          j                    r| j        d         }| j        dd          }|                     |          }|r||z   | _        nt          j        
                    |          rSt          j                            |          s4| j        D ],}	| d|	 }
t          j                            |
          r|
} n-|g|z   | _        n!|d g}|                     |||          | _        |                                 rSt          | j                  D ],}|(t          j                            |          r	|| _         n-| j        d         | _        |s|                                 rYt#          j        dt#          j        |          dt#          j        d          d	d
                    | j                  z             d S t#          j        dt#          j        |          dt#          j        d                     d S d S )Nz	--versionr   r   .Programzfound:YESz(%s) NO)r   pathcached_versionversion_argr   listifyr   
is_windows_shebang_to_cmdosisabsexistswindows_exts_searchfoundreversedisfiler   logboldgreenjoinred)selfr   r   r   r   r   r   argsretext	trial_extargs               S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mesonbuild/programs.py__init__zExternalProgram.__init__'   s8    	%)	/3&#+G44DL"$$ 0l1o|ABB' **3// 0#&:DLLw}}S)) &"'..2E2E & $(#4 & &C+.I!w~~i88 &&/ %& %(54<DL"#f<<k=IIDL::<< 		-  -- - -?rw~~c':':? #DIE L,	 	O zz|| ODIdOOXtz%?P?P#((4<"8"88: : : : : DIdOOXtx~~NNNNN	O 	O    return T.Union[str, mlog.AnsiDecorator]c                `    |                                  st          j        d          S | j        S )Nr"   )r.   r   r5   r#   r6   s    r<   summary_valuezExternalProgram.summary_value^   s(    zz|| 	"8D>>!yr>   c                \    d}|                     | j        j        | j        | j                  S Nz<{} {!r} -> {!r}>format	__class____name__r   r   r6   rs     r<   __repr__zExternalProgram.__repr__c   &    xx/DLIIIr>   c                6    d                     | j                  S )z)Human friendly description of the commandr!   )r4   r   rB   s    r<   descriptionzExternalProgram.descriptiong   s    xx%%%r>   interpreterT.Optional['Interpreter']c                   | j         sB|                                 | j        gz   }|rC|                    | | j        gfddt	          j                    dd          }|j        |j        }}nWt	          j        |          \  }}}|j	        dk    r4t	          j
        |          }t	          j        d|d|j	         d          |                                }|s|                                }t          j        d|          }	|	st          j        d|          }	|	st	          j        d	|          |	                    d
          | _         | j         S )NT)capturecheckenvr   zCommand z failed with status r   z([0-9]+(\.[0-9]+)+)z([0-9][0-9\.]+)z-Could not find a version number in output of r   )r$   get_commandr%   run_command_implr   EnvironmentVariablesstdoutstderr
Popen_safe
returncode	join_argsMesonExceptionstripresearchgroup)
r6   rP   raw_cmdresoepcmd_stroutputmatchs
             r<   get_versionzExternalProgram.get_versionk   sq   " 	1&&((D,<+==G m!22D4;K:L3M?C=A;C;X;Z;Z4\ 4\ 48	9 9
 z3:1"-g661a<1$$&099G"12kW2k2k\]\h2k2k2klllWWYYF #I4f==E >	"4f== k-.i^e.i.ijjj"'++a..D""r>   rU   'Environment'for_machiner   'ExternalProgram'c                z    |                     ||          }|t                      S |                     ||          S N)lookup_binary_entryNonExistingExternalProgram
from_entry)clsrU   rm   r   r   s        r<   from_bin_listzExternalProgram.from_bin_list   s>     ))+t<<?-///~~dG,,,r>   )maxsizer#   c                   dt           j        vr| S t          t           j        d                   dz  dz  dz  dz  }g }|                     t           j                  D ]u}t          |          |k    r|                    |           +dt          j        v r<|                    t           j        	                    t          j                             vt           j        
                    |          S )NUSERPROFILEAppDataLocal	MicrosoftWindowsApps)r)   environr   splitpathsepappendsys
executabler#   dirnamer4   )r#   appstore_dirpathseachs       r<   _windows_sanitize_pathz&ExternalProgram._windows_sanitize_path   s     
**K BJ}566BWL{Z]jjJJrz** 	> 	>DDzz\))T""""#.00RW__S^<<===zu%%%r>   T.Union[str, T.List[str]]c                n   t          |t                    rt          |          dk    r|d         }t          |t                    st          j                            |          r*t          |t                    r|g}t          | |d          S t          |t                    sJ t          |d          S )Nr   r   T)r   r   )r   )
isinstancelistlenr)   r#   r*   r   r   )r   r   s     r<   rs   zExternalProgram.from_entry   s    gt$$ 	%7||q  !!* gt$$ 	Gg(>(> 	G'3'' $")"4FFFF'3'''''wt4444r>   scriptc                   	 t          | d          5 }|                                                                }ddd           n# 1 swxY w Y   |                    d          r|dd                             d          d                                                             d	          }t          j                    r|d                             d
          r$|d                             d
          d         |d<   t          |          dk    r|d         dk    r
|dd         }t          |          dk    r#|d         dk    rt
          j        |dd         z   }nt          j	                    rM|d         dk    r
|dd         }t          |          dk    r#|d         dk    rt
          j        |dd         z   }nl|d         dk    r$|d         dk    rt
          j        |dd         z   }n<|d                             d
          d         dk    rt
          j        |dd         z   }|| gz   S n8# t          $ r+}t          j        t          |                     Y d}~nd}~ww xY wt          j        d|            dS )z
        Check if the file has a shebang and manually parse it to figure out
        the interpreter to use. This is useful if the script is not executable
        or if we're on Windows (which does not understand shebangs).
        zutf-8)encodingNz#!   #r   r   )maxsplit/r   rU   python3z/usr/bin/envzUnusable script )openreadliner_   
startswithr~   r   r'   r   python_commandis_haiku	Exceptionr   debugr   )r   f
first_linecommandsrf   s        r<   r(   zExternalProgram._shebang_to_cmd   s   $	fw/// 21ZZ\\//11
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2$$T** +
 &abb>//44Q7==??EEqEQQ&(( J  {--c22 A&.qk&7&7&<&<R&@8}}q((Xa[E-A-A#+ABB<8}}q((Xa[I-E-E#+#:Xabb\#I&(( J  {n44#+ABB<8}}q((Xa[I-E-E#+#:Xabb\#I  {n44!	9Q9Q#+#:Xabb\#I!!**3//3y@@#+#:Xabb\#I6(**?+@  	 	 	Js1vv	
0f00111ts:   H5 'AH5 A

H5 A
G%H5 5
I*?!I%%I*c                   t           j                            |          d                                         dd          }t          j        t          j        z  t          j        z  }t          j	                    r|| j
        v rdS n<t          j        |          j        |z  r t           j                            |           S dS )Nr   r   TF)r)   r#   splitextlowerstatS_IXUSRS_IXGRPS_IXOTHr   r'   r,   st_modeisdir)r6   r#   suffixexecmasks       r<   _is_executablezExternalProgram._is_executable   s    !!$''+1133ABB7<$,.=   	+***t +WT]]"X- 	+w}}T****ur>   
search_dirT.Optional[str]T.Optional[list]c                v   |d S t           j                            ||          }t           j                            |          r-|                     |          r|gS |                     |          S t          j                    r5| j        D ]-}| d| }t           j                            |          r|gc S .d S )Nr   )	r)   r#   r4   r+   r   r(   r   r'   r,   )r6   r   r   trialr9   r:   s         r<   _search_dirzExternalProgram._search_dir   s    4Z..7>>%   	+""5)) w ''..."$$ +, + +C#( 0 03 0 0Iw~~i00 + ){***+tr>   T.List[T.Optional[str]]c                   |rgt           j                            |          d         }|dd                                         | j        v r|gS |                     |          }|r|S dgS t           j                            |          r5| j        D ]-}| d| }t           j                            |          r|gc S .t          | 	                    t           j
                            dd                                        d                    }|r|                    |           |D ]}|                     ||          }|r|c S dgS )a  
        Lots of weird Windows quirks:
        1. PATH search for @name returns files with extensions from PATHEXT,
           but only self.windows_exts are executable without an interpreter.
        2. @name might be an absolute path to an executable, but without the
           extension. This works inside MinGW so people use it a lot.
        3. The script is specified without an extension, in which case we have
           to manually search in PATH.
        4. More special-casing for the shebang inside the script.
        r   Nr   PATH ;)r)   r#   r   r   r,   r(   r*   r+   r	   r   r}   getr~   difference_updater   )	r6   r   r   r   name_extr   r9   r   r   s	            r<   _search_windows_special_casesz-ExternalProgram._search_windows_special_cases  su     	
 w''003H|!!##t'888y ++G44H  6M 7== 	%( % %!//C//7>>'** %#9$$$%
 !!<!<RZ^^FTV=W=W!X!X!^!^_b!c!cdd 	9))-888% 	  	 J''j99H   vr>   c                   |D ]}|                      ||          }|r|c S t          j                            |          r"t          j                            |          sdgS t          j                            dt          j                  }t          j	                    r|r| 
                    |          }|r^t          |                    t          j                                                |          }t          j                            |          }t!          j        ||          }t          j	                    r|                     |||          S |gS )z{
        Search in the specified dirs for the specified executable by name
        and if not found search in PATH
        Nr   r#   )r   r)   r#   r   r*   r}   r   defpathr   r'   r   r	   r~   r   
differencer4   shutilwhichr   )	r6   r   r   r   r   r   r#   r   r   s	            r<   r-   zExternalProgram._search1  s@   
 & 	  	 J''j99H    7??4   	t)<)< 	6Mz~~fbj11   	5T 	5..t44D 	*tzz"*5566AA-PPE:??5))D,t$///   	T55dG]SSS yr>   c                     | j         d         d uS )Nr   r   rB   s    r<   r.   zExternalProgram.foundK  s    |Ad**r>   T.List[str]c                     | j         d d          S rp   r   rB   s    r<   rV   zExternalProgram.get_commandN  s    |AAAr>   c                    | j         S rp   r   rB   s    r<   get_pathzExternalProgram.get_pathQ  
    yr>   c                    | j         S rp   )r   rB   s    r<   get_namezExternalProgram.get_nameT  r   r>   NFNN)
r   r   r   r   r   r   r   r   r   r   )r?   r@   r?   r   rp   )rP   rQ   r?   r   )rU   rl   rm   r   r   r   r?   rn   )r#   r   r?   r   )r   r   r   r   r?   rn   )r   r   r?   r   )r#   r   r?   r   )r   r   r   r   r?   r   )r   r   r   r   r   r   r?   r   )r   r   r   r   r   r   r?   r   r?   r   )r?   r   )r?   r   )rI   
__module____qualname____doc__r,   r   BUILDrm   r=   rC   rL   rO   rk   classmethodru   staticmethod	functools	lru_cacher   rs   r(   r   r   r   r-   r.   rV   r   r    r>   r<   r   r      s       U U 7L%KEIZ^:>5O 5O 5O 5O 5On   
J J J J& & & &# # # # #6 - - - [- Y&&&& & & '& \&, 5 5 5 \5 , , , \,\      &+ + + +Z   4+ + + +           r>   r   c                  ,    e Zd ZdZdddZddZdd
ZdS )rr   zA program that will never existnonexistingprogramr   r   r?   Nonec                2    || _         d g| _        d | _        d S rp   )r   r   r#   )r6   r   s     r<   r=   z#NonExistingExternalProgram.__init__[  s    	v			r>   c                \    d}|                     | j        j        | j        | j                  S rE   rF   rJ   s     r<   rL   z#NonExistingExternalProgram.__repr__`  rM   r>   r   c                    dS )NFr   rB   s    r<   r.   z NonExistingExternalProgram.foundd  s    ur>   N)r   )r   r   r?   r   r   r   )rI   r   r   r   r=   rL   r.   r   r>   r<   rr   rr   X  s_        %%    
J J J J     r>   rr   c                  ,     e Zd ZdZ	 	 	 dd fdZ xZS )OverrideProgramzA script overriding a program.NFr   r   versionr   r   r   r   r   r   r   c                b    || _         t                                          |||||           d S )N)r   r   r   r   )r$   superr=   )r6   r   r   r   r   r   r   rH   s          r<   r=   zOverrideProgram.__init__l  sH     &wv%0 	 	O 	O 	O 	O 	Or>   r   )r   r   r   r   r   r   r   r   r   r   r   r   )rI   r   r   r   r=   __classcell__)rH   s   @r<   r   r   h  s\        ((SWZ^:>O O O O O O O O O O Or>   r   TrU   rl   rm   r   r   r   display_namedefault_namesr   allow_default_for_crossr   r   r   r?   *T.Generator['ExternalProgram', None, None]c              #    K   t          |          }|                    |           |D ]V}|                     ||          }	|	<t          j        | d| d|	            t
                              ||	          V   dS Wt          j        | d           |s#|t          j        u r| 	                    |          s4|D ]/}t          j        d| d|           t          |d|          V  0dS t          j        d	           dS )
zKFind an external program, checking the cross file plus any default options.Nz binary for z7 specified from cross file, native file, or env var as z@ binary missing from cross or native file, or env var undefined.zTrying a default z fallback atT)r   r   z+Default target is not allowed for cross use)
r	   addrq   r   r   r   rs   r   HOSTis_cross_build)
rU   rm   r   r   r   r   r   potential_namespotential_namepotential_cmds
             r<   find_external_programr   s  so     
 !//O)  //^LL$J, 8 8K 8 8(58 8 9 9 9!,,^]KKKKK FF % 	J,```aaa  B{m6H'H'HSM_M_`kMlMl'H+ 	\ 	\NJE<EEE~VVV!.][[[[[[[	\ 	\ 	
@AAAAAr>   )TN)rU   rl   rm   r   r   r   r   r   r   r   r   r   r   r   r?   r   )
__future__r   r   r)   r   r   r   r`   typingTpathlibr   r   r   r   r   r	   TYPE_CHECKINGenvironmentr
   rP   r   HoldableObjectr   rr   r   r   r   r>   r<   <module>r      s   # " " " " " C     				   



 				                       / / / / / / / /? )(((((((((((({ { { { {h- { { {|	        	O 	O 	O 	O 	Oo 	O 	O 	O ;?CGB B B B B B Br>   