o
    lduY                     @  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	m
Z
 ddlmZmZ dd	lmZmZ dd
lmZmZ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 ddl m!Z! ddl"m#Z#m$Z$ ej%rd dl&m'Z' ddl(m)Z) ddl*m+Z+ ddlm,Z,m-Z- ddl.m/Z/ d dl&m0Z0 G dd de0Z1G dd de0Z2G dd de0Z3G dd de0Z4G dd deZ5dS )    )annotationsN   )mesonlib)dependencies)build)mlogcoredata)MachineChoice	OptionKey)OverrideProgramExternalProgram)ENV_KWENV_METHOD_KWENV_SEPARATOR_KWenv_convertor_with_method)
MesonInterpreterObject
FeatureNewFeatureDeprecatedtyped_pos_argsnoArgsFlattening	noPosargsnoKwargstyped_kwargs	KwargInfoInterpreterException   )MesonVersionString)	NATIVE_KWNoneType)Literal)ExecutableSerialisation)Compiler)TYPE_kwargsTYPE_var)Interpreter)	TypedDictc                   @     e Zd ZU ded< ded< dS )FuncOverrideDependencymesonlib.MachineChoicenativeT.Optional[bool]staticN__name__
__module____qualname____annotations__ r1   r1   home/ych/rk3568/buildroot/output/rockchip_rk3568_recovery/host/lib/python3.10/site-packages/mesonbuild/interpreter/mesonmain.pyr'       s   
 r'   c                   @  s&   e Zd ZU ded< ded< ded< dS )AddInstallScriptKWboolskip_if_destdirstrinstall_tagdry_runNr,   r1   r1   r1   r2   r3   %   s   
 r3   c                   @  s   e Zd ZU ded< dS )NativeKWr(   r)   Nr,   r1   r1   r1   r2   r9   +   s   
 r9   c                   @  r&   )AddDevenvKWz#Literal['set', 'prepend', 'append']methodr6   	separatorNr,   r1   r1   r1   r2   r:   /   s   
 r:   c                      sX  e Zd Zd fddZdddZdddZedeej	e
jefeej	e
je
je
jefdedededddedeefddededdddd#d$Zed%eej	efeej	efdedd(d)Zed*eej	efeej	efdedd+d,Zeedd.d/Zeedd0d1Zeedd2d3Zeeed4d5d6dd7d8Zeeed9d5d:dd;d<Zeeed=d5dd>d?Z eeed@d5ddAdBZ!eeedCdDddEdFZ"eeedGdDddHdIZ#eeedJdKdLddNdOZ$eeedPdKddQdRZ%ddSdTZ&eeddUdVZ'edWeedWe(dd[d\Z)eedd]d^Z*eedd_d`Z+edaeeddbdcZ,edddeeddeej	ee
jfeddgdhZ-edie(edjeefddediee.j/edidkddndoZ0	dddtduZ1eeddvdwZ2edxdyeeddzd{Z3ed|deedddZ4eedddZ5eedddZ6dddZ7e8eddDdedee9gdedddZ:e8eddkedee9gdede(dddZ;eddDedeede(dddZ<eddDede=e>j?ddedee@eAe
jBfdddZCeeedddddZD  ZES )	MesonMainr   'build.Build'interpreter'Interpreter'c                   s   t  j|jd || _|| _| ji d| jd| jd| j	d| j
d| jd| jd| jd	| jd
| jd| jd| jd| jd| jd| jd| jd| jd| j| j| j| j| j| j| j| j| j| j | j!| j"| j#| j$| j%d d S )N
subprojectZget_compileris_cross_buildZhas_exe_wrapperZcan_run_host_binariesZis_unityis_subprojectZcurrent_source_dirZcurrent_build_dirZsource_rootZ
build_rootZproject_source_rootZproject_build_rootZglobal_source_rootZglobal_build_rootadd_install_scriptadd_postconf_scriptadd_dist_script)Zinstall_dependency_manifestZoverride_dependencyZoverride_find_programZproject_versionZproject_licenseZproject_license_filesversionproject_nameZget_cross_propertyZget_external_propertyZhas_external_propertybackend
add_devenvZbuild_options)&super__init__rB   r   r?   methodsupdateget_compiler_methodis_cross_build_methodhas_exe_wrapper_methodcan_run_host_binaries_methodis_unity_methodis_subproject_methodcurrent_source_dir_methodcurrent_build_dir_methodsource_root_methodbuild_root_methodproject_source_root_methodproject_build_root_methodglobal_source_root_methodglobal_build_root_methodadd_install_script_methodadd_postconf_script_methodadd_dist_script_method"install_dependency_manifest_methodoverride_dependency_methodoverride_find_program_methodproject_version_methodproject_license_methodproject_license_files_methodversion_methodproject_name_methodget_cross_property_methodget_external_property_methodhas_external_property_methodbackend_methodadd_devenv_methodbuild_options_method)selfr   r?   	__class__r1   r2   rM   5   sf   	
zMesonMain.__init__namer6   prog>T.Union[str, mesonlib.File, build.Executable, ExternalProgram]argsT.List[str]return'ExecutableSerialisation'c                 C  s   g }t |tjtfrtjd| d| j| jd || n t |t	j
r2tjd| d| j| jd | j|g}|| || | jjj|dd}| jj|_|S )Nz?Passing executable/found program object to script parameter of 0.55.0locationz+Passing file object to script parameter of 0.57.0T)verbose)
isinstancer   
Executabler   r   
single_userB   current_nodeappendr   Filer?   Zfind_program_implextendrJ   Zget_executable_serialisation)ro   rr   rs   ru   Zlargsfoundesr1   r1   r2   _find_source_scriptZ   s    




zMesonMain._find_source_scriptxT.Sequence[T.Union[str, mesonlib.File, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, ExternalProgram]]c                   s   g }d}|D ]S t  tr|  qt  tjr'd}| | jjj qt  t	j
t	jt	jfrQd}| fdd  D  t  t	jrMd j_qd _q| j d}q|rltjd| dd| jj| jd |S )	NFTc                   s   g | ]}t j  |qS r1   )ospathjoinZ
get_subdir).0oar1   r2   
<listcomp>   s    z2MesonMain._process_script_args.<locals>.<listcomp>z	Calling "zP" with File, CustomTarget, Index of CustomTarget, Executable, or ExternalProgramry   rz   )r~   r6   r   r   r   Zrel_to_builddirr?   environment
source_dirr   BuildTargetCustomTargetCustomTargetIndexr   get_outputstargetZbuild_by_defaultcommandr   r   rB   r   )ro   rr   ru   script_argsnewr1   r   r2   _process_script_argso   s,   


zMesonMain._process_script_argszmeson.add_install_script)varargsr5   Fr|   )defaultsincer7   z0.60.0)r   r8   z1.1.0T.Tuple[T.Union[str, mesonlib.File, build.Executable, ExternalProgram], T.List[T.Union[str, mesonlib.File, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, ExternalProgram]]]kwargs'AddInstallScriptKW'Nonec                 C  sR   |  d|d }| d|d |}|d |_|d |_|d |_| jj| d S )NrE   r   r   r5   r7   r8   )r   r   r5   tagr8   r   install_scriptsr   ro   ru   r   r   scriptr1   r1   r2   r^      s   


z#MesonMain.add_install_script_methodzmeson.add_postconf_scriptkT.Tuple[T.Union[str, mesonlib.File, ExternalProgram], T.List[T.Union[str, mesonlib.File, ExternalProgram]]]'TYPE_kwargs'c                 C  s4   |  d|d }| d|d |}| jj| d S )NrF   r   r   )r   r   r   Zpostconf_scriptsr   r   r1   r1   r2   r_      s   z$MesonMain.add_postconf_script_methodzmeson.add_dist_scriptc                 C  sx   |d rt jdd| jj| jd | jjdkr"t jdd| jj| jd | d|d }| d|d	 |}| jj	| d S )
Nr   z1Calling "add_dist_script" with multiple argumentsz0.49.0rz    z)Calling "add_dist_script" in a subproject0.58.0rG   r   )
r   r   r?   rB   r   r   r   r   Zdist_scriptsr   r   r1   r1   r2   r`      s   z MesonMain.add_dist_script_methodT.List['TYPE_var']c                 C  ,   | j jj}| j j}|dkr|S tj||S Nr   )r?   r   r   subdirr   r   r   ro   ru   r   srcsubr1   r1   r2   rV      
   
z#MesonMain.current_source_dir_methodc                 C  r   r   )r?   r   	build_dirr   r   r   r   r   r1   r1   r2   rW      r   z"MesonMain.current_build_dir_methodc                 C  
   | j jjS N)r?   rJ   rr   ro   ru   r   r1   r1   r2   rl         
zMesonMain.backend_methodzmeson.source_rootz0.56.0zFuse meson.project_source_root() or meson.global_source_root() instead.c                 C  r   r   r?   r   r   r   r1   r1   r2   rX         
zMesonMain.source_root_methodzmeson.build_rootzDuse meson.project_build_root() or meson.global_build_root() instead.c                 C  r   r   r?   r   r   r   r1   r1   r2   rY      r   zMesonMain.build_root_methodzmeson.project_source_rootc                 C  r   r   )r?   r   r   root_subdirr   r   r   r   r1   r1   r2   rZ      
   
z$MesonMain.project_source_root_methodzmeson.project_build_rootc                 C  r   r   )r?   r   r   r   r   r   r   r   r1   r1   r2   r[      r   z#MesonMain.project_build_root_methodzmeson.global_source_rootr   c                 C  r   r   r   r   r1   r1   r2   r\     r   z#MesonMain.global_source_root_methodzmeson.global_build_rootc                 C  r   r   r   r   r1   r1   r2   r]     r   z"MesonMain.global_build_root_methodzmeson.has_exe_wrapperry   z(use meson.can_run_host_binaries instead.r4   c                 C     |   S r   _can_run_host_binaries_implr   r1   r1   r2   rR        z MesonMain.has_exe_wrapper_methodzmeson.can_run_host_binariesc                 C  r   r   r   r   r1   r1   r2   rS     r   z&MesonMain.can_run_host_binaries_methodc                 C  s(   | j j o| j j o| j jjd u  S r   )r   r   rC   Zneed_exe_wrapperZexe_wrapper)ro   r1   r1   r2   r     s
   
z%MesonMain._can_run_host_binaries_implc                 C  s   | j j S r   )r   r   rC   r   r1   r1   r2   rQ   %  s   zMesonMain.is_cross_build_methodzmeson.get_compilerT.Tuple[str]
'NativeKW'
'Compiler'c              	   C  sR   |d }|d }| j jj| }z|| W S  ty(   td| d|  dw )Nr   r)   z'Tried to access compiler for language "z", not specified for z	 machine.)r?   r   	compilersKeyErrorr   get_lower_case_name)ro   ru   r   Zcnamefor_machineZclistr1   r1   r2   rP   *  s   
zMesonMain.get_compiler_methodc                 C  s.   | j jjtd}|dkp|dko| j  S )NZunityonZsubprojects)r?   r   r   
get_optionr
   rD   )ro   ru   r   optvalr1   r1   r2   rT   5  s   zMesonMain.is_unity_methodc                 C  s
   | j  S r   )r?   rD   r   r1   r1   r2   rU   ;  r   zMesonMain.is_subproject_methodz!meson.install_dependency_manifestc                 C  s   |d | j _d S )Nr   )r   Zdep_manifest_namer   r1   r1   r2   ra   @  s   z,MesonMain.install_dependency_manifest_methodzmeson.override_find_programz0.46.0GT.Tuple[str, T.Union[mesonlib.File, ExternalProgram, build.Executable]]c                 C  sf   |\}}t |tjr*|| jjj| jjj}tj	
|s$td| dt||g}| j|| d S )NzTried to override z! with a file that does not exist.)r~   r   r   Zabsolute_pathr?   r   r   r   r   r   existsr   r   Zadd_find_program_override)ro   ru   r   rr   exeabspathr1   r1   r2   rc   E  s   z&MesonMain.override_find_program_methodzmeson.override_dependencyr+   z0.54.0%T.Tuple[str, dependencies.Dependency]'FuncOverrideDependency'c                 C  s   |\}}|s
t dtd| jjd}| jj|}t|ts"J d|d }|d u re| j|||d d |dkrB| j|||dd d S |dkrQ| j|||d	d d S | j|||dd | j|||d	d d S | j|||d dd
 | j||||d d S )Nz3First argument must be a string and cannot be emptydefault_libraryrA   zfor mypyr+   )r+   TsharedF)r+   
permissive)	r   r
   r?   rB   r   r   r~   r6   _override_dependency_impl)ro   ru   r   rr   depZoptkeyr   r+   r1   r1   r2   rb   R  s"   	z$MesonMain.override_dependency_methodr   dependencies.Dependencyr*   r   c                 C  s   t d| }|d u r|d= n||d< t||}|d }| jj| |}	|	rA|r-d S d}
t	|	j
j|	j
j}t|
||t|| jj| jj| |< d S )NzT.Dict[str, T.Any]r+   r)   zUTried to override dependency {!r} which has already been resolved or overridden at {})Tcastcopyr   Zget_dep_identifierr   Zdependency_overridesgetr   Zget_error_location_stringnodefilenamelinenor   formatZDependencyOverrider?   r   )ro   rr   r   r   r+   r   nkwargs
identifierr   overridemr{   r1   r1   r2   r   y  s   z#MesonMain._override_dependency_implc                 C     | j j| jj jS r   )r   dep_manifestr?   active_projectnamerH   r   r1   r1   r2   rd     s   z MesonMain.project_version_methodzmeson.project_license()z0.45.0c                 C  r   r   )r   r   r?   r   licenser   r1   r1   r2   re     s   z MesonMain.project_license_methodzmeson.project_license_files()T.List[TYPE_var]r"   T.List[mesonlib.File]c                 C  s   dd | j j| jj jD S )Nc                 S  s   g | ]}|d  qS )r   r1   )r   lr1   r1   r2   r     s    z:MesonMain.project_license_files_method.<locals>.<listcomp>)r   r   r?   r   license_filesr   r1   r1   r2   rf     s   z&MesonMain.project_license_files_methodr   c                 C  s   t | jjjS r   )r   r?   r   rH   r   r1   r1   r2   rg     s   zMesonMain.version_methodc                 C  s   | j jS r   )r?   r   r   r1   r1   r2   rh     s   zMesonMain.project_name_methodpropnamefallbackT.Optional[object]machiner	   objectc                 C  sL   z
| j jj| | W S  ty%   |dur| Y S td|  d| w )zGShared implementation for get_cross_property and get_external_property.NzUnknown property for z
 machine: )r?   r   
propertiesr   r   r   )ro   r   r   r   r1   r1   r2   Z__get_external_property_impl  s   z&MesonMain.__get_external_property_implzmeson.get_cross_propertyz)Use meson.get_external_property() instead)Zoptargs T.Tuple[str, T.Optional[object]]c                 C  s   |\}}|  ||tjS r   )&_MesonMain__get_external_property_implr	   ZHOSTro   ru   r   r   r   r1   r1   r2   ri     s   z#MesonMain.get_cross_property_methodzmeson.get_external_propertyc                 C  s   |\}}|  |||d S )Nr)   )r   r   r1   r1   r2   rj     s   z&MesonMain.get_external_property_methodzmeson.has_external_propertyc                 C  s   |d }|| j jj|d  v S )Nr   r)   )r?   r   r   )ro   ru   r   Z	prop_namer1   r1   r2   rk     s   z&MesonMain.has_external_property_methodrK   r   z0.62.0=T.Tuple[T.Union[str, list, dict, build.EnvironmentVariables]]'AddDevenvKW'c                 C  s\   |d }t |}|rtd| t||d |d }t|tjs%J | jj| d S )Nr   z"add_devenv": r;   r<   )	r   	validatorr   ZInvalidArgumentsr   r~   EnvironmentVariablesZdevenvr   )ro   ru   r   envmsgZ	convertedr1   r1   r2   rm     s   
zMesonMain.add_devenv_methodzmeson.build_optionsc                 C  s   | j j}|d u r
dS t|S r   )r?   Zuser_defined_optionsr   Zformat_cmd_line_options)ro   ru   r   optionsr1   r1   r2   rn     s   
zMesonMain.build_options_method)r   r>   r?   r@   )rr   r6   rs   rt   ru   rv   rw   rx   )rr   r6   ru   r   rw   rv   )ru   r   r   r   rw   r   )ru   r   r   r   rw   r   )ru   r   r   r   rw   r6   )ru   r   r   r   rw   r4   )rw   r4   )ru   r   r   r   rw   r   )ru   r   r   r   rw   r   )ru   r   r   r   rw   r   )ru   r   r   r   rw   r   )F)rr   r6   r   r   r   r   r+   r*   r   r4   rw   r   )ru   r   r   r   rw   rv   )ru   r   r   r"   rw   r   )ru   r   r   r   rw   r   )r   r6   r   r   r   r	   rw   r   )ru   r   r   r   rw   r   )ru   r   r   r   rw   r   )ru   r   r   r   rw   r4   )ru   r   r   r   rw   r   )Fr-   r.   r/   rM   r   r   r   r6   r   r   r   r   r   r   r   r   r   r   r4   r   r^   r   r_   r`   r   rV   rW   rl   r   rX   rY   r   rZ   r[   r\   r]   rR   rS   r   rQ   r   rP   rT   rU   ra   rc   r   Z
Dependencyrb   r   rd   re   rf   rg   rh   r   r   r   ri   rj   rk   r   r   Zevolvelistdictr   rm   rn   __classcell__r1   r1   rp   r2   r=   4   s   
%
%

	





	
!
	

r=   )6
__future__r   r   typingr   r   r   r   r   r   r   r	   r
   Zprogramsr   r   Zinterpreter.type_checkingr   r   r   r   Zinterpreterbaser   r   r   r   r   r   r   r   r   r   Z
primitivesr   Ztype_checkingr   r   TYPE_CHECKINGtyping_extensionsr   Zbackend.backendsr    r   r!   r"   r#   r?   r$   r%   r'   r3   r9   r:   r=   r1   r1   r1   r2   <module>   s2   0