o
    nc,                     @  s   d dl mZ d dl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mZmZmZmZ ddlmZmZ ejrwd dlmZ dd	lmZ dd
lmZ ddlmZ ejeeje eje f Z ejeejedf eej!ejeef  f Z"G dd dZ#dS )    )annotationsN)Thread   )mlog)
PerMachine
Popen_safeversion_compare
is_windows	OptionKey)find_external_programNonExistingExternalProgram)Path)Environment)MachineChoice)ExternalProgram.c                   @  s   e Zd ZeddZeddZi Zd=d>ddZd=d?ddZd@ddZ	dAdBddZ
dCd#d$ZdDd&d'ZdDd(d)ZdDd*d+ZdDd,d-ZdEdFd/d0ZdGd1d2ZdHd3d4ZdHd5d6ZdId7d8ZdId9d:ZdJd;d<ZdS )KCMakeExecutorNFenvironment'Environment'versionstrfor_machiner   silentboolc              
   C  s   || _ || _|| _| j| j|d\| _| _d| _d| _g | _g | _	| jd u r(d S t
| j| j sMtdt| j dt| jdt| j d d | _d S | jjjtd| jd	 j| _| jro|  j	d
d| jg7  _	d S d S )N)r   TFzThe version of CMakeiszbut versionzis requiredZcmake_prefix_path)machinez-DCMAKE_PREFIX_PATH={};)min_versionr   r   find_cmake_binarycmakebin	cmakeversalways_capture_stderrprint_cmoutprefix_pathsextra_cmake_argsr   r   warningboldget_pathZcoredataoptionsr
   valueformatjoin)selfr   r   r   r    r,   xhome/ych/rk3568/buildroot/output/rockchip_rk3568_recovery/host/lib/python3.10/site-packages/mesonbuild/cmake/executor.py__init__.   s,   
"zCMakeExecutor.__init__return7T.Tuple[T.Optional['ExternalProgram'], T.Optional[str]]c                 C  s0  t tj| j trtd| j d dS tj| j d ur(td| j d ndtj| j d u s2J td| j d t|| jdd|jdd	D ])}| 	|}|sRqH|sdt
d
t| d| d |tj| j< |tj| j<  n|s}t
d
td t tj| j< d tj| j< dS tj| j tj| j fS )NzCMake binary for z is cached as not foundNNz is cached.z is not cachedZcmakeZCMakeF)Zallow_default_for_crosszFound CMake:()ZNO)
isinstancer   class_cmakebinr   r   r   debugr   Zdefault_cmakecheck_cmakelogr%   r&   class_cmakeversZred)r+   r   r   Zpotential_cmakebinZversion_if_okr,   r,   r-   r   G   s6   



zCMakeExecutor.find_cmake_binaryr   'ExternalProgram'T.Optional[str]c              
   C  s  |  std|j d S z&| }t|dg dd \}}|jdkr4tdd	| W d S W n2 t
yJ   tdd	| Y d S  tyg   dd	|}t s_|d	7 }t| Y d S w td
|}|d urw|dS td|d d S )NzDid not find CMake z	--versionr   r   z$Found CMake {!r} but couldn't run it z?We thought we found CMake {!r} but now it's not there. How odd!z7Found CMake {!r} but didn't have permissions to run it.zO

On Unix-like systems this is often caused by scripts that are not executable.z#(cmake|cmake3)\s*version\s*([\d.]+)zWe thought we found CMake z?, but it was missing the expected version string in its output.)foundr   r8   nameget_commandr   
returncoder$   r)   r*   FileNotFoundErrorPermissionErrorr	   researchgroup)r+   r   cmdpoutmsgZcmversr,   r,   r-   r7   j   s:   


zCMakeExecutor.check_cmaker!   T.Optional[bool]r    Nonec                 C  s$   |d ur|| _ |d ur|| _d S d S N)r!   r    )r+   r!   r    r,   r,   r-   set_exec_mode   s
   
zCMakeExecutor.set_exec_modeargsT.List[str]	build_dirr   envT.Optional[T.Dict[str, str]]TYPE_cache_keyc                 C  s8   |d ur
t | nt  }t|}| j || |fS rL   )	frozensetitemstupler   r&   as_posix)r+   rN   rP   rQ   ZfenvZtargsr,   r,   r-   
_cache_key   s   zCMakeExecutor._cache_keyTYPE_resultc                   s  | j  | }tj|tjtjt||d d fdd}t|d}|  zGd}t	d}d	}		  j
 }
|
s8n&|
jdd}||rN||7 }|d }	n|	rU||7 }nt|d q0W  j
  |     n j
  |     w  jd |fS )NstdoutstderrcwdrQ   r/   rK   c                    s:   	  j  } | s	nt| jddd q j   d S )NTignoreerrors
)r[   readliner   r8   decodestripclose)lineprocr,   r-   print_stdout   s   
z6CMakeExecutor._call_cmout_stderr.<locals>.print_stdout)target z/^\s*(.*\.(cmake|txt))\(([0-9]+)\):\s*(\w+)\(.*$FTr^   r_   z )
ra   )r/   rK   )r   r?   SPopenPIPEr   r   startrC   compiler\   rb   rc   matchendswithr   r$   rd   re   r*   waitr@   )r+   rN   rP   rQ   rF   ri   tZ	raw_traceZtline_start_regZinside_multiline_traceZline_rawrf   r,   rg   r-   _call_cmout_stderr   s:   








z CMakeExecutor._call_cmout_stderrc                 C  st   | j  | }tj|tjtjt||d}	 |j }|snt	
|jddd q|j  |  |jd d fS )NrZ   Tr^   r_   ra   )r   r?   rl   rm   rn   STDOUTr   r[   rb   r   r8   rc   rd   re   rs   r@   )r+   rN   rP   rQ   rF   rh   rf   r,   r,   r-   _call_cmout   s   

zCMakeExecutor._call_cmoutc           	   	   C  sh   |j ddd | j | }tj||t|dtjtjdd}|j}|jj	dd}|j
j	dd}|||fS )NT)parentsexist_okF)rQ   r]   	close_fdsr[   r\   universal_newlinesr^   r_   )mkdirr   r?   rl   runr   rn   r@   r[   rc   r\   )	r+   rN   rP   rQ   rF   retrcrH   errr,   r,   r-   _call_quiet   s   

zCMakeExecutor._call_quietc                 C  sp   t d| j  d| d |D ]}t d| d q| js'| |||S | jr1| |||S | |||S )NzCalling CMake (z) in z with:z  - "")	r   r6   r   r?   r!   r   r    ru   rw   )r+   rN   rP   rQ   ir,   r,   r-   
_call_impl   s   zCMakeExecutor._call_impldisable_cachec                 C  sd   |d u r	t j }|| j }|r| |||S tj}| |||}||vr.| |||||< || S rL   )osenvironcopyr#   r   r   class_cmake_cacherX   )r+   rN   rP   rQ   r   cachekeyr,   r,   r-   call   s   

zCMakeExecutor.callc                 C  s
   | j d uS rL   )r   r+   r,   r,   r-   r=         
zCMakeExecutor.foundc                 C     | j S rL   )r   r   r,   r,   r-   r         zCMakeExecutor.versionc                 C  
   | j  S rL   )r   r&   r   r,   r,   r-   executable_path   r   zCMakeExecutor.executable_pathc                 C  r   rL   )r   r?   r   r,   r,   r-   r?      r   zCMakeExecutor.get_commandc                 C  r   rL   )r"   r   r,   r,   r-   get_cmake_prefix_paths   r   z$CMakeExecutor.get_cmake_prefix_pathsc                 C  r   rL   )r   r   r,   r,   r-   machine_choice   r   zCMakeExecutor.machine_choice)F)r   r   r   r   r   r   r   r   )r   r   r   r   r/   r0   )r   r:   r/   r;   r1   )r!   rJ   r    rJ   r/   rK   )rN   rO   rP   r   rQ   rR   r/   rS   )rN   rO   rP   r   rQ   rR   r/   rY   )NF)
rN   rO   rP   r   rQ   rR   r   r   r/   rY   )r/   r   )r/   r   )r/   rO   )r/   r   )__name__
__module____qualname__r   r5   r9   r   r.   r   r7   rM   rX   ru   rw   r   r   r   r=   r   r   r?   r   r   r,   r,   r,   r-   r   '   s(    


#


+







r   )$
__future__r   
subprocessrl   	threadingr   typingTrC   r   rk   r   Zmesonlibr   r   r   r	   r
   Zprogramsr   r   TYPE_CHECKINGpathlibr   r   r   r   r   TupleintOptionalr   rY   	FrozenSetrS   r   r,   r,   r,   r-   <module>   s"   ,