o
    jg'                     @  s   d dl mZ d dlmZmZ 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mZmZ G dd dZG d	d
 d
eZdd ZG dd deZG dd deZdS )    )annotations)CallableOptional)OrderedDictN   )find_binary_of_commandunique_listCompileErrorc                   @  s|   e Zd ZU dZded< ded< dZded< ded< d	ed
< ded< ded< 			dddZedddZdd Z	dd Z
dS )CompilerRunnera   CompilerRunner base class.

    Parameters
    ==========

    sources : list of str
        Paths to sources.
    out : str
    flags : iterable of str
        Compiler flags.
    run_linker : bool
    compiler_name_exe : (str, str) tuple
        Tuple of compiler name &  command to call.
    cwd : str
        Path of root of relative paths.
    include_dirs : list of str
        Include directories.
    libraries : list of str
        Libraries to link against.
    library_dirs : list of str
        Paths to search for shared libraries.
    std : str
        Standard string, e.g. ``'c++11'``, ``'c99'``, ``'f2003'``.
    define: iterable of strings
        macros to define
    undef : iterable of strings
        macros to undefine
    preferred_vendor : string
        name of preferred vendor e.g. 'gnu' or 'intel'

    Methods
    =======

    run():
        Invoke compilation as a subprocess.

    strenviron_key_compilerenviron_key_flagsLDFLAGSenviron_key_ldflagszdict[str, str]compiler_dictztuple[None | str, ...]	standardsz)dict[str, Callable[[Optional[str]], str]]std_formatercompiler_name_vendor_mappingNT.c                 K  s  t |tr	tdt|| _|| _|pg | _tj	| j
r*|  jtj| j
  7  _|| _|r6|\| _| _nftj	| jrttj| j | _| j D ]\}}|| jv rZ|| _|| _ nqIt| j d \| _| _td| j| jf  n(|d u rtj	dd }| |\| _| _| _| jd u rtdd| j |pg | _|pg | _|pg | _|pg | _|	pg | _|
p| jd | _|| _ | j rtt!dd | j| _nd	| jvr| j"d	 | jr| j"| j#| j | j |pg d
d t$tj%tj	| j&d D  | _'|d urbt()d}t()d}|du r5t*t$|j+|r#t,dt*t$|j+|r.d S |"d d S |du rYt*t$|j+|rEd S t*t$|j+|rRt,d|"d d S d}t||d S )Nz2Expected argument sources to be a list of strings.r   z<failed to determine what kind of compiler %s is, assuming %sSYMPY_COMPILER_VENDORz No compiler found (searched: {})z, c                 S  s   | dkS )N-c xr   r   \/var/www/html/zoom/venv/lib/python3.10/site-packages/sympy/utilities/_compilation/runners.py<lambda>o   s    z)CompilerRunner.__init__.<locals>.<lambda>r   c                 S  s   g | ]}|d kr|qS ) r   ).0lfr   r   r   
<listcomp>x   s    z+CompilerRunner.__init__.<locals>.<listcomp>r   zno-strict-aliasing$zstrict-aliasing$Tz4Strict aliasing cannot be both enforced and disabledz-fstrict-aliasingFz-fno-strict-aliasingz:Expected argument strict_aliasing to be True/False, got {})-
isinstancer   
ValueErrorlistsourcesoutflagsosenvirongetr   splitcwdcompiler_namecompiler_binaryr   r   itemscompiler_vendorwarningswarnfind_compilerformatjoinvaluesdefineundefinclude_dirs	librarieslibrary_dirsr   std
run_linkerfilterappendr   mapstripr   linklinerecompileanymatchr	   )selfr#   r$   r%   r;   compilerr*   r7   r8   r9   r:   r5   r6   strict_aliasingpreferred_vendorr@   kwargskvnsa_resa_remsgr   r   r   __init__G   s   

















zCompilerRunner.__init__c                   s^   t  j }|r||v r|g| }ntd|t fdd|D \}}|| j| fS )z/ Identify a suitable C/fortran/other compiler. zUnknown vendor {}c                   s   g | ]} j | qS r   )r   r   r   clsr   r   r      s    z0CompilerRunner.find_compiler.<locals>.<listcomp>)r"   r   keysr!   r2   r   r   )rR   rH   
candidatesnamepathr   rQ   r   r1      s   zCompilerRunner.find_compilerc                 C  s   | j g| j dd | jD  dd | jD  dd | jD  | j }| jr:|dd | jD dd | jD  | j	 7 }g }t
dd|D ]}t|d	u r`||vr`|| d
|}t|qE|S )zD List of arguments (str) to be passed to e.g. ``subprocess.Popen``. c                 S     g | ]}d | qS )z-Ur   rP   r   r   r   r          z&CompilerRunner.cmd.<locals>.<listcomp>c                 S  rW   )z-Dr   rP   r   r   r   r      rX   c                 S  rW   )z-Ir   rP   r   r   r   r      rX   c                 S  rW   )z-Lr   rP   r   r   r   r      rX   c                 S  rW   )z-lr   rP   r   r   r   r      rX   z\$\{(\w+)\} Nz$Environment variable '{}' undefined.)r,   r%   r6   r5   r7   r#   r;   r9   r8   r@   rA   findallr3   r&   getenvr=   r2   r	   )rE   cmdcountedenvvarrN   r   r   r   r\      s6   

zCompilerRunner.cmdc              	   C  s   t | j| _| jd| jg tj }| j|d< tj	d
|  d| jtjtjtj|d}| }z
|d d| _W n tyM   |d d| _Y nw |j| _| jdkrmd	d
|  | jt| j| j}t|| j| jfS )
Nz-oPWDrY   T)shellr*   stdinstdoutstderrenvr   zutf-8z
iso-8859-1z3Error executing '{}' in {} (exited status {}):
 {}
)r   r%   extendr$   r&   r'   copyr*   
subprocessPopenr3   r\   PIPESTDOUTcommunicatedecode
cmd_outerrUnicodeDecodeError
returncodecmd_returncoder2   r   r	   )rE   rd   pcommrN   r   r   r   run   s2   


zCompilerRunner.run)NTNr   NNNNNNNNN)N)__name__
__module____qualname____doc____annotations__r   rO   classmethodr1   r\   rs   r   r   r   r   r
      s"   
 &
Kr
   c                   @  B   e Zd ZdZdZeg dZdZdjdjdjdZ	ddd	dZ
d
S )CCompilerRunnerCCCFLAGS))gnugcc)intelicc)llvmclang)c89c90c99c11-std={})r   r   r   r~   r   r   Nrt   ru   rv   r   r   r   r   r   r2   r   r   r   r   r   r   r{      s    
r{   c                   s.   ddi v r fdd}|S dd }|S )Ng++)zWimplicit-interfacec                   s      D ]	}|| v r dS qdS )NFTr   )r   nw
cmplr_namenot_welcomer   r   fltr   s
   z_mk_flag_filter.<locals>.fltrc                 S  s   dS )NTr   r   r   r   r   r      s   r   )r   r   r   r   r   _mk_flag_filter   s   r   c                   @  rz   )CppCompilerRunnerCXXCXXFLAGS))r~   r   )r   icpc)r   clang++)zc++98zc++0xr   )r   r   r   r~   r   r   Nr   r   r   r   r   r      s    
r   c                   @  s@   e Zd ZdZdZdZdd dd dZedd	gZd
ddZ	dS )FortranCompilerRunnerFCFFLAGS)Nf77f95f2003f2008c                 C  s"   | d u rdS | dkrdS d | S )Nz-std=gnur   z-std=legacyr   r2   r   r   r   r   r   !  s   " zFortranCompilerRunner.<lambda>c                 C  s   | d u rdS d | dd  S )Nz
-stand f08z
-stand f{}r   r   r   r   r   r   "  s    )gfortranifort)r~   r   )r   r   r~   r   N)
rt   ru   rv   r   r   r   r   r   r   r   r   r   r   r   r     s    
r   )
__future__r   typingr   r   collectionsr   r&   rA   rg   r/   utilr   r   r	   r
   r{   r   r   r   r   r   r   r   <module>   s     H