o
    e	                     @  sz   d dl m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 d dlZejr1d dlZdddZdddZdS )    )annotationsNPath)ThreadPoolExecutor   )lang_suffixes)	quiet_gitfnamer   returnT.List[str]c                 C  sz   g }z0| j dd}|D ]}| }|r|ds|| qW d    W |S 1 s+w   Y  W |S  ty<   Y |S w )Nzutf-8)encoding#)openstrip
startswithappendFileNotFoundError)r	   patternsflinepattern r   @/usr/lib/python3.10/site-packages/mesonbuild/scripts/run_tool.pyparse_pattern_file   s"   
r   namestrsrcdirbuilddirfn,T.Callable[..., subprocess.CompletedProcess]argsT.Anyintc                   s  t  d|  d }|r fdd|D }ntdg \}}|r- fdd| D g}n dg}t  d|  d }t|d	 g}	|	 fd
d|D  ttd ttd }
|
	d dd |
D }
g }d}t
 J}tj| D ](}t|| s|j|
vstfdd|	D rqv||j||g|R   qv|rtdd |D }W d    |S W d    |S 1 sw   Y  |S )N.z-includec                   s   g | ]}  |qS r   )glob.0pr   r   r   
<listcomp>,       zrun_tool.<locals>.<listcomp>zls-filesc                   s   g | ]}t  |qS r   r   )r&   r   r(   r   r   r)   0   r*   z**/*z-ignore*c                   s   g | ]}t  | qS r   )r   r%   r(   r   r   r)   5   s    ccpphc                 S  s   h | ]}d | qS )r#   r   )r&   sr   r   r   	<setcomp>8   r*   zrun_tool.<locals>.<setcomp>r   c                 3  s    | ]	}t   |V  qd S N)fnmatch)r&   i)strfr   r   	<genexpr>?   s    zrun_tool.<locals>.<genexpr>c                 s  s    | ]}|  jV  qd S r1   )result
returncode)r&   xr   r   r   r5   C   s    )r   r   
splitlinesr$   r   extendsetr   unionaddr   	itertoolschainis_dirsuffixanyr   submitmax)r   r   r   r   r    r   globsroignoresuffixesfuturesr7   er   r   )r   r4   r   run_tool(   s@   

	
		rL   )r	   r   r
   r   )r   r   r   r   r   r   r   r   r    r!   r
   r"   )
__future__r   r>   r2   pathlibr   Zconcurrent.futuresr   	compilersr   Zmesonlibr   typingTTYPE_CHECKING
subprocessr   rL   r   r   r   r   <module>   s   
