
    \h'                        S SK Jr  S SKJrJr  S SKJr  S SKrS SKrS SK	r	S SK
r
SSKJrJrJr   " S S5      r " S	 S
\5      rS r " S S\5      r " S S\5      rg)    )annotations)CallableOptional)OrderedDictN   )find_binary_of_commandunique_listCompileErrorc                      \ rS rSr% SrS\S'   S\S'   SrS\S'   S\S	'   S
\S'   S\S'   S\S'      SS jr\SS j5       r	S r
S rSrg)CompilerRunner   a  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_mappingNc                T
   [        U[        5      (       a  [        S5      e[        U5      U l        X l        U=(       d    / U l        [        R                  R                  U R                  5      (       a>  U =R                  [        R                  U R                     R                  5       -  sl        X`l        U(       a  Uu  U l        U l        GO[        R                  R                  U R                  5      (       a  [        R                  U R                     U l        U R                   R#                  5        H&  u  nnUU R                  ;   d  M  UU l        UU l          O   [        U R                   R#                  5       5      S   u  U l        U l        [&        R(                  " SU R                  < SU R                  < 35        OUc   [        R                  R                  SS 5      nU R+                  U5      u  U l        U l        U l        U R                  cA  [        SR-                  SR/                  U R                   R1                  5       5      5      5      eU=(       d    / U l        U=(       d    / U l        U=(       d    / U l        U=(       d    / U l        U	=(       d    / U l        U
=(       d    U R<                  S   U l        X@l         U R@                  (       a&  [        [C        S U R                  5      5      U l        O+S	U R                  ;  a  U R                  RE                  S	5        U R>                  (       aB  U R                  RE                  U RF                  U R                     " U R>                  5      5        U=(       d    / [I        [        RJ                  [        R                  R                  U RL                  S
5      R                  5       5       Vs/ s H  nUS
:w  d  M  UPM     sn-   U l'        UGb  [P        RR                  " S5      n[P        RR                  " S5      nUSL af  [U        [I        URV                  U5      5      (       a  [Y        S5      e[U        [I        URV                  U5      5      (       a  g URE                  S5        g USL af  [U        [I        URV                  U5      5      (       a  g [U        [I        URV                  U5      5      (       a  [Y        S5      eURE                  S5        g Sn[        UR-                  U5      5      eg s  snf )Nz2Expected argument sources to be a list of strings.r   z*failed to determine what kind of compiler z is, assuming SYMPY_COMPILER_VENDORz No compiler found (searched: {})z, c                    U S:g  $ )N-c xs    \/var/www/auris/envauris/lib/python3.13/site-packages/sympy/utilities/_compilation/runners.py<lambda>)CompilerRunner.__init__.<locals>.<lambda>o   s    qDy    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-   r:   r;   r<   r=   r8   r9   strict_aliasingpreferred_vendorrC   kwargskvlfnsa_resa_remsgs                          r   __init__CompilerRunner.__init__G   s    gs##QRRG}[b
::>>$0011JJ"**T%;%;<BBDDJ7?4D 4ZZ^^D5566#%::d.G.G#HD **0021,,,+,D()*D&	 3 <@@R@R@X@X@Z;[\];^8$d&8#33T5G5GI J  '#%::>>2I4#P MQM_M_`pMqJD 4d6J##+ !C!J!J499UYUgUgUnUnUpKq!rssl[b
(.B"b(.B+$..+$??f%8$**EFDJ4::%

!!$'88JJd//""$$(HH. / "RIIrzz~~d&>&>CIIK:
 , :
22X -/ :
 ,  &ZZ 56FJJ12E$&s6<</00&']^^U[[%011LL!45 E)s6<</003u{{E233*+abb%;<R O!<==) '	,s   $
T%2T%c                "   [        U R                  R                  5       5      nU(       a&  X;   a  U/U-   nO[        SR	                  U5      5      e[        U Vs/ s H  o0R                  U   PM     sn5      u  pEXEU R                  U   4$ s  snf )z.Identify a suitable C/fortran/other compiler. zUnknown vendor {})r%   r   keysr$   r5   r   r   )clsrK   
candidatesr   namepaths         r   r4   CompilerRunner.find_compiler   s     #++0023
-./
:
 !4!;!;<L!MNN+:,V:a->->q-A:,VW
3;;DAAA -Ws   Bc                   U R                   /U R                  -   U R                   Vs/ s H  nSU-   PM
     sn-   U R                   Vs/ s H  nSU-   PM
     sn-   U R                   Vs/ s H  nSU-   PM
     sn-   U R
                  -   nU R                  (       aP  X R                   Vs/ s H  nSU-   PM
     snU R                   Vs/ s H  nSU-   PM
     sn-   U R                  -   -  n/ n[        R                  " SSR                  U5      5       HN  n[        R                  " U5      b  M  XC;  d  M#  UR                  U5        SR!                  U5      n[#        U5      e   U$ s  snf s  snf s  snf s  snf s  snf )	zCList of arguments (str) to be passed to e.g. ``subprocess.Popen``. z-Uz-Dz-Iz-Lz-lz\$\{(\w+)\} z$Environment variable '{}' undefined.)r/   r(   r9   r8   r:   r&   r>   r<   r;   rC   rD   findallr6   r)   getenvr@   r5   r
   )rH   r   cmdcountedenvvarrR   s         r   r`   CompilerRunner.cmd   sh    !!"JJ!ZZ(ZT!VZ() "[[)[T!V[)* "../.T!V./	0
 LL 	 ??%6%67%6T!V%67%)^^4^T!V^45MM" #C jj#?Fyy ((NN6*@GGOC&s++ @ 
! ))/ 84s   E(	E-*E2*E7	E<c           
        [        U R                  5      U l        U R                  R                  SU R                  /5        [        R
                  R                  5       nU R                  US'   [        R                  " SR                  U R                  5       5      SU R                  [        R                  [        R                  [        R                  US9nUR                  5       n US   R                  S5      U l        UR$                  U l        U R&                  S:w  ac  S	R)                  SR                  U R                  5       5      U R                  [+        U R&                  5      U R                   5      n[-        U5      eU R                   U R&                  4$ ! ["         a    US   R                  S5      U l         Nf = f)
Nz-oPWDr]   T)shellr-   stdinstdoutstderrenvr   zutf-8z
iso-8859-1z3Error executing '{}' in {} (exited status {}):
 {}
)r	   r(   extendr'   r)   r*   copyr-   
subprocessPopenr6   r`   PIPESTDOUTcommunicatedecode
cmd_outerrUnicodeDecodeError
returncodecmd_returncoder5   r   r
   )rH   rj   pcommrR   s        r   runCompilerRunner.run   sY    ,
 	

4*+jjooXXE
 SXXdhhj1#'!%#-??$.OO$.$5$5!$& }}	;"1gnnW5DO  ll !#IPP$dhhD4G4G0H$//C s## 3 333 " 	;"1gnn\:DO	;s   +F   #GG)rs   rv   r/   r.   r1   r-   r8   r(   r:   r;   r<   rC   r'   r>   r&   r=   r9   )NTN.NNNNNNNNN)N)__name__
__module____qualname____firstlineno____doc____annotations__r   rS   classmethodr4   r`   ry   __static_attributes__r   r!   r   r   r      sq    $L (( "! &% <; #10UXX\SWI>V 	B 	B.4r!   r   c                      \ rS rSrSrSr\" / SQ5      rSrSR                  SR                  SR                  S.r
SS	S
S.rSrg)CCompilerRunner   CCCFLAGS))gnugcc)intelicc)llvmclang)c89c90c99c11-std={})r   r   r   r   r   r   r   Nr|   r}   r~   r   r   r   r   r   r   r5   r   r   r   r   r!   r   r   r      s[      ! M -I !!L $ r!   r   c                6   ^ ^ SS0mT T;   a	  U U4S jnU$ S nU$ )Ng++)zWimplicit-interfacec                ,   > TT    H
  nX;   d  M
    g   g)NFTr   )r   nw
cmplr_namenot_welcomes     r   fltr_mk_flag_filter.<locals>.fltr   s    !*-7  . r!   c                    g)NTr   r   s    r   r   r      s    r!   r   )r   r   r   s   ` @r   _mk_flag_filterr      s,    23K[ 	 K	Kr!   c                      \ rS rSrSrSr\" / SQ5      rSrSR                  SR                  SR                  S.r
SS	S
S.rSrg)CppCompilerRunner   CXXCXXFLAGS))r   r   )r   icpc)r   clang++)zc++98zc++0xr   )r   r   r   r   r   r   r   Nr   r   r!   r   r   r      s[     " ! M #I   ##L $ r!   r   c                  L    \ rS rSrSrSrSrS S S.r\" SS	/5      r	S
SS.r
Srg)FortranCompilerRunneri  FCFFLAGS)Nf77f95f2003f2008c                >    U c  S$ U S:X  a  S$ SR                  U 5      $ )Nz-std=gnur   z-std=legacyr   r5   r   s    r   r   FortranCompilerRunner.<lambda>!  s)    AIjoAQVJ=o\e\l\lmn\oor!   c                4    U c  S$ SR                  U SS  5      $ )Nz
-stand f08z
-stand f{}r   r   s    r   r   r   "  s#    19<U,:M:MaPRPSf:UUr!   )gfortranifort)r   r   )r   r   r   r   r   N)r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r!   r   r   r     sJ     6I pUL
  ! M $ r!   r   )
__future__r   typingr   r   collectionsr   r)   rD   rm   r2   utilr   r	   r
   r   r   r   r   r   r   r!   r   <module>r      sZ    " % # 	 	   
D4 D4Nn 4 6N r!   