o
    WodgH                     @  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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 ddlmZmZmZ ddlmZmZmZ ddlmZ ddlmZm Z  ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, ddl
m-Z- ddl.m/Z/m0Z0 ej1rd dl2m3Z3 ddlm4Z4 ddlm5Z5m6Z6 ddlm7Z7 ddlm8Z8 ddl9m:Z: ddl;m<Z<m=Z= G dd de3Z>G dd de:Z?dhZ@e@Ae e@dd h8 Z@G d!d" d"eZBe)d#eCefZDe)deEd$d%ZFG d&d' d'eZGG d(d) d)eZHd/d-d.ZIdS )0    )annotationsN   )ExtensionModule
ModuleInfo   )mesonlib)mlog)UserFeatureOption)known_shmod_kwargs)NotFoundDependency)get_dep_identifier)BasicPythonExternalProgrampython_factory_PythonDependencyBase)ExternalProgramHolderextract_required_kwargpermitted_dependency_kwargs)
primitives)NoneTypePRESERVE_PATH_KW)	noPosargsnoKwargspermittedKwargsContainerTypeInfoInvalidArgumentstyped_pos_argstyped_kwargs	KwargInfo
FeatureNewFeatureNewKwargsdisablerIfNotFound)MachineChoice)ExternalProgramNonExistingExternalProgram)	TypedDict)ModuleState)SharedModuleData)
Dependency)Interpreter)ExtractRequired)TYPE_varTYPE_kwargsc                   @  &   e Zd ZU ded< ded< ded< dS )PyInstallKwT.Optional[bool]purestrsubdirT.Optional[str]install_tagN__name__
__module____qualname____annotations__ r:   r:   xhome/ych/rk3568/buildroot/output/rockchip_rk3568_recovery/host/lib/python3.10/site-packages/mesonbuild/modules/python.pyr.   2      
 r.   c                   @  r-   )FindInstallationKwbooldisablerzT.List[str]modulesr/   r0   Nr5   r:   r:   r:   r;   r=   8   r<   r=   r2   name_prefixname_suffixc                      s*   e Zd Zdd fddZdddZ  ZS )PythonExternalProgramNstateT.Optional['ModuleState']returnr>   c                   s.   t   }|r| |d| _| |d| _|S )Nplatlibpurelib)supersanity	_get_pathrG   rH   )selfrD   ret	__class__r:   r;   rJ   E   s
   
zPythonExternalProgram.sanitykeyr1   Nonec                 C  s   | j d | dd  }|s|S |j| ddd}|r-|jdddr+td| d|S |jddd}|d	krA| j d
 r?dnd}|dkrStj| j d d |}|S |dkrh| j d
 satd| j d | }|S )NZinstall_pathsr   dirpython)moduleinstall_envzpython.z1dir and python.install_env are mutually exclusiveautoZis_venvvenvsystem	variablesprefixzDpython.install_env cannot be set to "venv" unless you are in a venv!Zsysconfig_paths)info
get_optionZis_user_defined_optionr   MesonExceptionospathjoin)rL   rD   rP   rel_pathvaluerU   r:   r:   r;   rK   L   s&   

zPythonExternalProgram._get_pathN)rD   rE   rF   r>   )rD   rE   rP   r1   rF   rQ   )r6   r7   r8   rJ   rK   __classcell__r:   r:   rN   r;   rC   D   s    rC   r0    defaultc                      s`  e Zd ZdDddZeedEddZdFddZeee	dhB e
dddgedGddZedeejfdedeeeedeefdddHd"d#Zeed$eedId&d'ZdJd,d-ZeedKd.d/Zed0eedLd2d3Zed4eegd5edMd8d9Zed:eedLd;d<Zed=eegd5edMd>d?Z eee!d@dAdK fdBdCZ"  Z#S )NPythonInstallationrS   'PythonExternalProgram'interpreter'Interpreter'c                 C  s   t | || |j}| jjjtd}t	|t
sJ d|d | _|d | _|d | _|j| _tj||j| _tj||j| _|d | _|d | _|d | _|d	 | _| j| j| j| j| j| j | j!| j"| j#| j$| j%| j&d
 d S )NrZ   zfor mypyrY   suffixpathsversionplatformis_pypylink_libpython)Zextension_moduleZ
dependencyZinstall_sourcesZget_install_dirZlanguage_versionfoundZhas_pathget_pathZhas_variableZget_variabler_   )'r   __init__r[   rj   environmentcoredatar\   r   Z	OptionKey
isinstancer1   rY   rl   rm   r0   r^   r_   r`   rG   platlib_install_pathrH   purelib_install_pathrn   ro   rp   rq   methodsupdateextension_module_methoddependency_methodinstall_sources_methodget_install_dir_methodlanguage_version_methodZfound_methodhas_path_methodget_path_methodhas_variable_methodget_variable_methodpath_method)rL   rS   rj   r[   rZ   r:   r:   r;   rt   k   s6   






zPythonInstallation.__init__argsT.List['TYPE_var']kwargs'TYPE_kwargs'rF   'SharedModule'c           	      C  s  d|v rd|v rt dn|dd}t|tst d| d||d< t|d}tdd	 |D }|sS| i }|	 sCt
d
|| tdd| jd| j ||d< | jdd\}}|d  |7  < d|d< ||d< d|vr| js~t| jdrd|d< | jd ||S )Ninstall_dirr2   z1"subdir" and "install_dir" are mutually exclusivere   z#"subdir" argument must be a string.Fdependenciesc                 s  s    | ]}t |tV  qd S rc   )rw   r   ).0depr:   r:   r;   	<genexpr>   s    z=PythonInstallation.extension_module_method.<locals>.<genexpr>Python dependency not foundzGpython_installation.extension_module with implicit dependency on pythonz0.63.0z$use python_installation.dependency().r   r   rA   rB   Zgnu_symbol_visibilityz>=3.9Zinlineshidden)r   poprw   r1   _get_install_dir_implr   Zextract_as_listany_dependency_method_implrr   r]   appendr   Z
single_use
subprojectcurrent_noderl   rsplitrp   Zversion_comparern   rj   Zfunc_shared_module)	rL   r   r   r2   Znew_depsZ	has_pydepZpydepsplitrl   r:   r:   r;   r|      s>   



z*PythonInstallation.extension_module_methodr,   r(   c                 C  s   | j |}t|  |}| j jj| |}|d ur|S | }d|d< td| j j	}t
| j j	||| jD ]}| }| rA nq6| j jj| || |S )NFrequiredrS   )rj   Zmachine_from_native_kwargr   Z
_full_pathrv   depsgetcopyr   ru   r   Zheld_objectrr   put)rL   r   Zfor_machine
identifierr   Z
new_kwargsdr:   r:   r;   r      s   z*PythonInstallation._dependency_method_implZembedzpython_installation.dependencyz0.53.0'Dependency'c                 C  sf   t || j\}}}|r!tdtddt|d td| jjS | |}|r1|	 s1t
d|S )Nr(   rS   zskipped: featuredisabledr   )r   r   r   logboldr   rj   ru   r   rr   r   r]   )rL   r   r   r   r   featurer   r:   r:   r;   r}      s   

z$PythonInstallation.dependency_methodinstall_data)varargsz#python_installation.install_sourcesr4   z0.60.0)since,T.Tuple[T.List[T.Union[str, mesonlib.File]]]'PyInstallKw''Data'c              
   C  sh   |d pd}|d d ur|d n| j }| ||d }| jj| j|d |t d |d|j|d dS )	Nr4   zpython-runtimer0   r2   r   rS   preserve_path)renametagZinstall_data_typeZinstall_dir_namer   )r0   r   rj   Zinstall_data_implZsource_strings_to_filesr   ZFileModeoptname)rL   r   r   r   r0   r   r:   r:   r;   r~      s   
z)PythonInstallation.install_sources_methodzpython_installation.install_dirr1   c                 C  s*   |d d ur
|d n| j }| ||d S )Nr0   r2   )r0   r   )rL   r   r   r0   r:   r:   r;   r      s   z)PythonInstallation.get_install_dir_methodr0   r>   r2   P_OBJ.OptionStringc                 C  s:   |r| j }d}n| j}d}ttj||tj||S )Nz{py_purelib}z{py_platlib})ry   rx   P_OBJZOptionStringr^   r_   r`   )rL   r0   r2   basenamer:   r:   r;   r      s    z(PythonInstallation._get_install_dir_implc                 C  s   | j S rc   )rn   rL   r   r   r:   r:   r;   r      s   z*PythonInstallation.language_version_methodzpython_installation.has_pathT.Tuple[str]c                 C     |d | j v S Nr   )rm   r   r:   r:   r;   r         z"PythonInstallation.has_path_methodzpython_installation.get_pathZoptargs$T.Tuple[str, T.Optional['TYPE_var']]
'TYPE_var'c                 C  B   |\}}z| j | W S  ty    |d ur| Y S t| dw )Nz is not a valid path name)rm   KeyErrorr   )rL   r   r   Z	path_namefallbackr:   r:   r;   r         z"PythonInstallation.get_path_methodz python_installation.has_variablec                 C  r   r   )rY   r   r:   r:   r;   r   
  r   z&PythonInstallation.has_variable_methodz python_installation.get_variablec                 C  r   )Nz is not a valid variable name)rY   r   r   )rL   r   r   var_namer   r:   r:   r;   r     r   z&PythonInstallation.get_variable_methodzPython module path methodz0.50.0c                   s   t  ||S rc   )rI   r   r   rN   r:   r;   r     s   zPythonInstallation.path_method)rS   ri   rj   rk   )r   r   r   r   rF   r   )r   r,   rF   r(   )r   r   r   r   rF   r   )r   r   r   r   rF   r   )r   r   r   r   rF   r1   )r0   r>   r2   r1   rF   r   )r   r   r   r   rF   r1   )r   r   r   r   rF   r>   )r   r   r   r   rF   r   )$r6   r7   r8   rt   r   
mod_kwargsr|   r   r    r   r   r   r}   r   r1   r   ZFiler   _PURE_KW
_SUBDIR_KWr   r   r   r~   r   r   r   r   r   objectr   r   r   r   r   rd   r:   r:   rN   r;   rh   j   sT    

%


		rh   c                      s   e Zd ZeddZd( fddZed)ddZd*ddZe	e
degdededeefddededddedeeedg dd ejdd!dd+d&d'Z  ZS ),PythonModulerS   z0.46.0rj   rk   rF   rQ   c                   s(   t  | i | _| jd| ji d S )Nfind_installation)rI   rt   installationsrz   r{   r   )rL   rj   rN   r:   r;   rt   %  s
   
zPythonModule.__init__name_or_pathr1   r3   c                 C  sj   | dvrd S t dsd S ddd|  }d|ddg}t|\}}}| }tj|r3tj|dS d S )N)python2python3pyz-2z-3-cz;import sysconfig; print(sysconfig.get_config_var('BINDIR'))rS   )	shutilwhichr   
Popen_safestripr^   r_   existsr`   )r   vercmd_stdout	directoryr:   r:   r;   _get_win_pythonpath-  s   
z PythonModule._get_win_pythonpathrD   'ModuleState'display_namer   r>   r"   c           	      C  s   |s	t dtj}n/t||}t ||d}| s,t r,| |}|d ur,|}t |}| s8|dv r8t d}| rW||rC|S | d}|rOt	|t
j||jd t S )Nr   )Zext_prog>   r   r   rS   z1 is not a valid python or it is missing distutils)location)rC   r   Zpython_commandr"   Z
from_entryrr   Z
is_windowsr   rJ   r]   r   warningr   r#   )	rL   rD   r   r   r   rS   Z
tmp_pythonZ
pythonpathZ	sanitymsgr:   r:   r;   _find_installation_impl=  s&   



z$PythonModule._find_installation_implzpython.find_installationr   Trf   r?   Fz0.49.0)rg   r   r@   z0.51.0)Zlistifyrg   r   z0.64.0r   T.Tuple[T.Optional[str]]r   'FindInstallationKw'c              
   C  s$  t dd}t||j|\}}}|jtjdpg }|d }	|	p d}
|s*|	d ur*|	g}|r0|d nd }|rJtd|p:ddt	ddt
|d	 t S | j|}|s_| ||
||}|| j|< |d
 }g }g }| r|r|D ]!}t|jdd| g ^}}|jdkr|| qo|| qod|jg}|r|dd| |d | r|s|tddd|jg n|t	d |r|d |d| tj|  | s|rtd|pdt S |r|rtd|pdd|t S t|}|d |_|S )Nz-Passing "feature" option to find_installationz0.48.0rS   r   ZProgramzfound:ZNOz(disabled by:)r@   r   zimport z({})z, ZYES zmodules:z{} not foundz{} is missing modules: {}r0   )r   r   r   ru   Zlookup_binary_entryr!   ZHOSTr   r   Zredr   r#   r   r   r   rr   r   r   command
returncoder   r   formatr`   extendZgreenr]   r   r0   ZMesonBugException)rL   rD   r   r   Zfeature_checkr   r   r   npr   r   r   rS   Zwant_modulesZfound_modulesZmissing_modulesmodpr   msgr:   r:   r;   r   ]  sd   
&



$



zPythonModule.find_installation)rj   rk   rF   rQ   )r   r1   rF   r3   )
rD   r   r   r1   r   r1   r   r>   rF   r"   )rD   r   r   r   r   r   rF   r"   )r6   r7   r8   r   INFOrt   staticmethodr   r   r    r   r1   r   r   r>   r	   r   listr   Zevolver   rd   r:   r:   rN   r;   r   !  s     

 r   rj   rk   rF   c                 C  s   t | }|jtt |S rc   )r   rj   Zappend_holder_maprC   rh   )rj   r   r:   r:   r;   
initialize  s   r   )rj   rk   rF   r   )J
__future__r   r   r^   r   typingTre   r   r   r   r   rv   r	   buildr
   r   r   Zdependencies.detectr   Zdependencies.pythonr   r   r   rj   r   r   r   r   r   Zinterpreter.type_checkingr   r   Zinterpreterbaser   r   r   r   r   r   r   r   r   r   r    r!   Zprogramsr"   r#   TYPE_CHECKINGtyping_extensionsr$   r%   r&   r'   r(   r)   Zinterpreter.kwargsr*   Zinterpreterbase.interpreterbaser+   r,   r.   r=   r   r{   rC   r>   r   r1   r   rh   r   r   r:   r:   r:   r;   <module>   sP   4
" 8 