o
    WodDG                     @  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mZ d dlZ	ddl
mZmZ ddlmZmZmZmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ e	jrd dl m!Z! ddlm"Z" ddlm#Z# ddlm$Z$ G dd de!Z%eZ&n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e*Z+G dd dee*Z,G dd dee*Z-	d.d/d*d+Z.ed,ej/ej0ej1ge(d-Z2dS )0    )annotationsN)Path   )mesonlibmlog   )process_method_kwDependencyMethodsDependencyTypeNameExternalDependencySystemDependency)ConfigToolDependency)DependencyFactory)ExtraFrameworkDependency)PkgConfigDependency)detect_cpu_family)ExternalProgram)	TypedDict)DependencyGenerator)Environment)MachineChoicec                   @  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	ed
< d	ed< ded< d	ed< dS )PythonIntrospectionDictzT.Dict[str, str]install_pathsboolis_pypyis_venvlink_libpythonsysconfig_pathspathsstrplatformsuffix	variablesversionN)__name__
__module____qualname____annotations__ r(   r(   }home/ych/rk3568/buildroot/output/rockchip_rk3568_recovery/host/lib/python3.10/site-packages/mesonbuild/dependencies/python.pyr   $   s   
 r   c                      s(   e Zd ZdgZdZd fd	d
Z  ZS )Pybind11ConfigToolDependencyzpybind11-configz--pkgconfigdirnamer   environmentr   kwargsT.Dict[str, T.Any]c                   s.   t  ||| | jsd S | dgd| _d S )Nz
--includescompile_args)super__init__is_foundZget_config_valuer/   )selfr+   r,   r-   	__class__r(   r)   r1   >   s   z%Pybind11ConfigToolDependency.__init__)r+   r   r,   r   r-   r.   )r$   r%   r&   toolsZskip_versionr1   __classcell__r(   r(   r4   r)   r*   6   s    r*   c                      s8   e Zd Z		dd fdd	ZdddZdddZ  ZS )BasicPythonExternalProgramNr+   r   commandT.Optional[T.List[str]]ext_progT.Optional[ExternalProgram]c                   s^   |d u rt  j||dd n|| _|j| _|j| _d | _i dddi i ddi dd
| _d| _d S )NT)r9   ZsilentFsentinelz0.0)
r   r   r   r   r   r   r    r!   r"   r#   )r0   r1   r+   r9   pathZcached_versioninfoZpure)r3   r+   r9   r;   r4   r(   r)   r1   F   s$   
z#BasicPythonExternalProgram.__init__r#   returnr   c                 C  s0   | j dkrt|dS | j dkrt|dS dS )NZpython2z< 3.0python3>= 3.0T)r+   r   version_compare)r3   r#   r(   r(   r)   _check_versionb   s
   

z)BasicPythonExternalProgram._check_versionc                 C  s   dd l }|jdd}|  t|g }t|\}}}W d    n1 s'w   Y  zt|}W n- tj	y`   d }t
dt|j|jf  t
d t
| t
d t
| Y nw |d uru| |d rutd|| _d	S d
S )Nr   zmesonbuild.scriptszpython_info.pyz.Could not introspect Python (%s): exit code %dzProgram stdout:
zProgram stderr:
r#   r   TF)importlib.resources	resourcesr>   Zget_commandr   r   Z
Popen_safejsonloadsJSONDecodeErrorr   debugargs
returncoderD   Tcastr?   )r3   	importlibfcmdpstdoutstderrr?   r(   r(   r)   sanityi   s&   


z!BasicPythonExternalProgram.sanity)NN)r+   r   r9   r:   r;   r<   )r#   r   r@   r   )r@   r   )r$   r%   r&   r1   rD   rU   r7   r(   r(   r4   r)   r8   E   s    
r8   c                   @  s   e Zd ZdddZdS )	_PythonDependencyBasepython_holder'BasicPythonExternalProgram'embedr   c                 C  sz   || _ |jd | _|jd | _|jd | _|jd | _|jd | _|jd p'|| _d | _t	| jdr8d| _
d S d	| _
d S )
Nr#   r    r"   r   r   r   rB      r   )rY   r?   r#   r    r"   r   r   r   r   rC   major_version)r3   rW   rY   r(   r(   r)   r1      s   	

z_PythonDependencyBase.__init__N)rW   rX   rY   r   r$   r%   r&   r1   r(   r(   r(   r)   rV          rV   c                   @  s   e Zd Z	ddddZdS )PythonPkgConfigDependencyFr+   r   r,   'Environment'r-   r.   installationrX   libpcr   c                 C  s   |rt d|d n	t d|d t| ||| t| ||dd |r7| js7t d| j d | jsFt	
| jdrHg | _d S d S d S )	NzSearching for z via pkgconfig lookup in LIBPCz/ via fallback pkgconfig lookup in default pathsrY   Fz"python-zT" could not be found in LIBPC, this is likely due to a relocated python installationz< 3.8)r   rJ   r   r1   rV   getr2   r#   r   r   rC   	link_args)r3   r+   r,   r-   r`   ra   r(   r(   r)   r1      s   

z"PythonPkgConfigDependency.__init__N)F)
r+   r   r,   r_   r-   r.   r`   rX   ra   r   r\   r(   r(   r(   r)   r^      s    r^   c                   @  s   e Zd Zdd	d
ZdS )PythonFrameworkDependencyr+   r   r,   r_   r-   r.   r`   rX   c                 C  s*   t | ||| t| ||dd d S )NrY   F)r   r1   rV   rb   )r3   r+   r,   r-   r`   r(   r(   r)   r1      s   z"PythonFrameworkDependency.__init__Nr+   r   r,   r_   r-   r.   r`   rX   r\   r(   r(   r(   r)   rd      r]   rd   c                   @  sL   e Zd Zdd	d
ZdddZdddZdddZdddZed ddZ	dS )!PythonSystemDependencyr+   r   r,   r_   r-   r.   r`   rX   c                 C  s   t | ||| t| ||dd | jr&t r | | n	| | nd| _	t
| jd| jd| jdg}|  jdd |D 7  _t rc|  d	rct| jd
rc|  jdg7  _| jjdd|| jdssd| _	d S d S )NrY   FT	INCLUDEPYincludeplatincludec                 S  s   g | ]}|rd | qS )z-Ir(   ).0r>   r(   r(   r)   
<listcomp>   s    z3PythonSystemDependency.__init__.<locals>.<listcomp>Z64z<3.12z-DMS_WIN64=zPython.h )
extra_args)r   r1   rV   rb   r   r   Z
is_windowsfind_libpy_windows
find_libpyr2   
OrderedSetr"   r   r/   get_windows_python_archendswithrC   r#   clib_compiler
has_header)r3   r+   r,   r-   r`   Z	inc_pathsr(   r(   r)   r1      s$   


$
zPythonSystemDependency.__init__r@   Nonec                 C  s   | j r| jdkrd}nd}tj| jdd}|g}n d| j }d| jv r.|| jd 7 }d| jv r:|| jd 7 }g }| j	|||}|d urP|| _
d	| _d S d S )
NrZ   zpypy3-czpypy-cbasebinpythonZ	DEBUG_EXTABIFLAGST)r   r[   osr>   joinr"   rb   r#   rs   Zfind_libraryrc   r2   )r3   r,   libnamelibdirlibdirslargsr(   r(   r)   ro      s"   



z!PythonSystemDependency.find_libpyT.Optional[str]c                 C  s   | j dkr$| jd}|drdS |drdS td|d d S | j dkr+dS | j d	v r2dS | j d
v r9dS td| j  d S )NmingwCCx86_64)i686i386x86z#MinGW Python built with unknown CC z, please file a bugwin32>   Zwin64z	win-amd64>   z	win-arm64aarch64z Unknown Windows Python platform )r    r"   rb   
startswithr   log)r3   Zpyccr(   r(   r)   rq      s    





z.PythonSystemDependency.get_windows_python_archr:   c                 C  s  | j dr| jd}| jd}| jdd}| jr'tdd| d }n|  }|jd	krS|d
kr=|dkr=td}np|d
krJtd| d}nctd| d}nZtdd| d }| jj	
td}t|tsnJ | jj	
td}|p}|dk}d}	td| jj	jv r| jj	jtd j}
|
dv rd}	|r|	r| jdsttd t| jd| }n%| j dkr| jr| jd}n| jd}t| jd| }ntd| stdt| d S t|gS ) Nwinpy_version_nodotpy_version_shortZimplementation_lowerrx   Zlibs	libpythonz.aZgccpypyz3.8zlibpypy3-c.dllZlibpypyz-c.dllz.dllz.lib	buildtyperJ   FZb_vscrt>   Zstatic_from_buildtypeZmddZmtdZfrom_buildtypeTPy_DEBUGau                              Using a debug build type with MSVC or an MSVC-compatible compiler
                            when the Python interpreter is not also a debug build will almost
                            certainly result in a failed build. Prefer using a release build
                            type or a debug Python interpreter.
                            base_prefixr   LIBRARY	LDLIBRARYLIBDIRzDOn a Windows path, but the OS doesn't appear to be Windows or MinGW.z#Could not find Python3 library {!r})r    r   r"   rb   staticr   Zget_compileridenvcoredataZ
get_optionr   Z	OptionKey
isinstancer   optionsvaluer   warningtextwrapdedentZMesonBugExceptionexistsr   format)r3   ZvernumZverdotZ	imp_lowerlibpathcompr   rJ   Zis_debug_buildZvscrt_debugZvscrtlibr|   r(   r(   r)   get_windows_link_args  sL   



z,PythonSystemDependency.get_windows_link_argsr   c                 C  s   |   }|du rd| _dS t|jjj}||kr.tdt| j	d| d|  d| _dS | 
 }|du r;d| _dS || _d| _dS )z{
        Find python3 libraries on Windows and also verify that the arch matches
        what we are building for.
        NFZNeedzfor z, but found T)rq   r2   r   r   	compilershostr   r   Zboldr+   r   rc   )r3   r   Zpyarcharchr   r(   r(   r)   rn   <  s   "
z)PythonSystemDependency.find_libpy_windowsc                   C  s   dS )N	sysconfigr(   r(   r(   r(   r)   	log_triedR  s   z PythonSystemDependency.log_triedNre   )r,   r_   r@   ru   )r@   r   )r@   r:   )r   r_   r@   ru   )r@   r   )
r$   r%   r&   r1   ro   rq   r   rn   staticmethodr   r(   r(   r(   r)   rf      s    




:rf   r   r_   for_machine'MachineChoice'r-   r.   r`   (T.Optional['BasicPythonExternalProgram']r@   T.List['DependencyGenerator']c              	     sn  t tjtjh|}|dd}g }|d u}|d u r#tdtj}|  |j	d dp/|j	d }tj|v r|ry|j	d d |rLt
|j	d drLd	nd
}	d| |	 }
d fdd}|t||
| ||  d urx|tt|
| || n|ttd| | tj|v r|ttd| || tj|v r| }t
|drdg|d< |ttd| || |S )NrY   FrA   r"   	LDVERSIONr#   LIBPCz>=3.8z-embedrl   zpython-r+   r   r   r_   r-   r.   r`   rX   r@   'ExternalDependency'c              	     s    st td|i }d|_|S tjdd }tjdd } tjd< zt| |||dW ddd}|d| |d| S ddd}|d| |d| w )N	pkgconfigrx   ZPKG_CONFIG_LIBDIRZPKG_CONFIG_PATHTr+   r   r   r@   ru   c                 S  s0   |d ur|t j| < d S | t jv rt j| = d S d S N)rz   environ)r+   r   r(   r(   r)   set_envz  s
   
z?python_factory.<locals>.wrap_in_pythons_pc_dir.<locals>.set_env)r+   r   r   r   r@   ru   )r   r
   r+   rz   r   popr^   )r+   r   r-   r`   emptyZold_pkg_libdirZold_pkg_pathr   Z
pkg_libdirr(   r)   wrap_in_pythons_pc_dirl  s   




z.python_factory.<locals>.wrap_in_pythons_pc_dirrx   z>= 3z/Library/Frameworksr   Python)
r+   r   r   r_   r-   r.   r`   rX   r@   r   )r   r	   	PKGCONFIGZSYSTEMrb   r8   r   Zpython_commandrU   r?   rC   append	functoolspartialr^   r   rf   ZEXTRAFRAMEWORKcopyrd   )r   r   r-   r`   methodsrY   
candidatesZfrom_installationZpkg_versionZ	pkg_embedpkg_namer   nkwargsr(   r   r)   python_factoryV  s6   



r   Zpybind11)Zconfigtool_classr   )
r   r_   r   r   r-   r.   r`   r   r@   r   )3
__future__r   r   rG   rz   r   pathlibr   typingrM   rl   r   r   rv   r   r	   r
   r   r   Z
configtoolr   factoryr   Z	frameworkr   r   r   r,   r   Zprogramsr   TYPE_CHECKINGtyping_extensionsr   r   r   r   r   Z_Baseobjectr*   r8   rV   r^   rd   rf   r   r   ZCONFIG_TOOLZCMAKEZpybind11_factoryr(   r(   r(   r)   <module>   sD    >  A
