ó
ÓnäZc           @   sŁ   d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z e j j	 e j j
 e   Z e j d e j  Z d   Z d e f d     YZ e d k rÕ e j e e j d   n  d S(	   su   Utility functions for Windows builds.

These functions are executed via gyp-win-tool when using the ninja generator.
i’’’’Ns   /OUT:(?P<out>.+)$c         C   s8   t    } | j |   } | d  k	 r4 t j |  n  d  S(   N(   t   WinToolt   Dispatcht   Nonet   syst   exit(   t   argst   executort	   exit_code(    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyt   main   s    	R    c           B   s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z RS(   s   This class performs all the Windows tooling steps. The methods can either
  be executed directly, or dispatched from an argument list.c         C   s±   t  |  d k  r! t d   n  | d d k r5 d Sd } xU | D]M } t j |  } | rB t j d d d | j d	  t j	   f  } PqB qB W| d k r£ d S| | d
 <d S(   sW   Allows to use a unique instance of mspdbsrv.exe per linker instead of a
    shared one.i   s   Not enough argumentsi    s   link.exeNs   \W+t    s   %s_%dt   outt   _MSPDBSRV_ENDPOINT_(
   t   lent	   ExceptionR   t   _LINK_EXE_OUT_ARGt   matcht   ret   subt   groupt   ost   getpid(   t   selft   envR   t   endpoint_namet   argt   m(    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyt   _UseSeparateMspdbsrv%   s    "c         C   sO   t  |  d k  r! t d   n  d |  j | d  } t |  |  | d   S(   s(   Dispatches a string command to a method.i   s   Not enough argumentss   Exec%si    (   R   R   t   _CommandifyNamet   getattr(   R   R   t   method(    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyR   @   s    c         C   s   | j    j d d  S(   s@   Transforms a tool name like recursive-mirror to RecursiveMirror.t   -R	   (   t   titlet   replace(   R   t   name_string(    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyR   H   s    c         C   sN   t  |  j   d  j d  } g  | D] } | j d d  ^ q& } t |  S(   s@   Gets the saved environment from a file for a given architecture.iž’’’s    t   =i   (   t   opent   readt   splitt   dict(   R   t   archt   pairst   itemt   kvs(    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyt   _GetEnvL   s    %c         C   s   t  | d  j   d S(   s   Simple stamp command.t   wN(   R#   t   close(   R   t   path(    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyt	   ExecStampU   s    c         C   s·   t  j j |  r~ t  j j |  rC d   } t j | d | q~ t  j | t  j  sn t  j | t	 j
  n  t  j |  n  t  j j |  r£ t j | |  n t j | |  d S(   s)   Emulation of rm -rf out && cp -af in out.c         S   s9   t  j | t  j  s+ t  j | t j  n  |  |  d  S(   N(   R   t   accesst   W_OKt   chmodt   statt   S_IWRITE(   t   fnR.   t   excinfo(    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyt	   _on_error]   s    t   onerrorN(   R   R.   t   existst   isdirt   shutilt   rmtreeR0   R1   R2   R3   R4   t   unlinkt   copytreet   copy2(   R   t   sourcet   destR7   (    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyt   ExecRecursiveMirrorY   s    	c   	   
   G   s  |  j  |  } | d k r. |  j | |  n  t j d k rf t |  } | d j d d  | d <n  t j | d t j d k d | d t j d	 t j	 } | j
   \ } } xL | j   D]> } | j d
  r» | j d  r» | j d  r» | GHq» q» W| j S(   s°   Filter diagnostic output from link that looks like:
    '   Creating library ui.dll.lib and object ui.dll.exp'
    This happens when there are exports from the dll or exe.
    t   Truet   win32i    t   /s   \t   shellR   t   stdoutt   stderrs      Creating library s   Generating codes   Finished generating code(   R+   R   R   t   platformt   listR    t
   subprocesst   Popent   PIPEt   STDOUTt   communicatet
   splitlinest
   startswitht
   returncode(	   R   R'   t   use_separate_mspdbsrvR   R   t   linkR
   t   _t   line(    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyt   ExecLinkWrappero   s    	!c	         G   s¶  i	 t  j d 6| d 6| d 6| d 6| d 6| d 6| d 6| d 6d	 j |	  d
 6}
 d } |	 r¬ t j d |
  | d k r¬ t j d |
  t j d |
  d |
 } q¬ n  t j | |  |	 r²t j d |
  d |
 } d |
 } t | d  U } t | d  = } | j   j d t	 j
  } | j   j d t	 j
  } Wd QXWd QX| | k r²t j |  d   } | |  | |  | |  t  j j d | | | f  d Sn  d S(   sZ   A wrapper for handling creating a manifest resource and then executing
    a link command.t   pythonR'   R
   t   ldcmdt   resnamet   mtt   rct   intermediate_manifestt    t	   manifestsR	   sn   %(python)s gyp-win-tool manifest-wrapper %(arch)s %(mt)s -nologo -manifest %(manifests)s -out:%(out)s.manifestRC   s`   %(python)s gyp-win-tool manifest-to-rc %(arch)s %(out)s.manifest %(out)s.manifest.rc %(resname)ssF   %(python)s gyp-win-tool rc-wrapper %(arch)s %(rc)s %(out)s.manifest.rcs    %(out)s.manifest.ress   %(python)s gyp-win-tool manifest-wrapper %(arch)s %(mt)s -nologo -manifest %(out)s.manifest %(intermediate_manifest)s -out:%(out)s.assert.manifests   %(out)s.assert.manifests   %(out)s.manifestt   rbNc         S   sJ   t  j j d |   t |  d  ! } t  j j | j   d  Wd  QXd  S(   Ns	   %s
-----
R`   s   
-----
(   R   RH   t   writeR#   R$   (   t   filenamet   f(    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyt   dumpŹ   s    s   Linker generated manifest "%s" added to final manifest "%s" (result in "%s"). Were /MANIFEST switches used in #pragma statements? i   (   R   t
   executablet   joinRK   t
   check_callR#   R$   t	   translateR   t   stringt
   whitespaceR   R=   RH   Ra   (   R   R'   t   embed_manifestR
   RY   RZ   R[   R\   R]   R_   t	   variablest	   add_to_ldt   assert_manifestt   our_manifestt   our_ft   assert_ft   our_datat   assert_dataRd   (    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyt   ExecLinkWithManifests   sX    


'	


	c      
   G   s   |  j  |  } t j | d t d | d t j d t j } | j   \ } } x. | j   D]  } | r[ d | k r[ | GHq[ q[ W| j S(   s   Run manifest tool with environment set. Strip out undesirable warning
    (some XML blocks are recognized by the OS loader, but not the manifest
    tool).RF   R   RG   RH   s#   manifest authoring warning 81010002(	   R+   RK   RL   RC   RM   RN   RO   RP   RR   (   R   R'   R   R   t   popenR
   RU   RV   (    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyt   ExecManifestWrapperŲ   s    c      
   G   sZ   | \ } } } t  | d  6 } | j d | t j j |  j d d  f  Wd QXd S(   sŃ   Creates a resource file pointing a SxS assembly manifest.
    |args| is tuple containing path to resource file, path to manifest file
    and resource name which can be "1" (for executables) or "2" (for DLLs).t   wbs(   #include <windows.h>
%s RT_MANIFEST "%s"s   \RE   N(   R#   Ra   R   R.   t   abspathR    (   R   R'   R   t   manifest_patht   resource_patht   resource_namet   output(    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyt   ExecManifestToRcå   s
    	c	            sł   d d g t  |	  d | d | d | d | d | d | | g }
 |  j |  } t j |
 d	 t d
 | d t j d t j } | j   \ } } | j   } d   t	   f d   | D  } x2 | D]* } | j
    rÄ | | k rÄ | GHqÄ qÄ W| j S(   sj   Filter noisy filenames output from MIDL compile step that isn't
    quietable via command line flags.
    t   midls   /nologos   /outs   /tlbs   /hs   /dlldatas   /iids   /proxyRF   R   RG   RH   s   Processing s   64 bit Processing c         3   s0   |  ]& } | j     r t j j |  Vq d  S(   N(   RQ   R   R.   t   basename(   t   .0t   x(   t   prefixes(    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pys	   <genexpr>  s   (   s   Processing s   64 bit Processing (   RJ   R+   RK   RL   RC   RM   RN   RO   RP   t   setRQ   RR   (   R   R'   t   outdirt   tlbt   ht   dlldatat   iidt   proxyt   idlt   flagsR   R   Ru   R
   RU   t   linest
   processingRV   (    (   R   s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyt   ExecMidlWrapperļ   s(    
c      
   G   sŖ   |  j  |  } t j | d t d | d t j d t j } | j   \ } } xR | j   D]D } | j d  r[ | j d  r[ | j d  r[ | r[ | GHq[ q[ W| j	 S(   s/   Filter logo banner from invocations of asm.exe.RF   R   RG   RH   s#   Copyright (C) Microsoft Corporations   Microsoft (R) Macro Assemblers    Assembling: (
   R+   RK   RL   RC   RM   RN   RO   RP   RQ   RR   (   R   R'   R   R   Ru   R
   RU   RV   (    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyt   ExecAsmWrapper  s    c      
   G   s   |  j  |  } t j | d t d | d t j d t j } | j   \ } } xB | j   D]4 } | j d  r[ | j d  r[ | r[ | GHq[ q[ W| j	 S(   sg   Filter logo banner from invocations of rc.exe. Older versions of RC
    don't support the /nologo flag.RF   R   RG   RH   s+   Microsoft (R) Windows (R) Resource Compilers#   Copyright (C) Microsoft Corporation(
   R+   RK   RL   RC   RM   RN   RO   RP   RQ   RR   (   R   R'   R   R   Ru   R
   RU   RV   (    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyt   ExecRcWrapper  s    c         G   s   |  j  |  } x6 t j j   D]% \ } } | | k r | | | <q q Wt |  j   } | rj | d n d } t j | d t	 d | d | S(   s   Runs an action command line from a response file using the environment
    for |arch|. If |dir| is supplied, use that as the working directory.i    RF   R   t   cwdN(
   R+   R   t   environt	   iteritemsR#   R$   R   RK   t   callRC   (   R   R'   t   rspfilet   dirR   t   kt   vR   (    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyt   ExecActionWrapper)  s    c         C   s   t  j j | t  } | j d  } g  | D] } t  j j | |  d ^ q+ } d g } | j |  t j | d t	 d t S(   sf   Executed by msvs-ninja projects when the 'ClCompile' target is used to
    build selected C/C++ files.t   ;s   ^^s	   ninja.exeRF   R   (
   R   R.   t   relpatht   BASE_DIRR%   Rf   t   extendRK   R   RC   (   R   t   project_dirt   selected_filesRb   t   ninja_targetst   cmd(    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyt   ExecClCompile6  s    )	(   t   __name__t
   __module__t   __doc__R   R   R   R+   R/   RB   RW   Rt   Rv   R}   R   R   R   R   R¢   (    (    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyR    !   s    									L		
				t   __main__i   (   R„   R   R   R;   RK   R3   Ri   R   R.   t   dirnameRx   t   __file__R   t   compilet
   IGNORECASER   R   t   objectR    R£   R   t   argv(    (    (    s0   /usr/lib/python2.7/dist-packages/gyp/win_tool.pyt   <module>
   s   	’ !