
8	Pc           @   s  d  Z  d 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 m Z d d l m Z d d l m Z d d l Z e j Z e j Z e j Z e j Z e j e j e j e j f Z  e j! d k oe j" d% k Z# e# r'd Z$ d Z% d Z& d Z' n d Z$ d Z% d Z& d Z' i d d 6d d 6d d 6Z( d d& d     YZ) d d' d     YZ* d   Z+ d   Z, d   Z- d   Z. d d   Z/ e+   Z0 e0 d! k  re d" e0   n  d# e f d$     YZ1 d S((   s  distutils.msvc9compiler

Contains MSVCCompiler, an implementation of the abstract CCompiler class
for the Microsoft Visual Studio 2008.

The module is compatible with VS 2005 and VS 2008. You can find legacy support
for older versions of VS in distutils.msvccompiler.
s   $Id$iN(   t   DistutilsExecErrort   DistutilsPlatformErrort   CompileErrort   LibErrort	   LinkError(   t	   CCompilert   gen_lib_options(   t   log(   t   get_platformt   win32i   i    s1   Software\Wow6432Node\Microsoft\VisualStudio\%0.1fs.   Software\Wow6432Node\Microsoft\VCExpress\%0.1fs5   Software\Wow6432Node\Microsoft\Microsoft SDKs\Windowss,   Software\Wow6432Node\Microsoft\.NETFrameworks%   Software\Microsoft\VisualStudio\%0.1fs"   Software\Microsoft\VCExpress\%0.1fs)   Software\Microsoft\Microsoft SDKs\Windowss    Software\Microsoft\.NETFrameworkt   x86t   amd64s	   win-amd64t   ia64s   win-ia64t   Regc           B   sb   e  Z d  Z d   Z e e  Z d   Z e e  Z d   Z e e  Z d   Z e e  Z RS(   s2   Helper class to read values from the registry
    c         C   sM   x: t  D]2 } |  j | |  } | r | | k r | | Sq Wt |   d  S(   N(   t   HKEYSt   read_valuest   KeyError(   t   clst   patht   keyt   baset   d(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt	   get_valueD   s
    c         C   s   y t  | |  } Wn t k
 r' d SXg  } d } xI t r y t | |  } Wn t k
 rd Pn X| j |  | d 7} q7 W| S(   s   Return list of registry keys.i    i   N(   t   RegOpenKeyExt   RegErrort   Nonet   Truet
   RegEnumKeyt   append(   R   R   R   t   handlet   Lt   it   k(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt	   read_keysL   s    	c   	      C   s   y t  | |  } Wn t k
 r' d SXi  } d } xm t r y t | |  \ } } } Wn t k
 rm Pn X| j   } |  j |  | |  j |  <| d 7} q7 W| S(   s`   Return dict of registry keys and values.

        All names are converted to lowercase.
        i    i   N(   R   R   R   R   t   RegEnumValuet   lowert   convert_mbcs(	   R   R   R   R   R   R   t   namet   valuet   type(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyR   ^   s    	c         C   sI   t  |  d d   } | d  k	 rE y | d  }  WqE t k
 rA qE Xn  |  S(   Nt   decodet   mbcs(   t   getattrR   t   UnicodeError(   t   st   dec(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyR$   t   s    (	   t   __name__t
   __module__t   __doc__R   t   classmethodR!   R   R$   t   staticmethod(    (    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyR   @   s   				t   MacroExpanderc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s'   i  |  _  t | |  _ |  j |  d  S(   N(   t   macrost   VS_BASEt   vsbaset   load_macros(   t   selft   version(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt   __init__   s    	c         C   s!   t  j | |  |  j d | <d  S(   Ns   $(%s)(   R   R   R4   (   R8   t   macroR   R   (    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt	   set_macro   s    c         C   sR  |  j  d |  j d d  |  j  d |  j d d  |  j  d t d  y2 | d k rl |  j  d	 t d
  n t d
   Wn t k
 r t d   n X| d k r |  j  d |  j d  |  j  d t d  n} d } xt t D]l } y t | |  } Wn t k
 rq n Xt	 | d  } t
 j | d | | f  } | d |  j d <q Wd  S(   Nt   VCInstallDirs	   \Setup\VCt
   productdirt   VSInstallDirs	   \Setup\VSt   FrameworkDirt   installrootg       @t   FrameworkSDKDirs   sdkinstallrootv2.0s  Python was built with Visual Studio 2008;
extensions must be built with a compiler than can generate compatible binaries.
Visual Studio 2008 was not found on this system. If you have Cygwin installed,
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.g      "@t   FrameworkVersions   clr versiont   WindowsSdkDirt   currentinstallfolders.   Software\Microsoft\NET Framework Setup\Producti    s   %s\%sR9   s   $(FrameworkVersion)(   R<   R6   t   NET_BASER   R   t   WINSDK_BASER   R   R   R   R   R   R4   (   R8   R9   t   pR   t   hR   R   (    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyR7      s.    
c         C   s6   x/ |  j  j   D] \ } } | j | |  } q W| S(   N(   R4   t   itemst   replace(   R8   R,   R    t   v(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt   sub   s    (   R.   R/   R:   R<   R7   RM   (    (    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyR3   ~   s   			c          C   s   d }  t  j j |   } | d k r( d S| t |   } t  j | j d d  \ } } t | d   d } t | d d ! d	 } | d k r d
 } n  | d k r | | Sd S(   s   Return the version of MSVC that was used to build Python.

    For Python 2.3 and up, the version number is included in
    sys.version.  For earlier versions, assume the compiler is MSVC 6.
    s   MSC v.ii   t    i   ii   i   g      $@i    N(   t   sysR9   t   findt   lent   splitt   intR   (   t   prefixR   R,   t   restt   majorVersiont   minorVersion(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt   get_build_version   s    	c         C   sI   g  } x< |  D]4 } t  j j |  } | | k r | j |  q q W| S(   sn   Return a list of normalized paths with duplicates removed.

    The current order of paths is maintained.
    (   t   osR   t   normpathR   (   t   pathst   reduced_pathsRH   t   np(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt   normalize_and_reduce_paths   s    c         C   s[   |  j  t j  } g  } x* | D]" } | | k r | j |  q q Wt j j |  } | S(   s8   Remove duplicate values of an environment variable.
    (   RR   RY   t   pathsepR   t   join(   t   variablet   oldListt   newListR   t   newVariable(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt   removeDuplicates   s    c         C   s  t  |  } y t j d | d  } Wn t k
 r= d } n X| d k r t |  } y t j d | d  } Wq t k
 r d } t j d  q Xn  | s t j	 j
 |  rZd |  } t j j | d  } | rFt j	 j
 |  rFt j	 j | t j t j d  } t j	 j |  } t j	 j
 |  sWt j d |  d SqZt j d |  n  | sqt j d  d St j	 j | d	  } t j	 j |  r| St j d
  d S(   s   Find the vcvarsall.bat file

    At first it tries to find the productdir of VS 2008 in the registry. If
    that fails it falls back to the VS90COMNTOOLS env var.
    s   %s\Setup\VCR>   s%   Unable to find productdir in registrys   VS%0.f0COMNTOOLSt   VCs   %s is not a valid directorys    Env var %s is not set or invalids   No productdir founds   vcvarsall.bats   Unable to find vcvarsall.batN(   R5   R   R   R   R   t   VSEXPRESS_BASER   t   debugRY   R   t   isdirt   environt   getR`   t   pardirt   abspatht   isfile(   R9   R6   R>   t   toolskeyt   toolsdirt	   vcvarsall(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt   find_vcvarsall   s@    



!c         C   s  t  |   } t d  } i  } | d k r9 t d   n  t j d | |   t j d | | f d t j d	 t j } z | j	   \ } } | j
   d
 k r t | j d    n  | j d  } x | j d  D] } t j |  } d | k r q n  | j   } | j d d  \ }	 }
 |	 j   }	 |	 | k r |
 j t j  rW|
 d  }
 n  t |
  | |	 <q q WWd | j j   | j j   Xt |  t |  k rt t t | j       n  | S(   sD   Launch vcvarsall.bat and read the settings from its environment
    t   includet   libt   libpathR   s   Unable to find vcvarsall.bats'   Calling 'vcvarsall.bat %s' (version=%s)s   "%s" %s & sett   stdoutt   stderri    R)   s   
t   =i   iN(   s   includes   libs   libpaths   path(   Rr   t   setR   R   R   Rh   t
   subprocesst   Popent   PIPEt   communicatet   waitR(   RR   R   R$   t   stripR#   t   endswithRY   R_   Re   Rv   t   closeRw   RQ   t
   ValueErrort   strt   listt   keys(   R9   t   archRq   t   interestingt   resultt   popenRv   Rw   t   lineR   R&   (    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt   query_vcvarsall  s<    	!g       @s(   VC %0.1f is not supported by this modulet   MSVCCompilerc           B   s;  e  Z d  Z d Z i  Z d g Z d d d g Z d g Z d g Z e e e e Z	 d Z
 d	 Z d
 Z d Z d Z Z d Z d d d d  Z d d  Z d d d  Z d d d d d d d d  Z d d d d  Z d d d d d d d d d d d 
 Z d   Z d   Z d   Z d   Z d d  Z d   Z RS(   sw   Concrete class that implements an interface to Microsoft Visual C++,
       as defined by the CCompiler abstract class.t   msvcs   .cs   .ccs   .cpps   .cxxs   .rcs   .mcs   .ress   .objs   .libs   .dlls   %s%ss   .exei    c         C   sP   t  j |  | | |  t |  _ d |  _ g  |  _ d  |  _ d  |  _ t	 |  _
 d  S(   Ns   Software\Microsoft\VisualStudio(   R   R:   t   VERSIONt   _MSVCCompiler__versiont   _MSVCCompiler__roott   _MSVCCompiler__pathsR   t	   plat_namet   _MSVCCompiler__archt   Falset   initialized(   R8   t   verboset   dry_runt   force(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyR:   S  s    					c      
   C   s+  |  j  s t d  | d  k r+ t   } n  d& } | | k rS t d | f   n  d t j k r d t j k r |  j d  r d |  _ d	 |  _	 d
 |  _
 d |  _ d |  _ n+| t   k s | d k r t | } n t t   d t | } t t |  } | d j d  j t j  |  _ | d j d  t j d <| d j d  t j d <t |  j  d k rt d |  j   n  |  j d  |  _ |  j d	  |  _	 |  j d
  |  _
 |  j d  |  _ |  j d  |  _ y5 x. t j d j d  D] } |  j j |  qWWn t k
 r#n Xt |  j  |  _ d j |  j  t j d <d  |  _ |  j d k rd d d d d g |  _ d d d d d d g |  _ n9 d d d d d d g |  _ d d d d d d d g |  _ d  d d! g |  _ |  j d" k rd  d d# d$ d% g |  _  n  d g |  _! t" |  _  d  S('   Ns   don't init multiple timesR	   s	   win-amd64s   win-ia64s   --plat-name must be one of %st   DISTUTILS_USE_SDKt   MSSdks   cl.exes   link.exes   lib.exes   rc.exes   mc.exet   _R   R)   Rt   Rs   i    sx   Python was built with %s, and extensions need to be built with the same version of the compiler, but it isn't installed.t   ;R
   s   /nologos   /Oxs   /MDs   /W3s   /DNDEBUGs   /Ods   /MDds   /Z7s   /D_DEBUGs   /GS-s   /DLLs   /INCREMENTAL:NOi   s   /INCREMENTAL:nos   /DEBUGs	   /pdb:None(   s   win32s	   win-amd64s   win-ia64(#   R   t   AssertionErrorR   R   R   RY   Rj   t   find_exet   cct   linkerRt   t   rct   mct   PLAT_TO_VCVARSR   R   t   encodeRR   R_   R   RQ   t   _MSVCCompiler__productR   R   R^   R`   t   preprocess_optionsR   t   compile_optionst   compile_options_debugt   ldflags_sharedR   t   ldflags_shared_debugt   ldflags_staticR   (   R8   R   t   ok_platst	   plat_spect   vc_envRH   (    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt
   initialize^  sf    -				"	t    c         C   s>  | d  k r d } n  g  } x| D]} t j j |  \ } } t j j |  d } | t j j |  } | |  j k r t d |   n  | r t j j |  } n  | |  j	 k r | j
 t j j | | |  j   q" | |  j k r| j
 t j j | | |  j   q" | j
 t j j | | |  j   q" W| S(   NR   i   s   Don't know how to compile %s(   R   RY   R   t   splitextt
   splitdrivet   isabst   src_extensionsR   t   basenamet   _rc_extensionsR   R`   t   res_extensiont   _mc_extensionst   obj_extension(   R8   t   source_filenamest	   strip_dirt
   output_dirt	   obj_namest   src_nameR   t   ext(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt   object_filenames  s(     	c	         C   s  |  j  s |  j   n  |  j | | | | | |  }	 |	 \ } }
 } } } | pR g  } | j d  | r{ | j |  j  n | j |  j  xV|
 D]N} y | | \ } } Wn t k
 r q n X| r t j	 j
 |  } n  | |  j k r d | } n| |  j k rd | } nq| |  j k r| } d | } y) |  j |  j g | | g | g  Wq t k
 r} t |   q Xq n| |  j k rqt j	 j |  } t j	 j |  } y |  j |  j g d | d | g | g  t j	 j t j	 j |   \ } } t j	 j | | d  } |  j |  j g d | g | g  Wq t k
 rj} t |   q Xq n t d | | f   d	 | } y- |  j |  j g | | | | g |  Wq t k
 r} t |   q Xq W|
 S(
   Ns   /cs   /Tcs   /Tps   /fos   -hs   -rs   .rcs"   Don't know how to compile %s to %ss   /Fo(   R   R   t   _setup_compileR   t   extendR   R   R   RY   R   Rm   t   _c_extensionst   _cpp_extensionsR   t   spawnR   R    R   R   t   dirnameR   R   R   R`   R   (   R8   t   sourcesR   R4   t   include_dirsRh   t   extra_preargst   extra_postargst   dependst   compile_infot   objectst   pp_optst   buildt   compile_optst   objt   srcR   t	   input_optt
   output_optt   msgt   h_dirt   rc_dirR   R   t   rc_file(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt   compile  sj    	
#$$#
c   	      C   s   |  j  s |  j   n  |  j | |  \ } } |  j | d | } |  j | |  r | d | g } | ro n  y |  j |  j g |  Wq t k
 r } t |   q Xn t	 j
 d |  d  S(   NR   s   /OUT:s   skipping %s (up-to-date)(   R   R   t   _fix_object_argst   library_filenamet
   _need_linkR   Rt   R    R   R   Rh   (	   R8   R   t   output_libnameR   Rh   t   target_langt   output_filenamet   lib_argsR   (    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt   create_static_lib)  s    		c         C   s  |  j  s |  j   n  |  j | |  \ } } |  j | | |  } | \ } } } | rr |  j d t |   n  t |  | | |  } | d  k	 r t j	 j
 | |  } n  |  j | |  r| t j k r |	 r |  j d } q|  j d } n |	 r|  j } n	 |  j } g  } x% | pg  D] } | j d |  q W| | | | d | g } t j	 j | d  } | d  k	 rt j	 j t j	 j |   \ } } t j	 j
 | |  j |   } | j d |  n  t j	 j
 | t j	 j |  d  } | j d |  |
 r|
 | d *n  | r/| j |  n  |  j t j	 j |   y |  j |  j g |  Wn t k
 r} t |   n X| t j k rd } n d	 } |  j |  d
 | | f } y  |  j d d d | | g  Wqt k
 r} t |   qXn t j d |  d  S(   Ns5   I don't know what to do with 'runtime_library_dirs': i   s   /EXPORT:s   /OUT:i    s   /IMPLIB:s	   .manifests   /MANIFESTFILE:i   s   -outputresource:%s;%ss   mt.exes   -nologos	   -manifests   skipping %s (up-to-date)(   R   R   R   t   _fix_lib_argst   warnR   R   R   RY   R   R`   R   R   t
   EXECUTABLER   R   R   R   R   R   R   R   t   mkpathR   R   R    R   t   _remove_visual_c_refR   Rh   (   R8   t   target_descR   R   R   t	   librariest   library_dirst   runtime_library_dirst   export_symbolsRh   R   R   t
   build_tempR   t
   fixed_argst   lib_optst   ldflagst   export_optst   symt   ld_argst   dll_namet   dll_extt   implib_filet   temp_manifestR   t   mfidt   out_arg(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt   linkB  st    									c         C   s   y t  |  } z | j   } Wd  | j   Xt j d t j  } t j | d |  } d } t j | d |  } t  | d  } z | j |  Wd  | j   XWn t k
 r n Xd  S(   NsU   <assemblyIdentity.*?name=("|')Microsoft\.VC\d{2}\.CRT("|').*?(/>|</assemblyIdentity>)R   s*   <dependentAssembly>\s*</dependentAssembly>t   w(	   t   opent   readR   t   reR   t   DOTALLRM   t   writet   IOError(   R8   t   manifest_filet
   manifest_ft   manifest_buft   pattern(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyR     s"    c         C   s   d | S(   Ns	   /LIBPATH:(    (   R8   t   dir(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt   library_dir_option  s    c         C   s   t  d   d  S(   Ns<   don't know how to set runtime library search path for MSVC++(   R   (   R8   R  (    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt   runtime_library_dir_option  s    c         C   s   |  j  |  S(   N(   R   (   R8   Rt   (    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt   library_option  s    c         C   s   | r | d | g } n	 | g } xW | D]K } xB | D]: } t  j j | |  j |   } t  j j |  r6 | Sq6 Wq) Wd  Sd  S(   Nt   _d(   RY   R   R`   R   t   existsR   (   R8   t   dirsRt   Rh   t	   try_namesR  R%   t   libfile(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt   find_library_file  s    	c         C   s   xH |  j  D]= } t j j t j j |  |  } t j j |  r
 | Sq
 WxU t j d j d  D]= } t j j t j j |  |  } t j j |  rb | Sqb W| S(   s  Return path to an MSVC executable program.

        Tries to find the program in several places: first, one of the
        MSVC program search paths from the registry; next, the directories
        in the PATH environment variable.  If any of those work, return an
        absolute path that is known to exist.  If none of them work, just
        return the original program name, 'exe'.
        t   PathR   (   R   RY   R   R`   Rm   Rn   Rj   RR   (   R8   t   exeRH   t   fn(    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyR     s    	!!N(   R.   R/   R0   t   compiler_typet   executablesR   R   R   R   R   R   R   t   static_lib_extensiont   shared_lib_extensiont   static_lib_formatt   shared_lib_formatt   exe_extensionR:   R   R   R   R   R   R   R   R  R  R  R  R   (    (    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyR   5  sN   			
YV\	 			l        (    (    (2   R0   t   __revision__RY   Rz   RO   R   t   distutils.errorsR    R   R   R   R   t   distutils.ccompilerR   R   t	   distutilsR   t   distutils.utilR   t   _winregt	   OpenKeyExR   t   EnumKeyR   t	   EnumValueR"   t   errorR   t
   HKEY_USERSt   HKEY_CURRENT_USERt   HKEY_LOCAL_MACHINEt   HKEY_CLASSES_ROOTR   t   platformt   maxsizet   NATIVE_WIN64R5   Rg   RG   RF   R   R   R3   RX   R^   Re   Rr   R   R   R   (    (    (    s-   /usr/lib/python2.7/distutils/msvc9compiler.pyt   <module>   sV   (					
>.				,)	