o
    §ƒðjý'  ã                   @  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 rœtd d | j ¡ ¡¡ƒ‚|pŸg | _|p¤g | _|p©g | _|p®g | _|	p³g | _|
p»| jd | _|| _ | j rÏtt!dd„ | jƒƒ| _nd	| jvrÚ| j "d	¡ | jrê| j "| j#| j | jƒ¡ |píg 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   ú¦/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/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