o
    uJAfg‚  ã                   @  sâ  d dl mZ d dlmZ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Zd dlZd dlZddlmZ ddl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"m#Z#m$Z$ ej%r¹d dl&m'Z' ddlm(Z( ej)ej* Z+G dd„ de'ƒZ,G dd„ de,ƒZ-G dd„ de,ƒZ.G dd„ de,ƒZ/G dd„ de,ƒZ0G dd„ de,ƒZ1G dd„ de,ƒZ2d 3e!¡Z4d<d!d"„Z5G d#d$„ d$ƒZ6ed%d&G d'd(„ d(ƒƒZ7d=d,d-„Z8d=d.d/„Z9d>d2d3„Z:d?d5d6„Z;d@d:d;„Z<dS )Aé    )Úannotations)Ú	dataclassÚInitVarN)ÚThreadPoolExecutor)ÚPathé   )Úmlog)ÚIntrospectionInterpreter)Ú	quiet_gitÚGitExceptionÚ
Popen_safeÚMesonExceptionÚwindows_proof_rmtree)ÚResolverÚWrapExceptionÚ	ALL_TYPESÚparse_patch_urlÚupdate_wrap_fileÚget_releases)ÚProtocol)ÚPackageDefinitionc                   @  s>   e Zd ZU ded< ded< ded< ded< ded	< d
ed< dS )Ú	ArgumentsÚstrÚ	sourcedirÚintÚnum_processesúT.List[str]ÚsubprojectsÚtypeszT.Callable[[], bool]Úsubprojects_funcÚboolÚallow_insecureN©Ú__name__Ú
__module__Ú__qualname__Ú__annotations__© r'   r'   ú</usr/lib/python3.10/site-packages/mesonbuild/msubprojects.pyr      s   
 r   c                   @  ó   e Zd ZU ded< ded< dS )ÚUpdateArgumentsr    ÚrebaseÚresetNr"   r'   r'   r'   r(   r*   %   ó   
 r*   c                   @  ó   e Zd ZU ded< ded< dS )ÚUpdateWrapDBArgumentsr    ÚforcezT.Dict[str, T.Any]ÚreleasesNr"   r'   r'   r'   r(   r/   )   r-   r/   c                   @  r.   )ÚCheckoutArgumentsr    Úbr   Úbranch_nameNr"   r'   r'   r'   r(   r2   -   r-   r2   c                   @  r.   )ÚForeachArgumentsr   Úcommandr   ÚargsNr"   r'   r'   r'   r(   r5   1   r-   r5   c                   @  r)   )ÚPurgeArgumentsr    ÚconfirmÚinclude_cacheNr"   r'   r'   r'   r(   r8   5   r-   r8   c                   @  r)   )ÚPackagefilesArgumentsr    ÚapplyÚsaveNr"   r'   r'   r'   r(   r;   9   r-   r;   ú, Úpathr   Ú	base_pathÚreturnúT.Set[Path]c                   s”   | j dkr)t | d¡}‡ fdd„| ¡ D ƒ}W d   ƒ |S 1 s"w   Y  |S t | ¡}‡ fdd„|D ƒ}W d   ƒ |S 1 sCw   Y  |S )Nz.zipÚrc                   ó   h | ]}ˆ |j  ’qS r'   )Úfilename©Ú.0Úi©r@   r'   r(   Ú	<setcomp>B   ó    z%read_archive_files.<locals>.<setcomp>c                   rD   r'   )ÚnamerF   rI   r'   r(   rJ   E   rK   )ÚsuffixÚzipfileÚZipFileÚinfolistÚtarfileÚopen)r?   r@   Zzip_archiveÚarchive_filesZtar_archiver'   rI   r(   Úread_archive_files?   s   

ÿûþ
ÿþrT   c                   @  s>   e Zd Zddd„Zddd„Zdd	d
„Zddd„Zddd„ZdS )ÚLoggerÚtotal_tasksr   rA   ÚNonec                 C  s(   t  ¡ | _|| _d| _tƒ | _d| _d S )Nr   Ú )Ú	threadingÚLockÚlockrV   Úcompleted_tasksÚsetÚrunning_tasksÚshould_erase_line)ÚselfrV   r'   r'   r(   Ú__init__I   s
   

zLogger.__init__c                 C  s"   | j rt| j dd d| _ d S d S )Nú©ÚendrX   )r_   Úprint©r`   r'   r'   r(   ÚflushP   s   
þzLogger.flushc                 C  s‚   d| j › d| j› }t ¡ jt|ƒ }d | j¡}t|ƒd |kr+|d |d … d }|d|› d }t| j	|d	d
d d| _	d S )Nz
Progress: z / r>   é   é   ú...z (ú)rX   rb   )Úseprd   z[K)
r\   rV   ÚshutilÚget_terminal_sizeÚcolumnsÚlenÚjoinr^   re   r_   )r`   ÚlineÚmax_lenÚrunningr'   r'   r(   Úprint_progressU   s   
zLogger.print_progressÚ	wrap_namer   c                 C  s@   | j  | j |¡ |  ¡  W d   ƒ d S 1 sw   Y  d S ©N)r[   r^   Úaddru   )r`   rv   r'   r'   r(   Ústart_   s   
"þzLogger.startÚ	log_queueú,T.List[T.Tuple[mlog.TV_LoggableList, T.Any]]c                 C  st   | j - |  ¡  |D ]\}}tj|i |¤Ž q
| j |¡ |  jd7  _|  ¡  W d   ƒ d S 1 s3w   Y  d S )Nr   )r[   rg   r   Úlogr^   Úremover\   ru   )r`   rv   rz   r7   Úkwargsr'   r'   r(   Údoned   s   
"úzLogger.doneN)rV   r   rA   rW   ©rA   rW   )rv   r   rA   rW   )rv   r   rz   r{   rA   rW   )r#   r$   r%   ra   rg   ru   ry   r   r'   r'   r'   r(   rU   H   s    




rU   F)Úeqc                   @  sN  e Zd ZU ded< ded< ded< ded< d	ed
< dSdd„ZdTdd„ZdUdd„ZedVdd„ƒZdUdd„Z	dUdd„Z
dWd"d#„ZdXd$d%„ZdYd&d'„ZdYd(d)„ZdZd+d,„ZdZd-d.„Zd[d\d1d2„ZdZd3d4„ZdZd5d6„Zd]d9d:„ZdUd;d<„ZdYd=d>„ZdUd?d@„ZdUdAdB„ZdUdCdD„ZdUdEdF„ZdUdGdH„ZdUdIdJ„ZdUdKdL„Zed^dNdO„ƒZdUdPdQ„ZdRS )_ÚRunnerrU   ÚloggerzInitVar[Resolver]rC   r   Úwrapr   Úrepo_dirú'Arguments'Úoptionsr   rA   rW   c                 C  sH   t   |¡| _tj |j| jj¡| j_| j| j_| j	j
 | ¡| _g | _d S rw   )ÚcopyÚwrap_resolverÚosr?   rq   Úsubdir_rootr„   Ú	directoryÚdirnamer‡   r   Ú__get__Ú
run_methodrz   )r`   rC   r'   r'   r(   Ú__post_init__v   s
   

zRunner.__post_init__r7   úmlog.TV_Loggabler~   úT.Anyc                 O  s   | j  t|ƒ|f¡ d S rw   )rz   ÚappendÚlist)r`   r7   r~   r'   r'   r(   r|      s   z
Runner.logr    c              
   C  st   | j  | jj¡ z|  ¡ }W n ty- } z|  t d¡t	|ƒ¡ d}W Y d }~nd }~ww | j  
| jj| j¡ |S )NzError:F)rƒ   ry   r„   rL   r   r   r|   r   Úredr   r   rz   )r`   ÚresultÚer'   r'   r(   Úrun‚   s   €þz
Runner.runú'UpdateWrapDBArguments'c                 C  s   t | jƒ| _d S rw   )r   r!   r1   ©r‡   r'   r'   r(   Úpre_update_wrapdbŒ   s   zRunner.pre_update_wrapdbc                 C  s”  |   d| jj› d¡ t d| j¡}|j | jj¡}|s#|   d¡ dS z| j d¡}| dd¡\}}W nP t	yO   |j
sI|   d	t d
¡¡ Y dS d  }}Y n5 tyƒ   z| j d¡}t|ƒ\}}W n ty€   |j
sz|   d	t d¡¡ Y Y dS d  }}Y nw Y nw |d d }| dd¡\}}	||ksš|	|kr¿| jjr¢| jjn| jj› d}
t|
| jj||	|jƒ |   dt |¡¡ dS |   dt |¡¡ dS )Nz#Checking latest WrapDB version for rj   r/   z  -> Wrap not found in wrapdbTÚwrapdb_versionú-r   ú  ->z<Malformed wrapdb_version field, use --force to update anywayFÚ	patch_urlzACould not determine current version, use --force to update anywayÚversionsr   z.wrapz  -> New version downloaded:z  -> Already at latest version:)r|   r„   rL   ÚTÚcastr‡   r1   ÚgetÚsplitÚ
ValueErrorr0   r   r•   r   r   ÚrsplitÚhas_wraprE   r   r!   Úblue)r`   r‡   Úinforœ   ÚbranchÚrevisionrŸ   Úlatest_versionZ
new_branchÚnew_revisionrE   r'   r'   r(   Úupdate_wrapdb   sL   
ü€ú
þþzRunner.update_wrapdbc              
   C  s”   t  d| j¡}|jr>t| jƒ z| j | jj	¡ |  
d¡ W dS  ty= } z|  
dt t|ƒ¡¡ W Y d }~dS d }~ww |  
d¡ |  
d¡ dS )Nr*   z  -> New version extractedTrž   Fzd  -> Subproject has not changed, or the new source/patch needs to be extracted on the same location.z<     Pass --reset option to delete directory and redownload.)r¡   r¢   r‡   r,   r   r…   r‰   Úresolver„   rL   r|   r   r   r•   r   )r`   r‡   r—   r'   r'   r(   Úupdate_file½   s   

€þ

zRunner.update_fileÚcmdr   c                 C  s   t || jddd S )NT)Úcheckr   )r
   r…   ©r`   r±   r'   r'   r(   Ú
git_outputÓ   ó   zRunner.git_outputc                 C  s   |   |  |¡¡ d S rw   )r|   r´   r³   r'   r'   r(   Úgit_verboseÖ   rµ   zRunner.git_verbosec                 C  s.   t g d¢| jƒd  ¡ r|  g d¢¡ d S d S )N)Ústatusz--porcelainú":!/.meson-subproject-wrap-hash.txtr   )ZstashÚpushz--allr¸   Ú.)r
   r…   Ústripr¶   rf   r'   r'   r(   Ú	git_stashÙ   s   ùzRunner.git_stashc              
   C  sZ   |   g d¢¡}dd„ | d¡D ƒ}|  dt |d ¡t |d ¡|d t |d	 ¡¡ d S )
N)Zshowz--quietz!--pretty=format:%h%n%d%n%s%n[%an]c                 S  ó   g | ]}|  ¡ ‘qS r'   ©r»   )rG   Úsr'   r'   r(   Ú
<listcomp>è   ó    z#Runner.git_show.<locals>.<listcomp>Ú
rž   r   r   é   rh   )r´   r¤   r|   r   Úyellowr•   r¨   )r`   Zcommit_messageÚpartsr'   r'   r(   Úgit_showæ   s   8zRunner.git_showr«   c                 C  s   z
|   g d¢¡ W dS  tyG } z1|   g d¢¡ |  dt | j¡dt |¡d¡ |  t |j¡¡ |  t t|ƒ¡¡ W Y d }~dS d }~ww )N)ú-cúrebase.autoStash=truer+   Ú
FETCH_HEAD)rÇ   rÈ   r+   z--abortz  -> Could not rebaseZontoz
-- abortedFT)	r´   r   r|   r   Úboldr…   r•   Úoutputr   ©r`   r«   r—   r'   r'   r(   Ú
git_rebaseë   s   ùÿ€úzRunner.git_rebasec                 C  sœ   z|   ¡  |  g d¢¡ | j ¡  | j ¡  W dS  tyM } z)|  dt | j	¡dt |¡¡ |  t 
|j¡¡ |  t 
t|ƒ¡¡ W Y d }~dS d }~ww )N)r,   z--hardrÉ   z  -> Could not resetÚtoFT)r¼   r´   r‰   Úapply_patchÚapply_diff_filesr   r|   r   rÊ   r…   r•   rË   r   rÌ   r'   r'   r(   Ú	git_reset÷   s   
û€üzRunner.git_resetFÚcreatec                 C  s¦   ddg}|r|  d¡ ||dg7 }z|  ¡  |  |¡ W dS  tyR } z)|  dt |¡dt | j¡¡ |  t |j	¡¡ |  t t
|ƒ¡¡ W Y d }~dS d }~ww )	NÚcheckoutz--ignore-other-worktreesú-bz--z  -> Could not checkoutÚinFT)r“   r¼   r´   r   r|   r   rÊ   r…   r•   rË   r   )r`   r«   rÒ   r±   r—   r'   r'   r(   Úgit_checkout  s   
û€üzRunner.git_checkoutc                 C  ó   |   |¡}|r|  |¡}|S rw   )rÖ   rÑ   ©r`   r«   Úsuccessr'   r'   r(   Úgit_checkout_and_reset  ó   

zRunner.git_checkout_and_resetc                 C  r×   rw   )rÖ   rÍ   rØ   r'   r'   r(   Úgit_checkout_and_rebase  rÛ   zRunner.git_checkout_and_rebaseÚurlsr]   c                 C  sr   g d¢}t || jƒ\}}|sdS z|jdddd }W n
 ty%   Y dS w dd|g}t || jƒ\}}| ¡ |v S )	N)ú	rev-parseú--abbrev-refz--symbolic-full-namez@{upstream}Fú/r   )Úmaxsplitr   Úremoteúget-url)r
   r…   r¤   Ú
IndexErrorr»   )r`   rÝ   r±   ÚretZupstreamrâ   Z
remote_urlr'   r'   r(   Úgit_branch_has_upstream'  s   ÿ
zRunner.git_branch_has_upstreamc                 C  s  t  d| j¡}tj tj | jd¡¡sU|jrIt	| jƒ z| j
 | jj¡ |  ¡  W dS  tyH } z|  dt t|ƒ¡¡ W Y d }~dS d }~ww |  d¡ |  d¡ dS | jj d¡}| jj d	¡}| jj d
¡}|rn|su|  d¡ dS z|  g d¢¡ ¡ }W n0 ty° } z$|  dt | j¡¡ |  t |j¡¡ |  t t|ƒ¡¡ W Y d }~dS d }~ww |jrüz|  ddd|g¡ |rÊ|  dddd|g¡ W nB tyû } z$|  dt | j¡¡ |  t |j¡¡ |  t t|ƒ¡¡ W Y d }~dS d }~ww ||kr|  d|›d|›¡ dS z|  g d¢¡ ¡ }|dkr|nd}W n1 tyS } z$|  dt | j¡¡ |  t |j¡¡ |  t t|ƒ¡¡ W Y d }~dS d }~ww | j
 |¡rrtdd|d g| jƒd rr|  dd|g¡ nIzd}d }	|  dd!|d!|	d|g¡ W n6 tyº } z)|  d"t |¡d#t | j¡¡ |  t |j¡¡ |  t t|ƒ¡¡ W Y d }~dS d }~ww |dkrÐ|jrÊ|  |¡}
n8|  |¡}
n2||krå|jrß|  |¡}
n#|   |¡}
n|jrï|  |¡}
n|  !||h¡rý|  |¡}
n|   |¡}
|
r	|  ¡  |
S )$Nr*   z.gitTrž   Fz  -> Not a git repository.z7Pass --reset option to delete directory and redownload.r«   Úurlzpush-urlz"  -> No revision or URL specified.)râ   rã   Úoriginz.  -> Failed to determine current origin URL inrâ   zset-urlrè   z--pushz"  -> Failed to reset origin URL inz  -> URL changed from ú to )rÞ   rß   ÚHEADrê   rX   z*  -> Failed to determine current branch inrÞ   z--verifyz	^{commit}r   Úfetchrº   z#+refs/heads/*:refs/remotes/origin/*z+refs/tags/*:refs/tags/*z--refmapz  -> Could not fetch revisionrÕ   )"r¡   r¢   r‡   rŠ   r?   Úexistsrq   r…   r,   r   r‰   r¯   r„   rL   Úupdate_git_doner   r|   r   r•   r   Úvaluesr£   r´   r»   r   rÊ   rË   Úis_git_full_commit_idr
   rÚ   rÜ   rÑ   rÍ   ræ   )r`   r‡   r—   r«   rç   Úpush_urlZ
origin_urlrª   Zheads_refmapZtags_refmaprÙ   r'   r'   r(   Ú
update_git4  s°   
€þ


€ü€€ü
€üÿ€ü


zRunner.update_gitc                 C  s   |   g d¢¡ |  ¡  d S )N)Ú	submoduleÚupdatez
--checkoutz--recursive)r´   rÆ   rf   r'   r'   r(   rí     s   zRunner.update_git_donec                 C  sx   | j  d¡}| ¡ dkrtjddg| jd dS tjdd|g| jddkr:tjddg| jd tjdd|g| jd dS )	Nr«   ÚtipÚhgZpull©ÚcwdrÓ   r   T)r„   r£   ÚlowerÚ
subprocessÚcallr…   Ú
check_call)r`   Úrevnor'   r'   r(   Ú	update_hg¡  s   ýzRunner.update_hgc                 C  sv   | j  d¡}tdddd| jgƒ\}}}|}||krdS | ¡ dkr-tjddg| jd dS tjddd	|g| jd dS )
Nr«   Úsvnr©   z--show-itemTÚheadró   rö   z-r)r„   r£   r   r…   rø   rù   rú   rû   )r`   rü   Ú_ÚoutZcurrent_revnor'   r'   r(   Ú
update_svn®  s   ÿzRunner.update_svnc                 C  sî   |   d| jj› d¡ d}tj | j¡s|   d¡ | jj }nF| jj	dkr*|  
¡ }n;| jj	dkr5|  ¡ }n0| jj	dkr@|  ¡ }n%| jj	dkrK|  ¡ }n| jj	d u r\|   d	¡ | jj }n	|   d
| jj	d¡ |rutj | j¡ru| j | j¡ |S )Nz	Updating rj   Fz  -> Not used.ÚfileÚgitrõ   rþ   z/  -> Cannot update subproject with no wrap filez  -> Cannot updateÚ
subproject)r|   r„   rL   rŠ   r?   Úisdirr…   r‡   r   Útyper°   rñ   rý   r  Úupdate_hash_cache)r`   rÙ   r'   r'   r(   ró   ½  s(   





zRunner.updatec                 C  sˆ   t  d| j¡}| jjdkstj | j¡sdS |j	r|j	n| j 
d¡}|s&dS |  d|› d| jj› d¡ | j||jdrB|  ¡  dS d	S )
Nr2   r  Tr«   z	Checkout z in rj   )rÒ   F)r¡   r¢   r‡   r„   r  rŠ   r?   r  r…   r4   r£   r|   rL   rÖ   r3   rÆ   )r`   r‡   r4   r'   r'   r(   rÓ   Ö  s   zRunner.checkoutc              
   C  s   |   d| jj› d¡ tj | j¡r|   d¡ dS z| j | jj¡ |   d¡ W dS  t	yG } z|   dt
 t|ƒ¡¡ W Y d }~dS d }~ww )Nz	Download rj   z  -> Already downloadedTz	  -> donerž   F)r|   r„   rL   rŠ   r?   r  r…   r‰   r¯   r   r   r•   r   )r`   r—   r'   r'   r(   Údownloadå  s   
ý€þzRunner.downloadc                 C  s¶   t  d| j¡}|  d| j› ¡ tj | j¡s|  d¡ dS |jg|j	 }t
|tj| jd\}}}|jdkrRd d |¡|j¡}|  d	t |¡¡ | j|d
d dS | j|d
d dS )Nr5   zExecuting command in ú  -> Not downloaded yetT)Ústderrr÷   r   z.Command '{}' returned non-zero exit status {}.ú z  -> rX   rc   F)r¡   r¢   r‡   r|   r…   rŠ   r?   r  r6   r7   r   rù   ÚSTDOUTÚ
returncodeÚformatrq   r   r•   )r`   r‡   r±   Úpr  r   Zerr_messager'   r'   r(   Úforeachò  s   

zRunner.foreachc              
   C  s$  t  d| j¡}| jjsdS | jjr(t| jjƒ ¡ }|j	r | 
¡  t d|› ¡ | jjdkrEt| jjƒ ¡ }|j	r=| 
¡  |  d|› ¡ |jr¶t| jjƒ ¡ }z|| j d¡ }| ¡ rl|j	rd| 
¡  |  d|› ¡ W n	 tyv   Y nw z|| j d¡ }| ¡ r“|j	r‹| 
¡  |  d|› ¡ W n	 ty   Y nw zt| ¡ ƒs«tt|ƒƒ W n	 tyµ   Y nw t| jƒ}|j ¡ |j }| ¡ rØ|j	rÎ| 
¡  |  d|› ¡ dS | ¡ sÞdS z|j	rètt|ƒƒ |  d|› ¡ W dS  ty } zt d|› d|› ¡ W Y d }~d	S d }~ww )
Nr8   Tz	Deleting ÚredirectÚsource_filenameÚpatch_filenamezUnable to remove: z: F) r¡   r¢   r‡   r„   r  Ú
redirectedr   Úoriginal_filenamer¯   r9   Úunlinkr   r|   rE   r:   r‰   Úcachedirr£   Úis_filer   ÚanyÚiterdirr   r   ÚFileNotFoundErrorr…   ÚparentrL   Ú
is_symlinkÚis_dirÚOSErrorÚerror)r`   r‡   Zredirect_fileÚpackagecacheZsubproject_cache_fileZsubproject_patch_fileZsubproject_source_dirr—   r'   r'   r(   Úpurge  sz   €ÿ€ÿ€ÿ
ü€þzRunner.purgeú'PurgeArguments'c                 C  s"   | j st d¡ t d¡ d S d S )NrX   z<Nothing has been deleted, run again with --confirm to apply.)r9   r   r|   rš   r'   r'   r(   Ú
post_purgeL  s   
þzRunner.post_purgec                 C  s†  t  d| j¡}|jr|jrtdƒ dS |jr6|  d| jj› d¡ t	j
 | j¡s/|  d¡ dS | j ¡  dS |jrÁd| jjvrFt d	¡ dS d
| jjvrSt d¡ dS t| jj| jjd
 ƒ}t| jj dd¡ƒ}t| jƒ}t| jj| jjd ƒ}|r||n|j}t||ƒ}t| d¡ƒ}|  d| jj› d|› d¡ t |¡ || D ]}	|	 ¡ s©q¢|	 |¡}
||
 }|jjddd t  |	|¡ q¢dS )Nr;   z0error: --apply and --save are mutually exclusiveFz#Re-applying patchfiles overlay for rj   r
  TÚpatch_directoryz-can only save packagefiles to patch_directoryr  z-can only save packagefiles from a [wrap-file]Úlead_directory_missingz**/*zSaving ré   )ÚparentsÚexist_ok)!r¡   r¢   r‡   r<   r=   re   r|   r„   rL   rŠ   r?   r  r…   r‰   rÏ   rî   r   r!  r   r  r    r£   Úfilesdirr  rT   r]   Úglobrm   Úrmtreer  Úrelative_toÚmkdirÚcopyfile)r`   r‡   Zarchive_pathr'  rŒ   Úpackagefilesr@   rS   Zdirectory_filesZsrc_pathÚrel_pathZdst_pathr'   r'   r(   r0  R  sF   







zRunner.packagefilesN)rC   r   rA   rW   )r7   r‘   r~   r’   rA   rW   )rA   r    )r‡   r™   rA   rW   )r±   r   rA   r   )r±   r   rA   rW   r€   )r«   r   rA   r    )F)r«   r   rÒ   r    rA   r    )rÝ   r]   rA   r    )r‡   r$  rA   rW   ) r#   r$   r%   r&   r   r|   r˜   Ústaticmethodr›   r®   r°   r´   r¶   r¼   rÆ   rÍ   rÑ   rÖ   rÚ   rÜ   ræ   rñ   rí   rý   r  ró   rÓ   r	  r  r#  r%  r0  r'   r'   r'   r(   r‚   n   sF   
 

	



-










i






Hr‚   r  úargparse.ArgumentParserrW   c                 C  sR   | j dddd | j dddt› dd | j d	d
d tdd | j ddddd d S )Nz--sourcedirrº   zPath to source directory)ÚdefaultÚhelpz--typesrX   z?Comma-separated list of subproject types. Supported types are: z (default: all)z-jz--num-processesz2How many parallel processes to use (Since 0.59.0).)r4  r  r5  z--allow-insecureFÚ
store_truez"Allow insecure server connections.©r4  Úactionr5  )Úadd_argumentÚALL_TYPES_STRINGr   ©r  r'   r'   r(   Úadd_common_arguments|  s   ÿ
ÿÿ

ÿr<  c                 C  s   | j dddd d S )Nr   Ú*z"List of subprojects (default: all)©Únargsr5  )r9  r;  r'   r'   r(   Úadd_subprojects_argument†  s   
ÿr@  Ú
subparsersú'SubParsers'c                 C  sP   | j ddd}|jddddd t|ƒ t|ƒ |jtjd	 |jtjd
 |S )Nró   z,Update wrap files from WrapDB (Since 0.63.0)©r5  z--forceFr6  z4Update wraps that does not seems to come from WrapDBr7  ©r   )Úpre_func)Ú
add_parserr9  r<  r@  Úset_defaultsr‚   r®   r›   )rA  r  r'   r'   r(   Úadd_wrap_update_parserŠ  s   
ÿrH  Úparserc                 C  sä  | j ddd}d|_|jddd}|jddd	d
d |jddd	dd t|ƒ t|ƒ |jtjd |jddd}|jddd	dd |jdddd t|ƒ t|ƒ |jtj	d |jddd}t|ƒ t|ƒ |jtj
d |jddd}|jdddd |jdtjtjd t|ƒ |jg d  |jtjd |jd!d"d}t|ƒ t|ƒ |jd#d	dd$d% |jd&d	dd'd% |jtjd |jtjd( |jd)d*d}t|ƒ t|ƒ |jd+d	dd,d% |jd-d	dd.d% |jtjd d S )/NÚCommandsr6   )ÚtitleÚdestTró   z&Update all subprojects from wrap filesrC  z--rebaser6  zeRebase your branch on top of wrap's revision. Deprecated, it is now the default behaviour. (git only)r7  z--resetFzBCheckout wrap's revision and hard reset to that commit. (git only)rD  rÓ   zCheckout a branch (git only)rÔ   zCreate a new branchr4   ú?zMName of the branch to checkout or create (default: revision set in wrap file)r>  r	  z¸Ensure subprojects are fetched, even if not in use. Already downloaded subprojects are not modified. This can be used to pre-fetch all subprojects and avoid downloads during configure.r  z/Execute a command in each subproject directory.zcommand ...z/Command to execute in each subproject directory)Úmetavarr5  r7   ©r   r#  z*Remove all wrap-based subproject artifactsz--include-cachez Remove the package cache as well)r8  r4  r5  z	--confirmz+Confirm the removal of subproject artifacts)Ú	post_funcr0  zManage the packagefiles overlayz--applyz$Apply packagefiles to the subprojectz--savez%Save packagefiles from the subproject)Úadd_subparsersÚrequiredrF  r9  r<  r@  rG  r‚   ró   rÓ   r	  ÚargparseÚ	REMAINDERÚSUPPRESSr  r#  r%  r0  )rI  rA  r  r'   r'   r(   Úadd_arguments–  sb   
ÿ
ÿ
ÿÿÿ
ÿrV  r‡   r†   r   c                   s`  t j t j ˆ j¡¡}t j t j |d¡¡s"t dt 	|¡d¡ dS t 
¡  t|ddƒ}| ¡  | ¡ p6d}W d   ƒ n1 sAw   Y  t j t j ||¡¡s]t dt 	|¡d¡ d	S t||d
ˆ jd
d}ˆ jrw‡ fdd„|j ¡ D ƒ}nt|j ¡ ƒ}ˆ jrŒdd„ ˆ j d¡D ƒng ‰ˆD ]}|tvr td|›dt› ƒ‚qg }g }t ¡ }	t |	¡ tˆ j ƒ}
ˆr¾‡fdd„|D ƒ}t!ˆ dd ƒ}|rÊ|ˆ ƒ t"t#|ƒƒ}|D ]%}t$|||j%ƒ &¡ }t'||||ˆ ƒ}|	 (|
|j)¡}| *|¡ | *|j+¡ qÒ|	 ,tj-|Ž ¡}| .¡  t!ˆ dd ƒ}|r|ˆ ƒ dd„ t/||ƒD ƒ}|r,d}|d |¡7 }t 0|¡ t#|ƒS )Nzmeson.buildZ	Directoryz-does not seem to be a Meson source directory.r   rX   Únoner   z"does not seem to have subprojects.r   T)Úwrap_frontendr!   Úsilentc                   s   g | ]\}}|ˆ j v r|‘qS r'   rO  )rG   rL   r„   rš   r'   r(   rÀ   Ú  s    zrun.<locals>.<listcomp>c                 S  r½   r'   r¾   )rG   Útr'   r'   r(   rÀ   Ý  rÁ   ú,zUnknown subproject type z, supported types are: c                   s   g | ]	}|j ˆ v r|‘qS r'   )r  )rG   r„   )r   r'   r(   rÀ   ç  s    rE  rP  c                 S  s   g | ]\}}|s|‘qS r'   r'   )rG   rL   rÙ   r'   r'   r(   rÀ   ÷  s    zlPlease check logs above as command failed in some subprojects which could have been left in conflict state: r>   )1rŠ   r?   ÚrelpathÚrealpathr   Úisfilerq   r   r!  rÊ   Ú
no_loggingr	   Úload_root_meson_fileÚextract_subproject_dirr  r|   r   r!   r   ÚwrapsÚitemsr”   rî   r   r¤   r   r   r:  ÚasyncioÚnew_event_loopÚset_event_loopr   r   ÚgetattrrU   rp   r   rŒ   Úas_posixr‚   Úrun_in_executorr˜   r“   rL   Úrun_until_completeÚgatherrg   ÚzipÚwarning)r‡   Ú
source_dirÚintrÚsubproject_dirrC   rb  rZ  ÚtasksZ
task_namesÚloopÚexecutorrE  rƒ   r„   r   ÚrunnerÚtaskÚresultsrP  ÚfailuresÚmr'   )r‡   r   r(   r˜   Ì  sb   
ý ÿ



r˜   )r?   r   r@   r   rA   rB   )r  r3  rA   rW   )rA  rB  rA   r3  )rI  r3  rA   rW   )r‡   r†   rA   r   )=Ú
__future__r   Údataclassesr   r   rŠ   rù   rS  rd  rY   rˆ   rm   Zconcurrent.futures.threadr   Úpathlibr   Útypingr¡   rQ   rN   rX   r   Úastr	   Úmesonlibr
   r   r   r   r   Z	wrap.wrapr   r   r   r   r   r   ÚTYPE_CHECKINGZtyping_extensionsr   r   Ú_SubParsersActionÚArgumentParserZ
SubParsersr   r*   r/   r2   r5   r8   r;   rq   r:  rT   rU   r‚   r<  r@  rH  rV  r˜   r'   r'   r'   r(   Ú<module>   sT     

	&    




6