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 ddlmZ dd	lmZ ejr‰dd
lmZ ddlmZ ddlmZ ddlmZ ejg ef Zejdeejeejf eje geje f Zejdeejeejf geje f Z ejdef Z!G dd„ dƒZ"ddd„Z#dS )é    )ÚannotationsNé   )ÚDependencyExceptionÚDependencyMethods©Úprocess_method_kw)ÚBuiltinDependencyÚSystemDependency)ÚCMakeDependency)ÚExtraFrameworkDependency)ÚPkgConfigDependency)ÚExternalDependency)ÚConfigToolDependencyé   )ÚEnvironment)ÚMachineChoicer   .c                   @  sJ   e Zd ZdZddededdeeedœ
d+dd„Z	e
d,d$d%„ƒZd-d)d*„ZdS ).ÚDependencyFactorya2  Factory to get dependencies from multiple sources.

    This class provides an initializer that takes a set of names and classes
    for various kinds of dependencies. When the initialized object is called
    it returns a list of callables return Dependency objects to try in order.

    :name: The name of the dependency. This will be passed as the name
        parameter of the each dependency unless it is overridden on a per
        type basis.
    :methods: An ordered list of DependencyMethods. This is the order
        dependencies will be returned in unless they are removed by the
        _process_method function
    :*_name: This will overwrite the name passed to the corresponding class.
        For example, if the name is 'zlib', but cmake calls the dependency
        'Z', then using `cmake_name='Z'` will pass the name as 'Z' to cmake.
    :*_class: A *type* or callable that creates a class, and has the
        signature of an ExternalDependency
    :system_class: If you pass DependencyMethods.SYSTEM in methods, you must
        set this argument.
    N)
Úextra_kwargsÚpkgconfig_nameÚpkgconfig_classÚ
cmake_nameÚcmake_classÚconfigtool_classÚframework_nameÚframework_classÚbuiltin_classÚsystem_classÚnameÚstrÚmethodsúT.List[DependencyMethods]r   úT.Optional[T.Dict[str, T.Any]]r   úT.Optional[str]r   ú'T.Type[PkgConfigDependency]'r   r   ú7'T.Union[T.Type[CMakeDependency], CmakeDependencyFunc]'r   ú*'T.Optional[T.Type[ConfigToolDependency]]'r   r   ú"'T.Type[ExtraFrameworkDependency]'r   ú'T.Type[BuiltinDependency]'r   ú'T.Type[SystemDependency]'c       
         C  s¨   t j|v r|stdƒ‚|pi | _|| _t jt |
|	p|¡t jt ||p$|¡t j	t ||p-|¡t j
t ||¡t jt ||¡t jd i| _|d urRt ||¡| jt j< d S d S )Nz%A configtool must have a custom class)r   ÚCONFIG_TOOLr   r   r   ÚEXTRAFRAMEWORKÚ	functoolsÚpartialÚ	PKGCONFIGÚCMAKEÚSYSTEMÚBUILTINÚclasses)Úselfr   r   r   r   r   r   r   r   r   r   r   r   © r3   úD/usr/lib/python3.10/site-packages/mesonbuild/dependencies/factory.pyÚ__init__P   s   
øýÿzDependencyFactory.__init__Úmethodr   Úenvú'Environment'Úfor_machiner   ÚreturnÚboolc                 C  s    | t ju r|j|  ¡ sdS dS )a%  Report whether a method is valid or not.

        If the method is valid, return true, otherwise return false. This is
        used in a list comprehension to filter methods that are not possible.

        By default this only remove EXTRAFRAMEWORK dependencies for non-mac platforms.
        FT)r   r*   ÚmachinesÚ	is_darwin)r6   r7   r9   r3   r3   r4   Ú_process_methodq   s
   

ÿz!DependencyFactory._process_methodÚkwargsúT.Dict[str, T.Any]úT.List['DependencyGenerator']c                   s8   t ˆj|ƒ}ˆj ¡ ‰ˆ |¡ ‡ ‡‡‡fdd„|D ƒS )zBReturn a list of Dependencies with the arguments already attached.c                   s.   g | ]}ˆ  |ˆ ˆ¡rt ˆj| ˆ ˆ¡‘qS r3   )r>   r+   r,   r1   )Ú.0Úm©r7   r9   Znwargsr2   r3   r4   Ú
<listcomp>‡   s    ÿz.DependencyFactory.__call__.<locals>.<listcomp>)r   r   r   ÚcopyÚupdate)r2   r7   r9   r?   r   r3   rD   r4   Ú__call__€   s   

zDependencyFactory.__call__)r   r   r   r    r   r!   r   r"   r   r#   r   r"   r   r$   r   r%   r   r"   r   r&   r   r'   r   r(   )r6   r   r7   r8   r9   r   r:   r;   ©r7   r8   r9   r   r?   r@   r:   rA   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r
   r   r   r	   r5   Ústaticmethodr>   rH   r3   r3   r3   r4   r   9   s     ö!r   r   úT.Set[DependencyMethods]r:   ú1T.Callable[['FactoryFunc'], 'WrappedFactoryFunc']c                   s   d‡ fdd„}|S )	a†  Decorator for handling methods for dependency factory functions.

    This helps to make factory functions self documenting
    >>> @factory_methods([DependencyMethods.PKGCONFIG, DependencyMethods.CMAKE])
    >>> def factory(env: Environment, for_machine: MachineChoice, kwargs: T.Dict[str, T.Any], methods: T.List[DependencyMethods]) -> T.List['DependencyGenerator']:
    >>>     pass
    Úfuncú'FactoryFunc'r:   ú'WrappedFactoryFunc'c                   s   t  ˆ ¡d‡ ‡fd	d
„ƒ}|S )Nr7   r8   r9   r   r?   r@   r:   rA   c                   s   ˆ | ||t ˆ|ƒƒS )Nr   )r7   r9   r?   )rQ   r   r3   r4   Úwrapped–   s   z/factory_methods.<locals>.inner.<locals>.wrappedrI   )r+   Úwraps)rQ   rT   ©r   )rQ   r4   Úinner”   s   zfactory_methods.<locals>.innerN)rQ   rR   r:   rS   r3   )r   rW   r3   rV   r4   Úfactory_methods‹   s   	rX   )r   rO   r:   rP   )$Ú
__future__r   r+   ÚtypingÚTÚbaser   r   r   r   r	   Úcmaker
   Ú	frameworkr   Ú	pkgconfigr   ÚTYPE_CHECKINGr   Ú
configtoolr   Úenvironmentr   Úmesonlibr   ÚCallableÚDependencyGeneratorÚDictr   ÚAnyÚListZFactoryFuncZWrappedFactoryFuncZCmakeDependencyFuncr   rX   r3   r3   r3   r4   Ú<module>   sF   üúÿ
ýûÿR