ó
9­\c           @` sù   d  d l  m Z 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 m Z m Z d  d l m Z d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   i    (   t   print_functiont   divisiont   absolute_import(   t   OrderedDictNi   (   t   get_abspatht   FileNotFoundErrort   find_binary_of_commandt   unique_listt   CompileError(   t   string_typest   CompilerRunnerc           B` sw   e  Z d  Z d Z d Z d Z d Z d e d d d d d d d d d d d „ Z	 e
 d d „ ƒ Z d „  Z d „  Z RS(   s’   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.

    t   .c         K` sÝ  t  | t ƒ r t d ƒ ‚ n  t | ƒ |  _ | |  _ | p? g  |  _ | |  _ | ri | \ |  _ |  _	 n~ | d  k r t j j d d  ƒ } n  |  j | ƒ \ |  _ |  _	 |  _ |  j	 d  k rç t d j d j |  j j ƒ  ƒ ƒ ƒ ‚ n  | pð g  |  _ | pÿ g  |  _ | pg  |  _ | pg  |  _ |	 p,g  |  _ |
 pB|  j d |  _ | |  _ |  j r{t t d „  |  j ƒ ƒ |  _ n" d |  j k r|  j j d ƒ n  |  j rÌ|  j j |  j |  j |  j ƒ ƒ n  g  |  _ | d  k	 rÙt  j! d ƒ } t  j! d	 ƒ } | t" k r]t# t$ | j% | ƒ ƒ r2t& d
 ƒ ‚ qÖt# t$ | j% | ƒ ƒ rMqÖ| j d ƒ qÙ| t' k r»t# t$ | j% | ƒ ƒ r„qÖt# t$ | j% | ƒ ƒ r«t& d
 ƒ ‚ qÖ| j d ƒ qÙd } t | j | ƒ ƒ ‚ n  d  S(   Ns2   Expected argument sources to be a list of strings.t   SYMPY_COMPILER_VENDORs!   No compiler found (searched: {0})s   , i    c         S` s
   |  d k S(   Ns   -c(    (   t   x(    (    sC   lib/python2.7/site-packages/sympy/utilities/_compilation/runners.pyt   <lambda>_   t    s   -cs   no-strict-aliasing$s   strict-aliasing$s4   Strict aliasing cannot be both enforced and disableds   -fstrict-aliasings   -fno-strict-aliasings:   Expected argument strict_aliasing to be True/False, got {}((   t
   isinstanceR	   t
   ValueErrort   listt   sourcest   outt   flagst   cwdt   compiler_namet   compiler_binaryt   Nonet   ost   environt   gett   find_compilert   compiler_vendort   formatt   joint   compiler_dictt   valuest   definet   undeft   include_dirst	   librariest   library_dirst	   standardst   stdt
   run_linkert   filtert   appendt   std_formatert   linklinet   ret   compilet   Truet   anyt   mapt   matchR   t   False(   t   selfR   R   R   R*   t   compilerR   R%   R&   R'   R)   R#   R$   t   strict_aliasingt   preferred_vendort   kwargst   nsa_ret   sa_ret   msg(    (    sC   lib/python2.7/site-packages/sympy/utilities/_compilation/runners.pyt   __init__D   sZ    		!*		!		c         C` s   t  |  j j ƒ  ƒ } | rO | | k r7 | g | } qO t d j | ƒ ƒ ‚ n  t g  | D] } |  j | ^ qY ƒ \ } } | | |  j | f S(   s/    Identify a suitable C/fortran/other compiler. s   Unknown vendor {}(   R   R!   t   keysR   R   R   t   compiler_name_vendor_mapping(   t   clsR9   t
   candidatesR   t   namet   path(    (    sC   lib/python2.7/site-packages/sympy/utilities/_compilation/runners.pyR   €   s    ,c         C` sH  |  j  g |  j g  |  j D] } d | ^ q g  |  j D] } d | ^ q8 g  |  j D] } d | ^ qV |  j } |  j rÉ | g  |  j D] } d | ^ qŠ g  |  j D] } d | ^ q§ |  j	 7} n  g  } xr t
 j d d j | ƒ ƒ D]U } t j | ƒ d	 k rë | | k r@| j | ƒ d j | ƒ } t | ƒ ‚ q@që që W| S(
   sD    List of arguments (str) to be passed to e.g. ``subprocess.Popen``. s   -Us   -Ds   -Is   -Ls   -ls   \$\{(\w+)\}t    s$   Environment variable '{}' undefined.N(   R   R   R$   R#   R%   R   R*   R'   R&   R.   R/   t   findallR    R   t   getenvR   R,   R   R   (   R6   R   t   cmdt   countedt   envvarR=   (    (    sC   lib/python2.7/site-packages/sympy/utilities/_compilation/runners.pyRH   Œ   s    j
	;"c         C` sx  t  |  j ƒ |  _ |  j j d |  j g ƒ t j j ƒ  } |  j | d <t j	 d j
 |  j ƒ  ƒ d t d |  j d t j d t j d t j d	 | ƒ} | j ƒ  } t j d
 d k rÄ | d
 |  _ nD y | d
 j d ƒ |  _ Wn' t k
 r| d
 j d ƒ |  _ n X| j |  _ |  j d
 k rhd j d j
 |  j ƒ  ƒ |  j t |  j ƒ |  j ƒ } t | ƒ ‚ n  |  j |  j f S(   Ns   -ot   PWDRE   t   shellR   t   stdint   stdoutt   stderrt   envi    i   s   utf-8s
   iso-8859-1s7   Error executing '{0}' in {1} (exited status {2}):
 {3}
(   R   R   t   extendR   R   R   t   copyR   t
   subprocesst   PopenR    RH   R1   t   PIPEt   STDOUTt   communicatet   syst   version_infot
   cmd_outerrt   decodet   UnicodeDecodeErrort
   returncodet   cmd_returncodeR   t   strR   (   R6   RP   t   pt   commR=   (    (    sC   lib/python2.7/site-packages/sympy/utilities/_compilation/runners.pyt   run£   s0    					0N(   t   __name__t
   __module__t   __doc__R   R!   R(   R-   R@   R1   R>   t   classmethodR   RH   Rb   (    (    (    sC   lib/python2.7/site-packages/sympy/utilities/_compilation/runners.pyR
      s   %:	t   CCompilerRunnerc           B` sb   e  Z e d d d g ƒ Z d Z i d
 j d 6d
 j d 6d
 j d 6Z i d  d 6d d 6d d 6Z RS(   t   gnut   gcct   intelt   icct   llvmt   clangt   c89t   c90t   c99t   c11s   -std={}(   Rh   Ri   (   Rj   Rk   (   Rl   Rm   (   Rn   Ro   Rp   Rq   (   Rc   Rd   R   R!   R(   R   R-   R@   (    (    (    sC   lib/python2.7/site-packages/sympy/utilities/_compilation/runners.pyRg   Ç   s   

c         ` s;   i d d 6‰ ˆ  ˆ k r. ‡  ‡ f d †  } n	 d „  } | S(   Ns   Wimplicit-interfaces   g++c         ` s)   x" ˆ ˆ  D] } | |  k r t  Sq Wt S(   N(   R5   R1   (   R   t   nw(   t
   cmplr_namet   not_welcome(    sC   lib/python2.7/site-packages/sympy/utilities/_compilation/runners.pyt   fltrá   s    c         S` s   t  S(   N(   R1   (   R   (    (    sC   lib/python2.7/site-packages/sympy/utilities/_compilation/runners.pyRu   ç   s    (   s   Wimplicit-interface(    (   Rs   Ru   (    (   Rs   Rt   sC   lib/python2.7/site-packages/sympy/utilities/_compilation/runners.pyt   _mk_flag_filterÞ   s
    	t   CppCompilerRunnerc           B` sb   e  Z e d	 d
 d g ƒ Z d Z i d j d 6d j d 6d j d 6Z i d  d 6d d 6d d 6Z RS(   Rh   s   g++Rj   t   icpcRl   s   clang++s   c++98s   c++0xs   -std={}(   Rh   s   g++(   Rj   Rx   (   Rl   s   clang++(   s   c++98s   c++0x(   Rc   Rd   R   R!   R(   R   R-   R@   (    (    (    sC   lib/python2.7/site-packages/sympy/utilities/_compilation/runners.pyRw   ì   s   

t   FortranCompilerRunnerc           B` sN   e  Z d Z i d „  d 6d „  d 6Z e d d g ƒ Z i d d 6d	 d 6Z RS(   t   f77t   f95t   f2003t   f2008c         C` s-   |  d  k r d S|  d k r  d Sd j |  ƒ S(   Ns   -std=gnuRz   s   -std=legacys   -std={}(   R   R   (   R   (    (    sC   lib/python2.7/site-packages/sympy/utilities/_compilation/runners.pyR   	  R   t   gfortranc         C` s!   |  d  k r d Sd j |  d ƒ S(   Ns
   -stand f08s
   -stand f{}iþÿÿÿ(   R   R   (   R   (    (    sC   lib/python2.7/site-packages/sympy/utilities/_compilation/runners.pyR   
  R   t   ifortRh   Rj   N(   NRz   R{   R|   R}   (   Rh   R~   (   Rj   R   (   Rc   Rd   R   R(   R-   R   R!   R@   (    (    (    sC   lib/python2.7/site-packages/sympy/utilities/_compilation/runners.pyRy     s   
(   t
   __future__R    R   R   t   collectionsR   R   R/   RS   RX   t   utilR   R   R   R   R   t   sympy.core.compatibilityR	   t   objectR
   Rg   Rv   Rw   Ry   (    (    (    sC   lib/python2.7/site-packages/sympy/utilities/_compilation/runners.pyt   <module>   s   (µ	