o
    Wod!                     @  s"  U 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d dlZd dl	Z	d dl
Z
d dlZddlmZmZmZ ddlmZ ddlmZmZmZmZmZmZmZmZ ddlmZmZ dd	lm Z  zd d
l!m"Z# W n e$yv   dZ#Y nw ej%rddlm&Z&m'Z'm(Z(m)Z)m*Z* ddlm+Z+m,Z, zd dlm-Z- W n e.y   d dl/m-Z- Y nw G dd de-Z0dZ1g Z2de3d< dQddZ4G dd dZ5dRddZ6dSdTd$d%Z7dUd)d*Z8			+dVdWd1d2Z9		+dXdYd5d6Z:dZd9d:Z;d[d=d>Z<d\d?d@Z=d]dCdDZ>d^dEdFZ?G dGdH dHZ@d_dKdLZAd`dOdPZBdS )a    )annotations)globN   )buildcoredataenvironment)InstallData)MesonException
Popen_safeRealPathAction
is_windowssetup_vsenvpickle_loadis_osx	OptionKey)depfixerdestdir_join)run_exe)__file__)ExecutableSerialisationInstallDataBaseInstallEmptyDirInstallSymlinkDataTargetInstallData)FileModeEnvironOrDict)Protocolc                   @  sb   e Zd ZU dZded< ded< ded< ded< ded< ded	< ded
< ded< ded< ded< dS )ArgumentTypez7Typing information for the object returned by argparse.bool
no_rebuildonly_changedprofilequietstrwddestdirdry_runskip_subprojectstagsstripN)__name__
__module____qualname____doc____annotations__ r/   r/   rhome/ych/rk3568/buildroot/output/rockchip_rk3568_recovery/host/lib/python3.10/site-packages/mesonbuild/minstall.pyr   4   s   
 r   zWarning: trying to copy a symlink that points to a file. This will copy the file,
but this will be changed in a future version of Meson to copy the symlink as is. Please update your
build definitions so that it will not break when the change happens.T.List[str]selinux_updatesparserargparse.ArgumentParserreturnNonec                 C  s   | j ddtdd | j dddtjd | j d	d
ddd | j dd
ddd | j dd
ddd | j dd dd | j ddddd | j dddddd | j dd dd | j d dd!d d S )"N-Cr$   z#directory to cd into before running)destactionhelpz--profile-self
store_truer!   )r9   r8   r:   --no-rebuildFz!Do not rebuild before installing.)defaultr9   r:   z--only-changedz9Only overwrite files that are older than the copied file.z--quietz+Do not print every file that was installed.z	--destdirz5Sets or overrides DESTDIR environment. (Since 0.57.0))r=   r:   z	--dry-runz-nz8Doesn't actually install, but print logs. (Since 0.57.0))r9   r:   z--skip-subprojects?* z;Do not install files from given subprojects. (Since 0.58.0))nargsconstr=   r:   z--tagszAInstall only targets having one of the given tags. (Since 0.60.0)z--stripzOStrip targets even if strip option was not set during configure. (Since 0.62.0))add_argumentr   argparseZSUPPRESS)r3   r/   r/   r0   add_argumentsH   s<   






rE   c                   @  s6   e Zd ZdddZddddZdddZdddZdS ) DirMakerlfT.TextIOmakedirsT.Callable[..., None]c                 C  s   || _ g | _t | _|| _d S N)rG   dirssetall_dirsmakedirs_impl)selfrG   rI   r/   r/   r0   __init___   s   
zDirMaker.__init__Fpathr#   exist_okr   r5   r6   c                 C  s   t j|}| j| g }|t j|kr5|| jv rnt j|s'|| t j|}|t j|ks| j	||d |
  |  j|7  _d S )NrS   )osrR   normpathrN   adddirnamerL   existsappendrO   reverse)rP   rR   rS   rX   rL   r/   r/   r0   rI   e   s   

zDirMaker.makedirs
'DirMaker'c                 C  s   | S rK   r/   )rP   r/   r/   r0   	__enter__{   s   zDirMaker.__enter__exception_typeT.Type[Exception]valueT.Any	tracebackc                 C  s&   | j   | j D ]}t| j| qd S rK   )rL   r[   append_to_logrG   )rP   r^   r`   rb   dr/   r/   r0   __exit__~   s   

zDirMaker.__exit__N)rG   rH   rI   rJ   F)rR   r#   rS   r   r5   r6   )r5   r\   )r^   r_   r`   ra   rb   ra   r5   r6   )r*   r+   r,   rQ   rI   r]   re   r/   r/   r/   r0   rF   ^   s
    

rF   fnamer#   r   c                 C  s   t | dtS )Nr   )r   r   )rg   r/   r/   r0   load_install_data   s   rh   FrR   follow_symlinksr   c                 C  s   t tj| |djd@ S )zCChecks whether any of the "x" bits are set in the source file mode.ri   I   )r   rU   statst_mode)rR   ri   r/   r/   r0   is_executable   s   rn   rG   rH   linec                 C  s*   |  | |ds|  d |   d S )N
)writeendswithflush)rG   ro   r/   r/   r0   rc      s   


rc   TuserT.Union[str, int, None]groupdir_fdT.Optional[int]c                   sF   t j ||dd fdd}z|t _t| || W  t _d S  t _w )Nrw   ri   rR   BT.Union[int, str, 'os.PathLike[str]', bytes, 'os.PathLike[bytes]']uidintgidrw   rx   ri   r   r5   r6   c                  s    | ||||d dS )zOverride the default behavior of os.chown

        Use a real function rather than a lambda to help mypy out. Also real
        functions are faster.
        ry   Nr/   )rR   r{   r}   rw   ri   Zreal_os_chownr/   r0   chown   s   zset_chown.<locals>.chown)rR   rz   r{   r|   r}   r|   rw   rx   ri   r   r5   r6   )rU   r   shutil)rR   rt   rv   rw   ri   r   r/   r~   r0   	set_chown   s   	
r   moder|   c              
   C  sV   zt j| |||d W d S  tttfy*   t j| s't j| ||d Y d S Y d S w )Nry   )rw   )rU   chmodNotImplementedErrorOSErrorSystemErrorrR   islink)rR   r   rw   ri   r/   r/   r0   	set_chmod   s   r   umaskT.Union[str, int]c              
   C  s   |dkrd S t |tsJ dt| ddrdnd}|| M }z
t| |dd W d S  tyI } zt| d|d|j d	 W Y d }~d S d }~ww )
Npreservez.umask should only be "preserver" or an integerFrj   i  i  : Unable to set permissions : , ignoring...)
isinstancer|   rn   r   PermissionErrorprintstrerror)rR   r   Z	new_permser/   r/   r0   sanitize_permissions   s   
*r   T.Optional['FileMode']default_umaskc                 C  s  |d u st dd |j|j|jfD rt| | d S t s|jd us'|jd urzt| |j|jdd W nd tyX } zt| d|jd|jd|j	 d W Y d }~nDd }~w t
yo   t| d	|jd
|jd Y n) ty } z|jtjkrt| d|jd
|jd n W Y d }~nd }~ww |jd urzt| |jdd W d S  ty } zt| d|jd|j	 d W Y d }~d S d }~ww t| | d S )Nc                 s  s    | ]}|d u V  qd S rK   r/   ).0mr/   r/   r0   	<genexpr>   s    zset_mode.<locals>.<genexpr>Frj   z: Unable to set owner z and group r   r   z: Nonexistent owner z
 or group z: ignoring...z: Nonexistent numeric owner r   )allZperms_sownerrv   r   r   r   r   r   r   LookupErrorr   errnoEINVALr   Zperms)rR   r   r   r   r/   r/   r0   set_mode   s4   &
2" 
,r   c                  C  s   zt dg W n ttttt jfy   Y dS w tds dS t	s$dS t
g dddd t	D d \} }}| jdkrItd	d
|d|dd dS dS )z|
    Restores the SELinux context for files in @selinux_updates

    If $DESTDIR is set, do not warn if the call fails.
    ZselinuxenabledN
restorecon)r   z-Fz-f-z-0 c                 s  s    | ]}|V  qd S rK   r/   )r   fr/   r/   r0   r      s    z+restore_selinux_contexts.<locals>.<genexpr>r   z7Failed to restore SELinux context of installed files...zStandard output:zStandard error:rp   )sep)
subprocess
check_callFileNotFoundErrorNotADirectoryErrorr   r   CalledProcessErrorr   whichr2   r
   join
returncoder   )procouterrr/   r/   r0   restore_selinux_contexts   s    
(

r   r%   
fullprefixc                 C  s,   t j|rt| |}|S t j||}|S rK   )rU   rR   isabsr   r   )r%   r   rR   outputr/   r/   r0   get_destdir_path   s
   
r   c                 C  s   |  ds
|  dr=t| jdkr;tj| \}}t|d | }t|dkr1td t	
d t|dkr;|d S | S |  dsG|  drxt| jdkrxtj| \}}t|d d	 }t|dkrntd
 t	
d t|dkrx|d S | S )zSome languages e.g. Rust have output files
    whose names are not known at configure time.
    Check if this is the case and return the real
    file instead.z.soz.dllr   z-*r   z8Stale dynamic library files in build dir. Can't install.z.az.libz.rlibz7Stale static library files in build dir. Can't install.)rr   rU   rl   st_sizerR   splitextr   lenr   sysexit)rg   basesuffixfilesr/   r/   r0   check_for_stampfile  s(   


r   c                   @  sR  e Zd ZdoddZdpddZdpddZdpddZdpddZdpddZdpddZ	dpddZ
dpddZdpddZdpddZdpd d!Zdpd"d#Zdqd&d'Zdrd)d*Zdsdtd1d2Zdud6d7Zdvd9d:Zdwd=d>Z	+dsdxdAdBZdydGdHZdzdSdTZd{dVdWZd|d\d]Zd}d_d`Zd}dadbZd}dcddZd}dedfZd}dgdhZd}didjZ d~dkdlZ!d}dmdnZ"d+S )	Installeroptions'ArgumentType'rG   rH   c                 C  sj   d| _ d| _|| _|| _d| _|j| _dd |jdD | _|jr0dd |jdD | _d S d | _d S )NFr   c                 S     g | ]}|  qS r/   r)   r   ir/   r/   r0   
<listcomp>-      z&Installer.__init__.<locals>.<listcomp>,c                 S  r   r/   r   r   r/   r/   r0   r   .  r   )	did_install_somethingprinted_symlink_errorr   rG   preserved_file_countr&   r'   splitr(   )rP   r   rG   r/   r/   r0   rQ   #  s   ,zInstaller.__init__argsra   kwargsr5   r6   c                 O     | j stj|i | d S d S rK   )r&   rU   removerP   r   r   r/   r/   r0   r   0     zInstaller.removec                 O  r   rK   )r&   rU   symlinkr   r/   r/   r0   r   4  r   zInstaller.symlinkc                 O  r   rK   )r&   rU   rI   r   r/   r/   r0   rI   8  r   zInstaller.makedirsc                 O  r   rK   )r&   r   copyr   r/   r/   r0   r   <  r   zInstaller.copyc                 O  r   rK   )r&   r   copy2r   r/   r/   r0   r   @  r   zInstaller.copy2c                 O  r   rK   )r&   r   copyfiler   r/   r/   r0   r   D  r   zInstaller.copyfilec                 O  r   rK   )r&   r   copystatr   r/   r/   r0   r   H  r   zInstaller.copystatc                 O  r   rK   )r&   r   	fix_rpathr   r/   r/   r0   r   L  r   zInstaller.fix_rpathc                 O     | j st|i | d S d S rK   )r&   r   r   r/   r/   r0   r   P     zInstaller.set_chownc                 O  r   rK   )r&   r   r   r/   r/   r0   r   T  r   zInstaller.set_chmodc                 O  r   rK   )r&   r   r   r/   r/   r0   r   X  r   zInstaller.sanitize_permissionsc                 O  r   rK   )r&   r   r   r/   r/   r0   r   \  r   zInstaller.set_moder%   r#   c                 C  s   | j s
|st  d S d S d S rK   )r&   r   )rP   r%   r/   r/   r0   r   `  s   

z"Installer.restore_selinux_contextsT.Tuple[int, str, str]c                 O  s*   | j st|i |\}}}|j||fS dS )N)r   r@   r@   )r&   r
   r   )rP   r   r   por   r/   r/   r0   r
   d  s   zInstaller.Popen_safeNexer   	extra_envT.Optional[T.Dict[str, str]]r|   c                 C  s   | j r|j rt||S dS )Nr   )r&   r   )rP   r   r   r/   r/   r0   r   j  s   
zInstaller.run_exerd   iT.Union[TargetInstallData, InstallEmptyDir, InstallDataBase, InstallSymlinkData, ExecutableSerialisation]r   c                 C  s:   |j r|j | jv sd| jv rdS | jr|j| jvrdS dS )Nr?   FT)Z
subprojectr'   r(   tag)rP   rd   r/   r/   r0   should_installo  s
   zInstaller.should_installmsgc                 C  s   | j js
t| d S d S rK   )r   r"   r   )rP   r   r/   r/   r0   logx  s   zInstaller.log	from_fileto_filec                 C  sH   | j jsdS tj|rtj|sdS t|j}t|j}||kS )NF)r   r    rU   rR   r   isfilerl   st_mtime)rP   r   r   Z	from_timeZto_timer/   r/   r0   should_preserve_existing_file|  s   z'Installer.should_preserve_existing_filerI   T.Optional[T.Tuple[T.Any, str]]c                 C  s2  t j|d }t j|st j|std|t j|rNt j|s/td|d| ||rHt| j	d| d |  j
d7  _
dS | | n|r[|\}}|j|d	d
 | d| d|  t j|rt j|s{| j||dd ntt | || n| || t| t| j	| d	S )Nr   z.Tried to install something that isn't a file: Destination z! already exists and is not a filez# Preserving old file rp   r   FTrT   zInstalling  to rj   )rU   rR   r   r   r   r	   rY   r   rc   rG   r   r   rI   r   r   r   symlink_warningr   r2   rZ   )rP   r   r   rI   outdirZdirmakerr/   r/   r0   do_copyfile  s0   
zInstaller.do_copyfiletargetlinkfull_dst_dirallow_missingc              	   C  s   |}t j|st j||}nt j|s|st||}t j|s,|s,td| t j|rEt j|s@td|d| | | j	sS| 
d| d|  z| j||t j|d W n ttfyw   | j	sttd d| _	Y d	S w t| j| dS )
Nz)Tried to install symlink to missing file r   z$ already exists and is not a symlinkzInstalling symlink pointing to r   )target_is_directoryzISymlink creation does not work on this platform. Skipping all symlinking.TF)rU   rR   r   r   rY   r   r	   r   r   r   r   r   isdirr   r   r   rc   rG   )rP   r   r   r%   r   r   Z
abs_targetr/   r/   r0   
do_symlink  s.   

zInstaller.do_symlinkdatar   src_dirdst_direxclude+T.Optional[T.Tuple[T.Set[str], T.Set[str]]]install_mode
'FileMode'dmrF   c                 C  s  t j|std| t j|std| |dur1|\}}dd |D }dd |D }nt  }}t |D ]\}	}
}t j|	sHJ |
dd D ]N}t j|	|}t jj||d}t j||}||v rp|
| qNt j	|rwqNt j
|rtd| d	 td
 || | || | ||j qN|D ]Y}t j|	|}t jj||d}||v rqt j||}t j	|rtd| d td
 t j|}t j	|s|| | t j|| | || | |||j qq;dS )a  
        Copies the contents of directory @src_dir into @dst_dir.

        For directory
            /foo/
              bar/
                excluded
                foobar
              file
        do_copydir(..., '/foo', '/dst/dir', {'bar/excluded'}) creates
            /dst/
              dir/
                bar/
                  foobar
                file

        Args:
            src_dir: str, absolute path to the source directory
            dst_dir: str, absolute path to the destination directory
            exclude: (set(str), set(str)), tuple of (exclude_files, exclude_dirs),
                     each element of the set is a path relative to src_dir.
        zsrc_dir must be absolute, got zdst_dir must be absolute, got Nc                 S     h | ]}t j|qS r/   rU   rR   rV   r   xr/   r/   r0   	<setcomp>      z'Installer.do_copydir.<locals>.<setcomp>c                 S  r   r/   r   r   r/   r/   r0   r    r  )startzTried to copy directory ( but a file of that name already exists.r   zTried to copy file z- but a directory of that name already exists.)rU   rR   r   
ValueErrorrM   walkr   relpathr   r   rY   r   r   r   rI   r   r   install_umaskrX   r   r   )rP   r   r   r   r   r   r   Zexclude_filesZexclude_dirsrootrL   r   rd   Zabs_srcZfilepartZabs_dstr   
parent_dirr/   r/   r0   
do_copydir  sV   





zInstaller.do_copydirdatafilenamec              	   C  s,  t |}| jj}|d u rtjd}|r"tj|s"tj|j	|}|d ur+|tjd< |p.d}t
||j}|jdkrHt|jtsBJ t|j d| _zt| j| j}| |||| | |||| | |||| | |||| | |||| | |||| | |||| | | | ||| | js| d | jjs| jdkr| d | jtj!| jj" W d    W d S W d    W d S W d    W d S 1 sw   Y  W d S  t#y   t$ s|dkst%t&j'( rt%t&j)( s tjdpt*+d	pt*+d
}t*+d}|d u r'|d ur'dtjvr'|}|d urt,d t-. }|/t&j0t-j1 d }	t2dD ])}
t,d| dddd |3dr^t&j04 5d}	nt,   n|	dv rj nqB|	d urut6d|	dkrtj7||t&j8t9gt&j:dd  dt; dR    w )NZDESTDIRr@   r   FzNothing to install.r   z6Preserved {} unchanged files, see {} for the full listZMESON_ROOT_CMDZsudoZdoaspkexecZ
PKEXEC_UIDz4Installation failed due to insufficient permissions.   zAttempt to use z$ to gain elevated privileges? [y/n] T)endrs      rp   >   ynzAnswer not one of [y/n]r  r   r7   r<   )<rh   r   r%   rU   environgetrR   r   r   	build_dirr   prefixr	  r   r|   r   r   rF   rG   rI   install_subdirsinstall_targetsinstall_headersinstall_maninstall_emptydirinstall_datainstall_symlinksr   run_install_scriptr   r"   r   formatrV   namer   r   isattyr   stdoutfilenostderrr   r   r   	selectorsDefaultSelectorregisterstdin
EVENT_READrangeselectreadlinerstripr	   execlp
executable	main_fileargvgetcwd)rP   r  rd   r%   r   r   Zrootcmdr  sZansattemptr/   r/   r0   
do_install
  s   



&.$
 



zInstaller.do_install	strip_binr1   rg   outnamec                 C  s   |  d|d t r| |dd|g \}}}n| ||g \}}}|dkrDtd td| d td	| d td
 d S d S )NzStripping target .z-Sz-xr   zCould not strip file.
zStdout:
rp   zStderr:
r   )r   r   r
   r   r   r   )rP   r7  rg   r8  r   ZstdoZstder/   r/   r0   do_stripN  s   zInstaller.do_stripr   c              	   C  sp   |j D ]2}| |sqd| _t|||j}| d|j d|  |j|dd | ||j||j	|j
| qd S )NTzInstalling subdir r   rT   )r  r   r   r   install_pathr   rR   rI   r  r   r   )rP   rd   r   r%   r   r   r   r/   r/   r0   r  ]  s   

zInstaller.install_subdirsc           	      C  h   |j D ].}| |sq|j}t|||j}tj|}| j||||fdr(d| _| 	||j
|j qd S NrI   T)r   r   rR   r   r;  rU   rX   r   r   r   r   r	  )	rP   rd   r   r%   r   r   fullfilenameoutfilenamer   r/   r/   r0   r  g     

zInstaller.install_datac                 C  sb   |j D ]+}| |sqt|||j}t|||j}|j|dd | |j||||jr.d| _	qd S )NTrT   )
symlinksr   r   r;  r!  rI   r   r   r   r   )rP   rd   r   r%   r   r4  r   Zfull_link_namer/   r/   r0   r  r  s   

zInstaller.install_symlinksc           	      C  r<  r=  )Zmanr   rR   r   r;  rU   rX   r   r   r   r   r	  )	rP   rd   r   r%   r   r   Zfull_source_filenamer@  r   r/   r/   r0   r  |  rA  zInstaller.install_manc                 C  s   |j D ]=}| |sqd| _t|||j}| d|  tj|r0td| d t	
d |j|dd | ||j|j qd S )NTzInstalling new directory zTried to create directory r  r   rT   )Zemptydirr   r   r   rR   r   rU   r   r   r   r   rI   r   r   r	  )rP   rd   r   r%   r   r   r   r/   r/   r0   r    s   


zInstaller.install_emptydirc           
      C  sv   |j D ]5}| |sq|j}tj|}t|||j}tj||}	| j||	||fdr/d| _	| 
|	|j|j qd S r=  )headersr   rR   rU   basenamer   r;  r   r   r   r   r   r	  )
rP   rd   r   r%   r   tr?  rg   r   r@  r/   r/   r0   r    s   

zInstaller.install_headersc              	   C  s  |j |j|j|ddd |jD d}| jjrd|d< | jr#d|d< |jD ]Z}| 	|s.q&d|j
}|jrB|rB| d| q&d	| _| d
| z| ||}W n tyk   td| d td Y nw |dkrtd| d| d t| q&d S )N c                 S  s   g | ]}t |qS r/   )shlexquoter   r/   r/   r0   r     s    z0Installer.run_install_script.<locals>.<listcomp>)ZMESON_SOURCE_ROOTZMESON_BUILD_ROOTZMESON_INSTALL_PREFIXZMESON_INSTALL_DESTDIR_PREFIXZMESONINTROSPECT1ZMESON_INSTALL_QUIETZMESON_INSTALL_DRY_RUNz6Skipping custom install script because DESTDIR is set TzRunning custom install script zFAILED: install script 'z' could not be run, stopped   r   z' exit code z	, stopped)
source_dirr  r  r   Zmesonintrospectr   r"   r&   install_scriptsr   Zcmd_argsZskip_if_destdirr   r   r   r   r   r   r   )rP   rd   r%   r   envr   r!  rcr/   r/   r0   r    s<   



zInstaller.run_install_scriptc                 C  s  |j D ]9}| |sqtj|js*|jr!| d|jd qtd|jdd}t	|j}t
|||j}tj|tj|}	tj|j|jtj|}
|jpZ|joZ| jj}|j}|j}|j}tj|srtd|dtj|r| j||	||fd}|r|jd ur|dr| dtj| q| |j||	 |drtj|d	 d
 }tj|rtj|	d	 d
 }| ||}n5tj|rtj|j|d}tj|tj|}	|j|dd |  |||	d || nt!d||r=d| _"z| j#|	|j$||
|dd W n" t%y4 } zt&|j't(r)|j'd	kr)n W Y d }~nd }~ww | )|	||j* qd S )NzFile z not found, skippingz could not be foundFr>  z.jarzNot stripping jar target: {}z.jsr   z.wasm/TrT   zUnknown file type for )verbose)+targetsr   rU   rR   rY   rg   optionalr   r	   r   r   r   r   rD  r  r)   Z	can_stripr   install_rpathinstall_name_mappingsr   r   r   r7  rr   r   r:  r   r   r  r.  rI   r  RuntimeErrorr   r   Zrpath_dirs_to_remove
SystemExitr   coder|   r   r	  )rP   rd   r   r%   r   rE  Zfile_copiedrg   r   r8  Z
final_pathZshould_striprS  rT  r   Zwasm_sourceZwasm_outputr   r/   r/   r0   r    sl   




zInstaller.install_targets)r   r   rG   rH   )r   ra   r   ra   r5   r6   )r%   r#   r5   r6   )r   ra   r   ra   r5   r   rK   )r   r   r   r   r5   r|   )rd   r   r5   r   )r   r#   r5   r6   )r   r#   r   r#   r5   r   )r   r#   r   r#   rI   r   r5   r   )r   r#   r   r#   r%   r#   r   r#   r   r   r5   r   )r   r   r   r#   r   r#   r   r   r   r   r   rF   r5   r6   )r  r#   r5   r6   )r7  r1   rg   r#   r8  r#   r5   r6   )
rd   r   r   rF   r%   r#   r   r#   r5   r6   )rd   r   r%   r#   r   r#   r5   r6   )#r*   r+   r,   rQ   r   r   rI   r   r   r   r   r   r   r   r   r   r   r
   r   r   r   r   r   r   r  r6  r:  r  r  r  r  r  r  r  r  r/   r/   r/   r0   r   !  sD    
















	

%

F
D








r   r$   backendc                   s   |dkrdS |dkrt d dS t }|st d dS d fd	d
}| \}}tj|d g ||dj}|dkrBt d   dS dS )NnoneTninjazKOnly ninja backend is supported to rebuild the project before installation.z%Can't find ninja, can't rebuild test.Fr5   DT.Tuple[T.Optional[EnvironOrDict], T.Optional[T.Callable[[], None]]]c                    s&  t  st dkrdd l} tj }tjdd ur@|d|dd|dd z
| t	j
}W n5 ty?   Y dS w tjdd uri|dz| }W n
 ty^   Y dS w |j|j |j
}ndS ttjdjt	kr|dS |d< ||d	< d fdd}||fS dS )Nr   Z	SUDO_USERZSUDO_UIDZSUDO_GID)NNZ	DOAS_USERzbuild.ninjaZUSERHOMEr5   r6   c                     sD   t dd  d urtt  d ur tt d S d S )NzDropping privileges to z before running ninja...)r   rU   setgidr|   setuidr/   Zorig_gidZorig_uidZ	orig_userr/   r0   wrapped&  s   z5rebuild_all.<locals>.drop_privileges.<locals>.wrappedr5   r6   )r   rU   geteuidpwdr  r   r  popgetpwuidr|   pw_dirKeyErrorgetpwnampw_uidpw_gidrl   rR   r   st_uid)rc  rM  homedirZpwdatar`  r$   r_  r0   drop_privileges  s<   


z$rebuild_all.<locals>.drop_privilegesr7   )rM  
preexec_fnr   zCould not rebuild )r5   r[  )r   r   Zdetect_ninjar   runr   )r$   rX  rZ  rn  rM  ro  retr/   rm  r0   rebuild_all  s    
-rr  optsr   c                 C  s\  d}t j|}t j|d}t jt j| j|s td | jsSt	
| j}td|jjtd}t| td|jjtd}t| j|sStd t | j tt j|d	d
dd?}t| |}t|d t|d | jrdd l}	t j|d}
|	jdt t |
d n|| W d    dS W d    dS 1 sw   Y  dS )Nzmeson-private/install.datz../meson-logszAInstall data not found. Run this command in build directory root.r   Zvsenvr#   rX  zinstall-log.txtwzutf-8)encodingz"# List of files installed by Mesonz5# Does not contain files installed by custom scripts.r   zprofile-installer.logz"installer.do_install(datafilename))filename)rU   rR   rX   r   rY   r$   r   r   r   r   loadTcastr   r   Z
get_optionr   r   rr  chdiropenr   rc   r!   ZcProfileZrunctxglobalslocalsr6  )rs  r  Zprivate_dirZlog_dirbZ
need_vsenvrX  rG   	installerr!   rg   r/   r/   r0   rp  :  s:   









rp  )r3   r4   r5   r6   )rg   r#   r5   r   rf   )rR   r#   ri   r   r5   r   )rG   rH   ro   r#   r5   r6   )NNNT)rR   r#   rt   ru   rv   ru   rw   rx   ri   r   r5   r6   )NT)
rR   r#   r   r|   rw   rx   ri   r   r5   r6   )rR   r#   r   r   r5   r6   )rR   r#   r   r   r   r   r5   r6   ra  )r%   r#   r   r#   rR   r#   r5   r#   )rg   r#   r5   r#   )r$   r#   rX  r#   r5   r   )rs  r   r5   r|   )C
__future__r   r   rD   r   rU   r&  rG  r   r   r   typingry  r@   r   r   r   Zbackend.backendsr   Zmesonlibr	   r
   r   r   r   r   r   r   scriptsr   r   Zscripts.meson_exer   __main__r   r1  ImportErrorTYPE_CHECKINGr   r   r   r   r   r   r   r   AttributeErrortyping_extensionsr   r   r2   r.   rE   rF   rh   rn   rc   r   r   r   r   r   r   r   r   rr  rp  r/   r/   r/   r0   <module>   sn   (

&

	



   
YC