o
    uJAfUY                     @  sr  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'm(Z( ddl)m*Z* ddlm+Z+m,Z, ddlm-Z- ddl.m/Z/ G dd de(Z0G dd de(Z1G dd de(Z2G dd de(Z3G dd deZ4d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	TypedDict)Compiler)TYPE_kwargsTYPE_var)ExecutableSerialisation)Interpreterc                   @     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   E/usr/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
subproject
add_devenvadd_dist_scriptadd_install_scriptadd_postconf_scriptbackendZbuild_options
build_rootZcan_run_host_binariesZcurrent_source_dirZcurrent_build_dirget_compilerZget_cross_propertyZget_external_propertyZglobal_build_rootZglobal_source_rootZhas_exe_wrapperZhas_external_property)Zinstall_dependency_manifestis_cross_buildis_subprojectis_unityZoverride_dependencyZoverride_find_programZproject_build_rootZproject_licenseZproject_license_filesproject_nameZproject_source_rootproject_versionsource_rootversion)&super__init__rB   r   r?   methodsupdateadd_devenv_methodadd_dist_script_methodadd_install_script_methodadd_postconf_script_methodbackend_methodbuild_options_methodbuild_root_methodcan_run_host_binaries_methodcurrent_source_dir_methodcurrent_build_dir_methodget_compiler_methodget_cross_property_methodget_external_property_methodglobal_build_root_methodglobal_source_root_methodhas_exe_wrapper_methodhas_external_property_method"install_dependency_manifest_methodis_cross_build_methodis_subproject_methodis_unity_methodoverride_dependency_methodoverride_find_program_methodproject_build_root_methodproject_license_methodproject_license_files_methodproject_name_methodproject_source_root_methodproject_version_methodsource_root_methodversion_method)selfr   r?   	__class__r1   r2   rR   4   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?   find_program_implextendrG   get_executable_serialisation)rt   rw   rx   rz   largsfoundesr1   r1   r2   _find_source_scriptY   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join
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 ExternalProgramr~   r   )r   r6   r   r   r   rel_to_builddirr?   environment
source_dirr   BuildTargetCustomTargetCustomTargetIndexr   get_outputstargetbuild_by_defaultcommandr   r   rB   r   )rt   rw   rz   script_argsnewr1   r   r2   _process_script_argsn   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   rt   rz   r   r   scriptr1   r1   r2   rW      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   postconf_scriptsr   r   r1   r1   r2   rX      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.0r    z)Calling "add_dist_script" in a subproject0.58.0rD   r   )
r   r   r?   rB   r   r   r   r   dist_scriptsr   r   r1   r1   r2   rV      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   rt   rz   r   srcsubr1   r1   r2   r]      
   
z#MesonMain.current_source_dir_methodc                 C  r   r   )r?   r   	build_dirr   r   r   r   r   r1   r1   r2   r^      r   z"MesonMain.current_build_dir_methodc                 C  
   | j jjS N)r?   rG   rw   rt   rz   r   r1   r1   r2   rY         
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   rr         
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   r[      r   zMesonMain.build_root_methodzmeson.project_source_rootc                 C  r   r   )r?   r   r   root_subdirr   r   r   r   r1   r1   r2   rp      
   
z$MesonMain.project_source_root_methodzmeson.project_build_rootc                 C  r   r   )r?   r   r   r   r   r   r   r   r1   r1   r2   rl      r   z#MesonMain.project_build_root_methodzmeson.global_source_rootr   c                 C  r   r   r   r   r1   r1   r2   rc     r   z#MesonMain.global_source_root_methodzmeson.global_build_rootc                 C  r   r   r   r   r1   r1   r2   rb     r   z"MesonMain.global_build_root_methodzmeson.has_exe_wrapperr~   z(use meson.can_run_host_binaries instead.r4   c                 C     |   S r   _can_run_host_binaries_implr   r1   r1   r2   rd        z MesonMain.has_exe_wrapper_methodzmeson.can_run_host_binariesc                 C  r   r   r   r   r1   r1   r2   r\     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   rJ   need_exe_wrapperexe_wrapper)rt   r1   r1   r2   r     s
   
z%MesonMain._can_run_host_binaries_implc                 C  s   | j j S r   )r   r   rJ   r   r1   r1   r2   rg   $  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)rt   rz   r   Zcnamefor_machineclistr1   r1   r2   r_   )  s   
zMesonMain.get_compiler_methodc                 C  s.   | j jjtd}|dkp|dko| j  S )Nunityonsubprojects)r?   r   r   
get_optionr
   rK   )rt   rz   r   optvalr1   r1   r2   ri   4  s   zMesonMain.is_unity_methodc                 C  s
   | j  S r   )r?   rK   r   r1   r1   r2   rh   :  r   zMesonMain.is_subproject_methodz!meson.install_dependency_manifestc                 C  s   |d | j _d S )Nr   )r   dep_manifest_namer   r1   r1   r2   rf   ?  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   absolute_pathr?   r   r   r   r   r   existsr   r   add_find_program_override)rt   rz   r   rw   exeabspathr1   r1   r2   rk   D  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)rt   rz   r   rw   depZoptkeyr   r+   r1   r1   r2   rj   Q  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   get_dep_identifierr   dependency_overridesgetr   get_error_location_stringnodefilenamelinenor   formatDependencyOverrider?   r   )rt   rw   r   r   r+   r   nkwargs
identifierr   overridemr   r1   r1   r2   r   x  s   z#MesonMain._override_dependency_implc                 C     | j j| jj jS r   )r   dep_manifestr?   active_projectnamerP   r   r1   r1   r2   rq     s   z MesonMain.project_version_methodzmeson.project_license()z0.45.0c                 C  r   r   )r   r   r?   r   licenser   r1   r1   r2   rm     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   rn     s   z&MesonMain.project_license_files_methodr   c                 C  s   t | jjjS r   )r   r?   r   rP   r   r1   r1   r2   rs     s   zMesonMain.version_methodc                 C  s   | j jS r   )r?   r   r   r1   r1   r2   ro     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   )rt   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)optargs T.Tuple[str, T.Optional[object]]c                 C  s   |\}}|  ||tjS r   )&_MesonMain__get_external_property_implr	   HOSTrt   rz   r   r  r  r1   r1   r2   r`     s   z#MesonMain.get_cross_property_methodzmeson.get_external_propertyc                 C  s   |\}}|  |||d S )Nr)   )r  r  r1   r1   r2   ra     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	  )rt   rz   r   Z	prop_namer1   r1   r2   re     s   z&MesonMain.has_external_property_methodrC   r   z0.62.0@T.Tuple[T.Union[str, list, dict, mesonlib.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   InvalidArgumentsr   r   r   EnvironmentVariablesdevenvr   )rt   rz   r   envmsg	convertedr1   r1   r2   rU     s   
zMesonMain.add_devenv_methodzmeson.build_optionsc                 C  s   | j j}|d u r
dS t|S r   )r?   user_defined_optionsr   format_cmd_line_options)rt   rz   r   optionsr1   r1   r2   rZ     s   
zMesonMain.build_options_method)r   r>   r?   r@   )rw   r6   rx   ry   rz   r{   r|   r}   )rw   r6   rz   r   r|   r{   )rz   r   r   r   r|   r   )rz   r   r   r   r|   r   )rz   r   r   r   r|   r6   )rz   r   r   r   r|   r4   )r|   r4   )rz   r   r   r   r|   r   )rz   r   r   r   r|   r   )rz   r   r   r   r|   r   )rz   r   r   r   r|   r   )F)rw   r6   r   r   r   r   r+   r*   r   r4   r|   r   )rz   r   r   r   r|   r{   )rz   r   r   r"   r|   r  )rz   r   r   r   r|   r   )r  r6   r  r  r  r	   r|   r  )rz   r  r   r   r|   r  )rz   r  r   r   r|   r  )rz   r   r   r   r|   r4   )rz   r  r   r  r|   r   )Fr-   r.   r/   rR   r   r   r   r6   r   r   r   r   r   r   r   r   r   r   r4   r   rW   r   rX   rV   r   r]   r^   rY   r   rr   r[   r   rp   rl   rc   rb   rd   r\   r   rg   r   r_   ri   rh   rf   rk   r   
Dependencyrj   r   rq   rm   rn   rs   ro   r  r   r  r`   ra   re   r   r   evolvelistdictr  rU   rZ   __classcell__r1   r1   ru   r2   r=   3   s   
%
%

	





	
!
	

r=   )5
__future__r   r   typingr   r   r   r   r   r   r   r	   r
   programsr   r   Zinterpreter.type_checkingr   r   r   r   interpreterbaser   r   r   r   r   r   r   r   r   r   
primitivesr   type_checkingr   r   TYPE_CHECKINGZtyping_extensionsr   r    r   r!   r"   r#   r$   r?   r%   r'   r3   r9   r:   r=   r1   r1   r1   r2   <module>   s0   0