o
    8cZ1                     @  s,  d dl mZ d dlmZmZm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 dd	lmZmZmZmZ dd
lmZmZmZmZmZ ddlmZmZm Z m!Z! e	j"rddl
m#Z# ddl$m%Z% ddlm&Z&m'Z' d dl(m)Z) G dd de)Z*G dd de)Z+G dd deZ,dddZ-dS )    )annotations)PathPurePathPureWindowsPathN   )ExtensionModuleModuleReturnValue
ModuleInfo   )mlog)CustomTargetInvalidArguments)
INSTALL_KWINSTALL_MODE_KWINSTALL_TAG_KWNoneType)
FeatureNew	KwargInfotyped_kwargstyped_pos_argsnoKwargs)FileMesonExceptionhas_path_seppath_is_in_root)ModuleState)Interpreter)FileOrStringFileMode)	TypedDictc                   @  s   e Zd ZU dZded< dS )
ReadKwArgszKeyword Arguments for fs.read.strencodingN__name__
__module____qualname____doc____annotations__ r)   r)   thome/ych/rk3568/buildroot/output/rockchip_rk3568_recovery/host/lib/python3.10/site-packages/mesonbuild/modules/fs.pyr    (   s   
 r    c                   @  s2   e Zd ZU dZded< ded< ded< ded< d	S )
CopyKwzKwargs for fs.copyboolinstallzT.Optional[str]install_dirr   install_modeinstall_tagNr#   r)   r)   r)   r*   r+   -   s   
 r+   c                      sZ  e Zd ZeddZdY fddZdZddZdZddZee	dde
ded[ddZee	dde
deefd\ddZee	d de
d ed[d!d"Zee
d#ed]d$d%Zee
d&eefd\d'd(Zee
d)ed]d*d+Zee
d,ed]d-d.Zee
d/eefed^d1d2Zee
d3eefd_d5d6Zee
d7eefeefd`d9d:Zee
d;eefed^d<d=Zee
d>eefdad?d@Zee
dAeefdadBdCZee
dDeefe	dDddadEdFZe	dGdHe
dGeefedGedIedJdKdbdMdNZe	dOdPe
dOeefegdQedOeee edRee!fdcdWdXZ"  Z#S )dFSModulefsz0.53.0interpreter'Interpreter'returnNonec                   s   t  | | ji d| jd| jd| jd| jd| jd| j	d| j
d| jd	| jd
| jd| jd| jd| jd| jd| jd| j d S )N
expanduseris_absoluteas_posixexists
is_symlinkis_fileis_dirhashsizeis_samepathreplace_suffixparentnamestemreadcopyfile)super__init__methodsupdater7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   )selfr3   	__class__r)   r*   rH   ;   sD   	

zFSModule.__init__state'ModuleState'arg'FileOrString'r   c                 C  sD   t |trt||j| jj S t|jt|j t|	  S )zX
        make an absolute path from a relative path, WITHOUT resolving symlinks
        )

isinstancer   r   Zabsolute_pathZsource_rootr3   environmentget_build_dirsubdirr7   )rK   rN   rP   r)   r)   r*   _absolute_dirP   s   
 zFSModule._absolute_dirc                 C  s0   |  ||}z| }W |S  ty   Y |S w )z
        resolves symlinks and makes absolute a directory relative to calling meson.build,
        if not already absolute
        )rV   resolve	Exception)rK   rN   rP   pathr)   r)   r*   _resolve_dirX   s   
zFSModule._resolve_dirzfs.expanduserz0.54.0argsT.Tuple[str]kwargsT.Dict[str, T.Any]r!   c                 C  s   t t|d  S Nr   )r!   r   r7   rK   rN   r[   r]   r)   r)   r*   r7   f   s   zFSModule.expanduserzfs.is_absoluteT.Tuple['FileOrString']r,   c                 C  s4   t |d trtdd|j tt|d  S )Nr   zfs.is_absolute_file0.59.0)rR   r   r   use
subprojectr   r!   r8   r`   r)   r)   r*   r8   l   s   zFSModule.is_absolutezfs.as_posixc                 C  s   t |d  S )z
        this function assumes you are passing a Windows path, even if on a Unix-like system
        and so ALL '' are turned to '/', even if you meant to escape a character
        r   )r   r9   r`   r)   r)   r*   r9   t   s   zFSModule.as_posixz	fs.existsc                 C     |  ||d  S r_   )rZ   r:   r`   r)   r)   r*   r:   ~      zFSModule.existszfs.is_symlinkc                 C  s4   t |d trtdd|j | ||d  S )Nr   zfs.is_symlink_filerb   )rR   r   r   rc   rd   rV   r;   r`   r)   r)   r*   r;      s   zFSModule.is_symlinkz
fs.is_filec                 C  re   r_   )rZ   r<   r`   r)   r)   r*   r<      rf   zFSModule.is_filez	fs.is_dirc                 C  re   r_   )rZ   r=   r`   r)   r)   r*   r=      rf   zFSModule.is_dirzfs.hashT.Tuple['FileOrString', str]c                 C  s   t |d trtdd|j | ||d }| s#t| dz	t	|d }W n t
y<   td|d w td|d || j ||  | S )Nr   zfs.hash_filerb   z- is not a file and therefore cannot be hashedr   z"hash algorithm {} is not availablez$computing {} sum of {} size {} bytes)rR   r   r   rc   rd   rZ   r<   r   hashlibnew
ValueErrorformatr   debugstatst_sizerJ   
read_bytes	hexdigest)rK   rN   r[   r]   filehr)   r)   r*   r>      s   zFSModule.hashzfs.sizeintc                 C  st   t |d trtdd|j | ||d }| s#t| dz| j	W S  t
y9   td|d w )Nr   zfs.size_filerb   z, is not a file and therefore cannot be sizedz{} size could not be determined)rR   r   r   rc   rd   rZ   r<   r   rm   rn   rj   rk   )rK   rN   r[   r]   rq   r)   r)   r*   r?      s   zFSModule.sizezfs.is_samepath'T.Tuple['FileOrString', 'FileOrString']c                 C  s   t |d tst |d trtdd|j | ||d }| ||d }| s-dS | s3dS z||W S  tyC   Y dS w )Nr   r   zfs.is_samepath_filerb   F)	rR   r   r   rc   rd   rZ   r:   samefileOSError)rK   rN   r[   r]   Zfile1Zfile2r)   r)   r*   r@      s   zFSModule.is_samepathzfs.replace_suffixc                 C  sF   t |d trtdd|j tt|d }||d }t|S )Nr   zfs.replace_suffix_filerb   r   )rR   r   r   rc   rd   r   r!   with_suffixrK   rN   r[   r]   originalri   r)   r)   r*   rA      s
   zFSModule.replace_suffixz	fs.parentc                 C  >   t |d trtdd|j tt|d }|j}t|S )Nr   zfs.parent_filerb   )rR   r   r   rc   rd   r   r!   rB   rx   r)   r)   r*   rB      
   zFSModule.parentzfs.namec                 C  rz   )Nr   zfs.name_filerb   )rR   r   r   rc   rd   r   r!   rC   rx   r)   r)   r*   rC      r{   zFSModule.namezfs.stemc                 C  rz   )Nr   zfs.stem_filerb   )rR   r   r   rc   rd   r   r!   rD   rx   r)   r)   r*   rD      s
   zFSModule.stemzfs.readz0.57.0r"   zutf-8)default'ReadKwArgs'c                 C  s
  |d }|d }| j jj}| j j}| j j }t|tr-|jr#tdt	j
|| }n|r6t	j
||}t	j
||}t	j
|}tt|t|ddrRtdzt||d}	|	 }
W d   n1 shw   Y  W n ty|   td	| w | j | |
S )
aO  Read a file from the source tree and return its value as a decoded
        string.

        If the encoding is not specified, the file is assumed to be utf-8
        encoded. Paths must be relative by default (to prevent accidents) and
        are forbidden to be read from the build directory (to prevent build
        loops)
        r   r"   z2fs.read_file does not accept built files() objectsT)rW   z"path must not be in the build tree)r"   Nzdecoding failed for )r3   rS   
source_dirrU   rT   rR   r   Zis_builtr   osrY   joinZrelative_nameabspathr   r   openrE   UnicodeDecodeErrorZadd_build_def_file)rK   rN   r[   r]   rY   r"   src_dirZsub_dir	build_dirfdatar)   r)   r*   rE      s6   


zFSModule.readzfs.copyfilez0.64.0)Zoptargsr.   r   &T.Tuple[FileOrString, T.Optional[str]]r+   r   c                 C  s   |d r|d st d| j|d gd }|d r|d ntj|j}t|r.t dt||j	|j
|j|j g d |g|gd|d |d g|d	 |d
 g|jd}t||gS )z3Copy a file into the build directory at build time.r-   r.   z6"install_dir" must be specified when "install" is truer   r   z-Destination path may not have path separators)z
--internalcopyz@INPUT@z@OUTPUT@Tr/   r0   )Zbuild_by_defaultr-   r.   r/   r0   backend)r   r3   Zsource_strings_to_filesr   rY   basenamefnamer   r   rU   rd   rS   Zget_build_commandr   r   )rK   rN   r[   r]   srcdestctr)   r)   r*   rF     s,   zFSModule.copyfile)r3   r4   r5   r6   )rN   rO   rP   rQ   r5   r   )rN   rO   r[   r\   r]   r^   r5   r!   )rN   rO   r[   ra   r]   r^   r5   r,   )rN   rO   r[   r\   r]   r^   r5   r,   )rN   rO   r[   rg   r]   r^   r5   r!   )rN   rO   r[   ra   r]   r^   r5   rs   )rN   rO   r[   rt   r]   r^   r5   r,   )rN   rO   r[   ra   r]   r^   r5   r!   )rN   rO   r[   ra   r]   r}   r5   r!   )rN   r   r[   r   r]   r+   r5   r   )$r$   r%   r&   r	   INFOrH   rV   rZ   r   r   r   r!   r7   r   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   r   r   rE   r   r   r   r   rF   __classcell__r)   r)   rL   r*   r1   7   s    


'r1   r[   T.Anyr]   r5   c                  O  s   t | i |S )N)r1   )r[   r]   r)   r)   r*   
initialize:  s   r   )r[   r   r]   r   r5   r1   ).
__future__r   pathlibr   r   r   rh   r   typingT r   r   r	   r   buildr   r   Zinterpreter.type_checkingr   r   r   r   Zinterpreterbaser   r   r   r   r   Zmesonlibr   r   r   r   TYPE_CHECKINGr   r3   r   r   r   typing_extensionsr   r    r+   r1   r   r)   r)   r)   r*   <module>   s,   
  