+
    UBinI                    "   ^ RI Ht  ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt	^ RI
Ht ^RIHt ^RIHt ^RIHtHt ]	P"                  '       d   ^RIHt ^RIHt  ! R	 R
]P,                  4      t ! R R]4      t ! R R]4      tRR R lltR# )    )annotationsN)Path)mesonlib)mlog)MachineChoice
OrderedSet)Environment)Interpreterc                  ^   ] tR t^tRtR't]P                  tR(R R llt	R R lt
R R ltR	 R
 ltR)R R llt]R R l4       t]]P$                  ! RR7      R R l4       4       t]R R l4       t]R R l4       tR R ltR R ltR R ltR R ltR R ltR  R! ltR" R# ltR$ R% ltR&tR# )*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 PATHNc          
     ,    V ^8  d   QhRRRRRRRRR	R/# )
   namestrcommandT.Optional[T.List[str]]silentboolsearch_dirs#T.Optional[T.List[T.Optional[str]]]exclude_paths )formats   "8/usr/lib/python3.14/site-packages/mesonbuild/programs.py__annotate__ExternalProgram.__annotate__'   s:     5O 5OS 5O+B 5O5O4W5O 75O    c           
     	F   Wn         R V n        R V n        RV n        VEe!   \        P
                  ! V4      V n        \        P                  ! 4       '       d   V P                  ^ ,          pV P                  R,          pV P                  V4      pV'       d   W,           V n        M\        P                  P                  V4      '       di   \        P                  P                  V4      '       gD   V P                   F3  p	V RV	 2p
\        P                  P                  V
4      '       g   K1  T
p M	  V.V,           V n        MVf   R .pV P                  WV4      V n        V P                  4       '       dh   \        V P                  4       F6  pVf   K	  \        P                  P!                  V4      '       g   K0  Wn         M	  V P                  R
,          V n        V'       g   V P                  4       '       de   \"        P$                  ! R\"        P&                  ! V4      R\"        P(                  ! R4      RRP+                  V P                  4      ,          4       R # \"        P$                  ! R\"        P&                  ! V4      R\"        P,                  ! R	4      4       R # R # )Nz	--version   NN.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   cmdargsretext	trial_extargs   &&&&&&      r   __init__ExternalProgram.__init__'   s    	%)	/3&#++G4DL""$$ll1o||B' **3/#&:DLww}}S))"''..2E2E $(#4#4C+.%qI!ww~~i88&/ %	 $5
 %(54<DL"#f<<=IDL::<<  -?rww~~c':': #I .
 !LL,	 zz||DIIdOXtzz%?P#((4<<"88: DIIdOXtxx~N r   c                   V ^8  d   QhRR/# )r   returnz T.Union[str, mlog.AnsiDecorator]r   )r   s   "r   r   r   ^   s      ? r   c                	r    V P                  4       '       g   \        P                  ! R 4      # V P                  # )r%   )r2   r   r9   r'   r:   s   &r   summary_valueExternalProgram.summary_value^   s%    zz||88D>!yyr   c                   V ^8  d   QhRR/# r   rD   r   r   )r   s   "r   r   r   c        J J# Jr   c                	|    R pVP                  V P                  P                  V P                  V P                  4      # z<{} {!r} -> {!r}>r   	__class____name__r   r   r:   rs   & r   __repr__ExternalProgram.__repr__c   ,    xx//DLLIIr   c                   V ^8  d   QhRR/# rJ   r   )r   s   "r   r   r   g   s     & &S &r   c                8    RP                  V P                  4      # )z)Human friendly description of the commandr$   )r8   r   rF   s   &r   descriptionExternalProgram.descriptiong   s    xx%%r   c                    V ^8  d   QhRRRR/# )r   interpreterzT.Optional['Interpreter']rD   r   r   )r   s   "r   r   r   k   s     # #'@ #C #r   c           
     	0   V P                   '       Egy   V P                  4       V P                  .,           pV'       dQ   VP                  W P                  .3R RRRR\        P
                  ! 4       /R4      pVP                  VP                  rTMh\        P                  ! V4      w  rdpVP                  ^ 8w  d?   \        P                  ! V4      p\        P                  ! RV: RVP                   R24      hVP                  4       pV'       g   VP                  4       p\        P                  ! RV4      p	V	'       g   \        P                  ! RV4      p	V	'       g   \        P                  ! R	V: 24      hV	P                  ^4      V n         V P                   # )
captureTcheckenvz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(   get_commandr)   run_command_implr   EnvironmentVariablesstdoutstderr
Popen_safe
returncode	join_argsMesonExceptionstripresearchgroup)
r:   r[   raw_cmdresoepcmd_stroutputmatchs
   &&        r   get_versionExternalProgram.get_versionk   sQ   """&&(D,<,<+==G!22D;K;K:L3M4=t4;T498;X;X;Z4\ 48	9
 zz3::1"--g6a<<1$&009G"11HWKG[\]\h\h[iij2kllWWYFII4f=E		"4f=--0]^e]h.ijj"'++a.D"""r   c               (    V ^8  d   QhRRRRRRRR/# )	r   r_   'Environment'for_machiner   r   r   rD   'ExternalProgram'r   )r   s   "r   r   r      s*     - - -M -QT -Yj -r   c                	b    VP                  W#4      pVf   \        4       # V P                  W44      # N)lookup_binary_entryNonExistingExternalProgram
from_entry)clsr_   ry   r   r   s   &&&& r   from_bin_listExternalProgram.from_bin_list   s1     ))+<?-//~~d,,r   )maxsizec                    V ^8  d   QhRRRR/# )r   r'   r   rD   r   )r   s   "r   r   r      s     & &S &S &r   c                	"   R \         P                  9  d   V # \        \         P                  R ,          4      R,          R,          R,          R,          p. pV P                  \         P                  4       Fy  p\        V4      V8w  d   VP                  V4       K&  R\        P                  9   g   K=  VP                  \         P                  P                  \        P                  4      4       K{  	  \         P                  P                  V4      # )USERPROFILEAppDataLocal	MicrosoftWindowsApps)r-   environr   splitpathsepappendsys
executabler'   dirnamer8   )r'   appstore_dirpathseachs   &   r   _windows_sanitize_path&ExternalProgram._windows_sanitize_path   s     

*K BJJ}56BWL{Z]jjJJrzz*DDz\)T"#..0RWW__S^^<=	 +
 zzu%%r   c               $    V ^8  d   QhRRRRRR/# )r   r   r   r   zT.Union[str, T.List[str]]rD   rz   r   )r   s   "r   r   r      s#     5 5 5'@ 5EV 5r   c                	l   \        V\        4      '       d   \        V4      ^8X  d
   V^ ,          p\        V\        4      '       g&   \        P                  P                  V4      '       d'   \        V\        4      '       d   V.p\        WRR7      # \        V\        4      '       g   Q h\        VRR7      # )r    T)r   r   )r   )
isinstancelistlenr-   r'   r.   r   r   )r   r   s   &&r   r   ExternalProgram.from_entry   s    gt$$7|q !!* gt$$g(>(>'3''")"4FF'3''''wt44r   c                    V ^8  d   QhRRRR/# )r   scriptr   rD   r   r   )r   s   "r   r   r      s     , , ,(? ,r   c                ^    \        V RR7      ;_uu_ 4       pVP                  4       P                  4       pRRR4       XP                  R4      '       Ed   VR,          P	                  R4      ^ ,          P                  4       P	                  ^R7      p\
        P                  ! 4       '       d   V^ ,          P                  R4      '       d#   V^ ,          P	                  R4      R,          V^ &   \        V4      ^ 8  d   V^ ,          R	8X  d
   VR
,          p\        V4      ^ 8  d-   V^ ,          R8X  d   \
        P                  VR
,          ,           pM\
        P                  ! 4       '       dU   V^ ,          R8X  d
   VR
,          p\        V4      ^ 8  d-   V^ ,          R8X  d   \
        P                  VR
,          ,           pM}V^ ,          R8X  d.   V^,          R8X  d    \
        P                  VR,          ,           pMBV^ ,          P	                  R4      R,          R8X  d   \
        P                  VR
,          ,           pW0.,           #  \        P                  ! RV : 24       R#   + '       g   i     EL7; i  \         d*   p\        P                  ! \        T4      4        Rp?L_Rp?ii ; i)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   NN#)maxsplit/r_   r   python3z/usr/bin/envzUnusable script r&   )openreadlineri   
startswithr   r   r+   r   python_commandis_haiku	Exceptionr   debugr   )r   f
first_linecommandsrp   s   &    r   r,   ExternalProgram._shebang_to_cmd   s   $	fw//1ZZ\//1
 0$$T**
 &b>//4Q7==?EEqEQ&&((  {--c22&.qk&7&7&<R&@8}q(Xa[E-A#+B<8}q(Xa[I-E#+#:#:Xb\#I&&((  {n4#+B<8}q(Xa[I-E#+#:#:Xb\#I  {n4!	9Q#+#:#:Xb\#I!!**3/3y@#+#:#:Xb\#I(**? +D 	

%fZ01K 0//D  	JJs1v	sH   I8 I$I8 AI8 .I8 B I8 -CI8 $I5	/	I8 8J,J''J,c                    V ^8  d   QhRRRR/# )r   r'   r   rD   r   r   )r   s   "r   r   r      s      3 4 r   c                	   \         P                  P                  V4      R,          P                  4       R,          p\        P
                  \        P                  ,          \        P                  ,          p\        P                  ! 4       '       d   W P                  9   d   R#  R# \         P                  ! V4      P                  V,          '       d%   \         P                  P                  V4      '       * # R# )r    r   TFr&   )r-   r'   splitextlowerstatS_IXUSRS_IXGRPS_IXOTHr   r+   r0   st_modeisdir)r:   r'   suffixexecmasks   &&  r   _is_executableExternalProgram._is_executable   s    !!$'+113B7<<$,,.=  *** +  WWT]""X--ww}}T***r   c               $    V ^8  d   QhRRRRRR/# )r   r   r   
search_dirT.Optional[str]rD   zT.Optional[list]r   )r   s   "r   r   r      s"        EU r   c                	   Vf   R # \         P                  P                  W!4      p\         P                  P                  V4      '       d,   V P	                  V4      '       d   V.# V P                  V4      # \        P                  ! 4       '       dE   V P                   F4  pV RV 2p\         P                  P                  V4      '       g   K1  V.u # 	  R # )Nr!   )	r-   r'   r8   r/   r   r,   r   r+   r0   )r:   r   r   trialr>   r?   s   &&&   r   _search_dirExternalProgram._search_dir   s    Z.77>>%  ""5))w ''..""$$,,C#('3% 0Iww~~i00 ){* - r   c               (    V ^8  d   QhRRRRRRRR/# )	r   r   r   r   r   r   r   rD   T.List[T.Optional[str]]r   )r   s   "r   r   r     s.     + +# + +`w +  }T +r   c                   V'       dn   \         P                  P                  V4      ^,          pVR,          P                  4       V P                  9   d   V.# V P                  V4      pV'       d   V# R.# \         P                  P                  V4      '       dE   V P                   F4  pV RV 2p\         P                  P                  V4      '       g   K1  V.u # 	  \        V P                  \         P                  P                  RR4      4      P                  R4      4      pV'       d   VP                  V4       V F   pV P                  W4      pV'       g   K  Vu # 	  R.# )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   r0   r,   r.   r/   r   r   r   getr   difference_updater   )	r:   r   r   r   name_extr   r>   r   r   s	   &&&&     r   _search_windows_special_cases-ExternalProgram._search_windows_special_cases  s$    
 ww''03H|!!#t'8'88y ++G4H6M 77==((!F!C5/77>>'**#9$ ) !!<!<RZZ^^FTV=W!X!^!^_b!cd))-8%J''9Hx & vr   c               (    V ^8  d   QhRRRRRRRR/# )r   r   r   r   r   r   r   rD   r   )r   s   "r   r   r   1  s/      C .E Vm   sJ r   c                   V F   pV P                  W4      pV'       g   K  Vu # 	  \        P                  P                  V4      '       d)   \        P                  P	                  V4      '       g   R.# \        P
                  P                  R\        P                  4      p\        P                  ! 4       '       d   V'       d   V P                  V4      pV'       dW   \        VP                  \        P                  4      4      P                  V4      p\        P                  P                  V4      p\         P"                  ! WR7      pV'       gO   \        P$                  ! 4       '       d4   R F-  p	\         P"                  ! V RV	 2VR7      pV'       g   K*  V.u # 	  \        P                  ! 4       '       d   V P'                  WV4      # V.# )zc
Search in the specified dirs for the specified executable by name
and if not found search in PATH
Nr   r'   r!   )exer;   )r   r-   r'   r   r.   r   r   defpathr   r+   r   r   r   r   
differencer8   shutilwhichis_os2r   )
r:   r   r   r   r   r   r'   r   r   r>   s
   &&&&      r   r1   ExternalProgram._search1  sB   
 &J''9Hx &
 77??4  t)<)<6Mzz~~fbjj1  T..t4Dtzz"**56AA-PE::??5)D,,t/8??,,% ,,$qTB7#9$ &   55d]SS yr   c                   V ^8  d   QhRR/# r   rD   r   r   )r   s   "r   r   r   P  s     + +t +r   c                	,    V P                   ^ ,          RJ# )r   Nr   rF   s   &r   r2   ExternalProgram.foundP  s    ||Ad**r   c                   V ^8  d   QhRR/# )r   rD   T.List[str]r   )r   s   "r   r   r   S  s      [ r   c                	(    V P                   R ,          # ):NNNr   rF   s   &r   r`   ExternalProgram.get_commandS  s    ||Ar   c                   V ^8  d   QhRR/# )r   rD   r   r   )r   s   "r   r   r   V  s      / r   c                	    V P                   # r|   r   rF   s   &r   get_pathExternalProgram.get_pathV      yyr   c                   V ^8  d   QhRR/# rJ   r   )r   s   "r   r   r   Y  s      # r   c                	    V P                   # r|   )r   rF   s   &r   get_nameExternalProgram.get_nameY  r   r   )r(   r   r   r'   r)   )r   msccombatr;   NFNNr|   )rP   
__module____qualname____firstlineno____doc__r0   r   BUILDry   rA   rG   rS   rX   ru   classmethodr   staticmethod	functools	lru_cacher   r   r,   r   r   r   r1   r2   r`   r   r   __static_attributes__r   r   r   r   r      s    U 7L%%K5On
J&#6 - - && ' &, 5 5 , ,\&+Z>+ r   r   c                  B    ] tR tRtRtRR R lltR R ltR R ltR	tR
# )r~   i]  zA program that will never existc                    V ^8  d   QhRRRR/# )r   r   r   rD   Noner   )r   s   "r   r   'NonExistingExternalProgram.__annotate__`  s      S D r   c                	0    Wn         R .V n        R V n        R # r|   )r   r   r'   )r:   r   s   &&r   rA   #NonExistingExternalProgram.__init__`  s    	v	r   c                   V ^8  d   QhRR/# rJ   r   )r   s   "r   r   r   e  rK   r   c                	|    R pVP                  V P                  P                  V P                  V P                  4      # rM   rN   rQ   s   & r   rS   #NonExistingExternalProgram.__repr__e  rU   r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   i  s      t r   c                	    R # )Fr   rF   s   &r   r2    NonExistingExternalProgram.foundi  s    r   )r   r   r'   N)nonexistingprogram)	rP   r   r   r   r   rA   rS   r2   r   r   r   r   r~   r~   ]  s    %
J r   r~   c                  6   a  ] tR tRtRtRR V 3R llltRtV ;t# )OverrideProgramim  zA script overriding a program.c               0    V ^8  d   QhRRRRRRRRRR	R
R/# )r   r   r   versionr   r   r   r   r   r   r   r   )r   s   "r   r   OverrideProgram.__annotate__q  s:     & &S &3 &9P &&4W& 7&r   c                	8   < \         SV `  WVWVR 7       W n        R# ))r   r   r   r   N)superrA   r(   )r:   r   r
  r   r   r   r   rO   s   &&&&&&&r   rA   OverrideProgram.__init__q  s%     	v%0 	 	O%r   )r(   r   )rP   r   r   r   r   rA   r   __classcell__)rO   s   @r   r  r  m  s    (& & &r   r  c               8    V ^8  d   QhRRRRRRRRRR	R
RRRRR/# )r   r_   rx   ry   r   r   r   display_namedefault_namesr   allow_default_for_crossr   r   r   rD   z*T.Generator['ExternalProgram', None, None]r   )r   s   "r   r   r   x  s[     B B} B= BPS B(+B<GB37B *AB MwBr   c              #  "  "   \        V4      pVP                  V4       V FP  pV P                  W4      p	V	f   K  \        P                  ! V RV RV	 24       \
        P                  W4      x   R# 	  \        P                  ! V R24       V'       g,   V\        P                  J d   V P                  V4      '       g7   V F.  p\        P                  ! RV R2V4       \        VRVR7      x  K0  	  R# \        P                  ! R	4       R# 5i)
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   addr}   r   r   r   r   r   HOSTis_cross_build)
r_   ry   r   r  r  r  r   potential_namespotential_namepotential_cmds
   &&&&&&&   r   find_external_programr  x  s     
 !/O)//L$JJ,|K= A((58 9!,,^KK  * 	JJ,_`a {m6H6H'HSM_M_`kMlMl+NJJ*<.E~V!.][[ , 	

@As   4DAD*DAD)TN)
__future__r   r   r-   r   r   r   rj   typingTpathlibr   r   r   r   r   r   TYPE_CHECKINGenvironmentr	   r[   r
   HoldableObjectr   r~   r  r  r   r   r   <module>r#     sv    # C  	   
 	     /???((@h-- @F
  	&o 	&B Br   