o
    uJAf7                     @  s   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
mZ dddZddddZdddZedkrJeeejdd  dS dS )    )annotationsN   )ExecutableSerialisationreturnargparse.ArgumentParserc                  C  s.   t jdd} | d | d | d | S )NzECustom executable wrapper for Meson. Do not run on your own, mmm'kay?)descriptionz
--unpicklez	--capturez--feed)argparseArgumentParseradd_argument)parser r   A/usr/lib/python3.10/site-packages/mesonbuild/scripts/meson_exe.pybuildparser   s
   


r   exer   	extra_envT.Optional[T.Dict[str, str]]intc              	   C  s  | j r| j  std| jd | j  | j  | j }n| j}tj	 }|r.|
| | jr7| j|}| jr{tj| jdg |d  |d< | j r{tdd | j  D r{ddlm} || j  d	d
 | jD |ddd | j|d< d }| jrt| jd}tj}| jr| jrJ dd }tj||| jd|||d}| \}}	|d ur|  |j dkrd|d  }
t!|j |
||j dkr| j"rt#d| | jr|j S t$% }| jst#d t#|j&|dd t#d t#|	j&|dd |j S | jrKd}zt| jd}|' |k}W d    n	1 sw   Y  W n
 t(y*   Y nw |sKt| jd}|)| W d    dS 1 sFw   Y  dS )NzBBUG: Can't run cross-compiled exe {!r} with not-found wrapper {!r}r    PATHc                 s  s    | ]}d |v V  qdS )wineNr   ).0ir   r   r   	<genexpr>1   s    zrun_exe.<locals>.<genexpr>r   )mesonlibc                 S  s   g | ]}d | qS )zZ:r   )r   pr   r   r   
<listcomp>5   s    zrun_exe.<locals>.<listcomp>WINEPATH;rbz4Cannot capture and print to console at the same timeF)envcwd	close_fdsstdinstdoutstderrl   5   z.Failed to run due to missing DLLs, with path: zwhile executing z--- stdout ---replace)encodingerrorsz--- stderr ---wb)*exe_wrapperfoundAssertionErrorformatcmd_argsget_pathget_commandosenvironcopyupdater   get_envextra_pathspathsepjoinanyr   r   get_wine_shortpathgetsplitworkdirfeedopen
subprocessPIPEverbosecapturePopencommunicateclose
returncodeFileNotFoundErrorpickledprintlocalegetpreferredencodingdecodereadOSErrorwrite)r   r   r-   	child_envr   r"   piper   r#   r$   strerrorr&   Z
skip_writecuroutputr   r   r   run_exe!   s   


 


rU   argsT.List[str]c                 C  s   t  }|| \}}|r|d dkr|dd  }|js"|s"|d |jrW|s-|js-|jr2|d t|jd}t|}d|_	W d    t|S 1 sNw   Y  t|S t
||j|jd}t|S )	Nr   z--   z:either --unpickle or executable and arguments are requiredz.no other arguments can be used with --unpickler   T)rB   r=   )r   parse_known_argsZunpickleerrorrB   r=   r>   pickleloadrH   r   rU   )rV   r   optionsr-   fr   r   r   r   runh   s$   




r_   __main__rX   )r   r   )N)r   r   r   r   r   r   )rV   rW   r   r   )
__future__r   r0   sysr   r[   r?   typingTrJ   Z
utils.corer   r   rU   r_   __name__exitargvr   r   r   r   <module>   s   

G