o
    nc"                     @  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 ddl	m
Z
mZmZ ddlmZ ddlmZ dd	lmZ ejrIdd
lmZ ddlmZmZ ee
je
je
jhd ddZG dd deZG dd deZG dd deZG dd deZdS )!    )annotationsN   )detect_cpu_family   )DependencyMethodsdetect_compilerSystemDependency)ConfigToolDependency)factory_methods)PkgConfigDependency)DependencyGenerator)EnvironmentMachineChoiceenv'Environment'for_machine'MachineChoice'kwargsT.Dict[str, T.Any]methodsT.List[DependencyMethods]returnT.List['DependencyGenerator']c              	   C  s  | dd}|dvrg S g }td| ||}|sg S | dv }tj|v rI|sId }|dkr/d}n|dkr6d}n|d	kr<d
}|tjt|| ||d tj	|v r|
 }	|r| j|  rcd|	d< d|	d< |dkrptj ddg}
n|dkr}tj ddg}
n|d	krtj ddg}
t}n0|dkrtj ddg}
n!|dkrtj ddddg}
n|d	krdd dD }
|
g d t}d d |
D }
|
sJ |
|	d!< |tj||
d" | |	|d tj|v r|tjtd#| ||d |S )$Nlanguagec>   r   cppfortranZmpi>   intelintel-clzompi-cr   zompi-cxxr   z	ompi-fortr   -vversion_arg   Zreturncode_valueZI_MPI_CCZmpiiccZ	I_MPI_CXXZmpiicpcZ	I_MPI_F90ZmpiifortZMPICCZmpiccZMPICXXzmpic++ZmpicxxZmpiCCc                 S  s   g | ]}t j|qS  )osenvironget).0er#   r#   zhome/ych/rk3568/buildroot/output/rockchip_rk3568_recovery/host/lib/python3.10/site-packages/mesonbuild/dependencies/mpi.py
<listcomp>U   s    zmpi_factory.<locals>.<listcomp>)ZMPIFCZMPIF90ZMPIF77)ZmpifortZmpif90Zmpif77c                 S  s   g | ]}|r|qS r#   r#   )r'   tr#   r#   r)   r*   Z   s    toolsr   msmpi)r&   r   Zget_idr   	PKGCONFIGappend	functoolspartialr   CONFIG_TOOLcopymachines
is_windowsr$   r%   IntelMPIConfigToolDependencyextendOpenMPIConfigToolDependencySYSTEMMSMPIDependency)r   r   r   r   r   
candidatescompilerZcompiler_is_intelpkg_nameZnwargsZ
tool_namesclsr#   r#   r)   mpi_factory    sf   



r?   c                   @  s*   e Zd ZdddZdddZdddZdS )_MPIConfigToolDependencyargsT.List[str]r   c                 C  s   g }d}| j dkr| jjj| j d }|| 7 }d}|D ]0}|d| s8|dks8|drD|dkrD|dsD|| ||v rCd	}q|rMd}|| q|S )
r
        MPI wrappers return a bunch of garbage args.
        Drop -O2 and everything that is not needed.
        )-Ir   F)z-Dz-f-pthread-W-Wall-WerrorT)r   r   coredata	compilersr   Zget_module_incdir_args
startswithr/   )selfrA   resultZ
multi_argsZfcinclude_nextfr#   r#   r)   _filter_compile_argsj   s.   


z-_MPIConfigToolDependency._filter_compile_argsc                 C  sJ   g }d}|D ]}|  |r|| |dv rd}q|r"d}|| q|S )rC   F>   -L-XlinkerT)_is_link_argr/   )rL   rA   rM   rN   rO   r#   r#   r)   _filter_link_args   s   


z*_MPIConfigToolDependency._filter_link_argsrO   strboolc                 C  sX   | j jdkr|dkp|dp|dS |dp+|dkp+|do+|dko+|d	 S )
Nr   z/linkz/LIBPATHz.lib)rQ   -lrR   rE   rF   rG   rH   )Zclib_compileridrK   endswith)rL   rO   r#   r#   r)   rS      s   
z%_MPIConfigToolDependency._is_link_argN)rA   rB   r   rB   )rO   rU   r   rV   )__name__
__module____qualname__rP   rT   rS   r#   r#   r#   r)   r@   h   s    

r@   c                      4   e Zd ZdZdZ	dd fddZdddZ  ZS )r6   z*Wrapper around Intel's mpiicc and friends.r    NnamerU   r   r   r   r   r   T.Optional[str]c                   sH   t  j||||d | jsd S | dgd}| || _| || _d S )Nr   z-showzlink and compile argssuper__init__is_foundZget_config_valuerP   compile_argsrT   	link_args)rL   r^   r   r   r   rA   	__class__r#   r)   rb      s   z%IntelMPIConfigToolDependency.__init__outr   c                 C  s,   t d|}|rd|d|dS |S )Nz(\d{4}) Update (\d)z{}.{}r   r   )researchformatgrouprL   rh   vr#   r#   r)   _sanitize_version   s   z.IntelMPIConfigToolDependency._sanitize_versionNr^   rU   r   r   r   r   r   r_   rh   rU   r   rU   rZ   r[   r\   __doc__r!   rb   ro   __classcell__r#   r#   rf   r)   r6      s    
r6   c                      r]   )r8   z)Wrapper around OpenMPI mpicc and friends.z--showme:versionNr^   rU   r   r   r   r   r   r_   c                   sV   t  j||||d | jsd S | dgd}| || _| dgd}| || _d S )Nr   z--showme:compilerd   z--showme:linkre   r`   )rL   r^   r   r   r   Zc_argsZl_argsrf   r#   r)   rb      s   z$OpenMPIConfigToolDependency.__init__rh   r   c                 C  s   t d|}|r|dS |S )Nz\d+.\d+.\d+r   )ri   rj   rl   rm   r#   r#   r)   ro      s   
z-OpenMPIConfigToolDependency._sanitize_versionrp   rq   rr   rs   r#   r#   rf   r)   r8      s    r8   c                      s&   e Zd ZdZ	dd fddZ  ZS )r:   zThe Microsoft MPI.Nr^   rU   r   r   r   r   r   r_   c           	        s  t  j||||d |dvrd| _d S | jj| j  sd S tj	d}t
| jjjj}d }|dkr;tj	d}d}n|dkrGtj	d}d	}|d u sO|d u rTd| _d S d
| _dtj|d g| _d| dtj|| g| _| jdkr| jdtj|d  d S d S )Nr   >   r   Nr   FZ	MSMPI_INCx86ZMSMPI_LIB32x86_64ZMSMPI_LIB64x64TrW   r-   rD   r   Zmsmpifec)ra   rb   rc   r   r4   r   r5   r$   r%   r&   r   rI   rJ   hostpathjoinre   rd   r   r/   )	rL   r^   r   r   r   incdirarchlibdirpostrf   r#   r)   rb      s0   
zMSMPIDependency.__init__rp   rq   )rZ   r[   r\   rt   rb   ru   r#   r#   rf   r)   r:      s    r:   )
r   r   r   r   r   r   r   r   r   r   )
__future__r   r0   typingTr$   ri   environmentr   baser   r   r   Z
configtoolr	   factoryr
   Z	pkgconfigr   TYPE_CHECKINGr   r   r   r.   r2   r9   r?   r@   r6   r8   r:   r#   r#   r#   r)   <module>   s&   G4