o
    uJAf%-                     @  s  d dl m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
mZ ddlmZmZmZ ddlmZ ejrcd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mZ ddlmZ G dd dZ G dd deZ!G dd de!Z"ej#G dd dZ$G dd de!Z%G dd de%Z&G dd de%Z'd0d"d#Z(G d$d% d%Z)G d&d' d'ej*Z+G d(d) d)ej*Z,G d*d+ d+ej*Z-G d,d- d-ej*Z.G d.d/ d/ej*Z/dS )1    )annotationsN   )buildmesonlib)IncludeDirs)noKwargs	noPosargs)relpathHoldableObjectMachineChoice)ExternalProgram)Interpreter)ProgramVersionFunc)MachineHolder)TYPE_varTYPE_kwargs)OverrideProgram)WrapMode)
Dependencyc                   @  s   e Zd ZdZdEddZdFdGddZddddejfdHdd Z		dIdJd%d&Z			dKdLd)d*Z
			dMdNd2d3Zd4ejddfdOd:d;Zd4ejddfdPd<d=ZdQdAdBZdRdCdDZdS )SModuleStatezObject passed to all module methods.

    This is a WIP API provided to modules, it should be extended to have everything
    needed so modules does not touch any other part of Meson internal APIs.
    interpreter'Interpreter'returnNonec                 C  s  || _ |j | _t|j |j | _|j| _|j| _|j	| _	|j
| _
|j| _|jj| _|jj|j j| _|j| _|jj| _|jj| _|j | _|j | _|jjj| _|jjj|ji | _td|jd j | _!td|jd j | _"td|jd j | _#|j$| _$d S )Nr   build_machinehost_machinetarget_machine)%_interpreterenvironmentget_source_dirsource_rootr	   get_build_dirbuild_to_src
subprojectsubdirroot_subdircurrent_linenor   project_namedep_manifestactive_projectnameversionproject_versionbackendtargetsdataget_headersheadersget_manmanglobal_argshostprojects_argsgetZproject_argsTcastbuiltinheld_objectr   r   r   current_nodeselfr    r>   @/usr/lib/python3.10/site-packages/mesonbuild/modules/__init__.py__init__+   s.   



zModuleState.__init__-Iinclude_dirs+T.Iterable[T.Union[str, build.IncludeDirs]]prefixstrT.List[str]c                   s   |sg S | j  }| j  }g }|D ]/}t|tr#|  | g7 }q| fdd|||D  | fdd| D  q|S )Nc                      g | ]}  | qS r>   r>   .0irD   r>   r?   
<listcomp>S       z0ModuleState.get_include_args.<locals>.<listcomp>c                   rG   r>   r>   rH   rK   r>   r?   rL   T   rM   )r   r   r!   
isinstancerE   extendto_string_listget_extra_build_dirs)r=   rB   rD   srcdirbuilddirZdirs_strdirsr>   rK   r?   get_include_argsG   s   


 zModuleState.get_include_argsTNFprog=T.Union[mesonlib.FileOrString, T.List[mesonlib.FileOrString]]requiredboolversion_funcT.Optional[ProgramVersionFunc]wantedT.Optional[str]silentfor_machiner   ;T.Union[ExternalProgram, build.Executable, OverrideProgram]c                 C  s(   t |ts|g}| jj||||||dS )N)rX   rZ   r\   r^   r_   )rN   listr   find_program_impl)r=   rV   rX   rZ   r\   r^   r_   r>   r>   r?   find_programX   s
   
zModuleState.find_programnamedepnamevarname?T.Union['build.Executable', ExternalProgram, 'OverrideProgram']c                 C  s   | j |gg }|d ur|S | jtj|}|d ur t||S | j|dd|d}|	 rU|j
dkrU|j|d}	|	rUt|	}|	 sSd|d|d|	d	}
t|
|S | j|||d
S )NTF)nativerX   r\   	pkgconfig)ri   zDependency z tool variable z contains erroneous value: zM

This is a distributor issue -- please report it to your {depname} provider.)rX   r\   )r   program_from_overridesr   lookup_binary_entryr   HOSTr   
from_entry
dependencyfound	type_nameget_variabler   MesonExceptionrc   )r=   rd   re   rf   rX   r\   progobjZ	prog_listdepvaluemsgr>   r>   r?   	find_toolb   s    
zModuleState.find_toolrh   'Dependency'c                 C  s*   ||d}|r||d< | j | j|g|S )N)rh   rX   r*   )r   func_dependencyr;   )r=   re   rh   rX   r\   kwargsr>   r>   r?   rn   }   s   
zModuleState.dependencyargsTT.Tuple[str, T.Union[build.Executable, build.Jar, 'ExternalProgram', mesonlib.File]]workdirenv+T.Union[T.List[str], T.Dict[str, str], str]depends6T.List[T.Union[build.CustomTarget, build.BuildTarget]]c                 C  s*   |||d}t |}| j| j|| d S )N)r}   r~   r   )ra   r   	func_testr;   )r=   r{   r}   r~   r   rz   Z	real_argsr>   r>   r?   test   s   zModuleState.test r#   machinelangmodule0T.Union[T.List[str], str, int, bool, 'WrapMode']c              	   C  s   | j jt|||||S N)r   coredata
get_optionr   	OptionKey)r=   rd   r#   r   r   r   r>   r>   r?   r      s   zModuleState.get_optionc                 C  s    t |||||}|| jjjv S r   )r   r   r   user_defined_optionscmd_line_options)r=   rd   r#   r   r   r   keyr>   r>   r?   is_user_defined_option   s   z"ModuleState.is_user_defined_optionrT   %T.Iterable[T.Union[str, IncludeDirs]]T.Iterable[IncludeDirs]c                 c  s2    |D ]}t |tr|V  q| j|gV  qdS )zConvert raw include directory arguments to only IncludeDirs

        :param dirs: An iterable of strings and IncludeDirs
        :return: None
        :yield: IncludeDirs objects
        N)rN   r   r   build_incdir_object)r=   rT   dr>   r>   r?   process_include_dirs   s   
z ModuleState.process_include_dirsc                 C  s   | j |gd| d S NT)r   add_languages)r=   r   r_   r>   r>   r?   add_language   s   zModuleState.add_languager   r   r   r   )rA   )rB   rC   rD   rE   r   rF   )rV   rW   rX   rY   rZ   r[   r\   r]   r^   rY   r_   r   r   r`   )TN)rd   rE   re   rE   rf   rE   rX   rY   r\   r]   r   rg   )FTN)
re   rE   rh   rY   rX   rY   r\   r]   r   rx   )NNN)
r{   r|   r}   r]   r~   r   r   r   r   r   )rd   rE   r#   rE   r   r   r   r]   r   r]   r   r   )rd   rE   r#   rE   r   r   r   r]   r   r]   r   rY   )rT   r   r   r   )r   rE   r_   r   r   r   )__name__
__module____qualname____doc__r@   rU   r   rl   rc   rw   rn   r   r   r   r   r   r>   r>   r>   r?   r   $   s>    


r   c                   @  s   e Zd ZdZdddZdS )ModuleObjectz3Base class for all objects returned by modules
    r   r   c                 C  s
   i | _ d S r   )methodsr=   r>   r>   r?   r@      s   zModuleObject.__init__Nr   r   )r   r   r   r   r@   r>   r>   r>   r?   r      s    r   c                   @     e Zd ZdS )MutableModuleObjectNr   r   r   r>   r>   r>   r?   r          r   c                   @  sJ   e Zd ZU dZded< dZded< dZded< dZd	ed
< dZded< dS )
ModuleInfozMetadata about a Module.rE   rd   Nr]   added
deprecatedFrY   unstable
stabilized)	r   r   r   r   __annotations__r   r   r   r   r>   r>   r>   r?   r      s   
 r   c                      sV   e Zd ZU dZded< d fddZeedddZe	dddZ
dddZ  ZS )NewExtensionModule=Class for modern modules

    provides the found method.
    r   INFOr   r   c                   s    t    | jd| ji d S )Nro   )superr@   r   updatefound_methodr   	__class__r>   r?   r@      s   

zNewExtensionModule.__init__state'ModuleState'r{   T.List['TYPE_var']rz   'TYPE_kwargs'rY   c                 C  s   |   S r   )ro   )r=   r   r{   rz   r>   r>   r?   r      s   zNewExtensionModule.found_methodc                   C     dS r   r>   r>   r>   r>   r?   ro         zNewExtensionModule.foundbbuild.Buildc                 C  s   d S r   r>   )r=   r   r>   r>   r?   postconf_hook   s   z NewExtensionModule.postconf_hookr   )r   r   r{   r   rz   r   r   rY   r   rY   )r   r   r   r   )r   r   r   r   r   r@   r   r   r   staticmethodro   r   __classcell__r>   r>   r   r?   r      s   
 r   c                      s   e Zd Zd fddZ  ZS )ExtensionModuler   r   r   r   c                   s   t    || _d S r   )r   r@   r   r<   r   r>   r?   r@      s   

zExtensionModule.__init__r   )r   r   r   r@   r   r>   r>   r   r?   r      s    r   c                      s0   e Zd ZdZd fddZedd	d
Z  ZS )NotFoundExtensionModuler   rd   rE   r   r   c                   s   t    t|| _d S r   )r   r@   r   r   )r=   rd   r   r>   r?   r@      s   
z NotFoundExtensionModule.__init__rY   c                   C  r   )NFr>   r>   r>   r>   r?   ro      r   zNotFoundExtensionModule.found)rd   rE   r   r   r   )r   r   r   r   r@   r   ro   r   r>   r>   r   r?   r      s
    r   fnamemesonlib.FileOrStringr   rY   c                 C  s   |  dd }|dv S )z
    Check if the file is a library-like file generated by a module-specific
    target, such as GirTarget or TypelibTarget
    .>   ZgirZtypelib)split)r   suffixr>   r>   r?   is_module_library   s   r   c                   @  s   e Zd Zd
ddZd	S )ModuleReturnValuereturn_valueT.Optional['TYPE_var']new_objectsCT.Sequence[T.Union['TYPE_var', 'mesonlib.ExecutableSerialisation']]r   r   c                 C  s   || _ t|ts
J || _d S r   )r   rN   ra   r   )r=   r   r   r>   r>   r?   r@   	  s   
zModuleReturnValue.__init__N)r   r   r   r   r   r   )r   r   r   r@   r>   r>   r>   r?   r     s    r   c                   @  r   )GResourceTargetNr   r>   r>   r>   r?   r     r   r   c                   @  r   )GResourceHeaderTargetNr   r>   r>   r>   r?   r     r   r   c                   @  r   )	GirTargetNr   r>   r>   r>   r?   r     r   r   c                   @  r   )TypelibTargetNr   r>   r>   r>   r?   r     r   r   c                   @  r   )
VapiTargetNr   r>   r>   r>   r?   r     r   r   )r   r   r   rY   )0
__future__r   dataclassestypingr7   r   r   r   r   interpreterbase.decoratorsr   r   r	   r
   r   programsr   TYPE_CHECKINGr   r   Zinterpreter.interpreterr   Zinterpreter.interpreterobjectsr   interpreterbaser   r   r   wrapr   dependenciesr   r   r   r   	dataclassr   r   r   r   r   r   CustomTargetr   r   r   r   r   r>   r>   r>   r?   <module>   s@    

	