
    "Kb;5                     `   d 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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 G d de      Zedk(  r& e	j,                   ee	j.                  d	d              yy)
zuUtility functions for Windows builds.

These functions are executed via gyp-win-tool when using the ninja generator.
    )print_functionNz/OUT:(?P<out>.+)$c                 j    t               }|j                  |       }|t        j                  |       y y N)WinToolDispatchsysexit)argsexecutor	exit_codes      ./usr/lib/python3/dist-packages/gyp/win_tool.pymainr      s0    Y(%)HHY     c                   j    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d Zy)r   zThis class performs all the Windows tooling steps. The methods can either
  be executed directly, or dispatched from an argument list.c           	         t        |      dk  rt        d      |d   dk7  ryd}|D ]X  }t        j                  |      }|st	        j
                  ddd|j                  d	      t        j                         fz        } n |y||d
<   y)zWAllows to use a unique instance of mspdbsrv.exe per linker instead of a
    shared one.   Not enough argumentsr   zlink.exeNz\W+ z%s_%dout_MSPDBSRV_ENDPOINT_)	len	Exception_LINK_EXE_OUT_ARGmatchresubgrouposgetpid)selfenvr
   endpoint_nameargms         r   _UseSeparateMspdbsrvzWinTool._UseSeparateMspdbsrv'   s     4y1},--Aw* M 

!
!#
&a	
vrqwwu~ryy{335 
 "/Cr   c                     t        |      dk  rt        d      d| j                  |d         z  } t        | |      |dd  S )z(Dispatches a string command to a method.r   r   zExec%sr   N)r   r   _CommandifyNamegetattr)r    r
   methods      r   r   zWinTool.DispatchB   sL    
4y1},--,,T!W55F 74 $qr(++r   c                 B    |j                         j                  dd      S )z@Transforms a tool name like recursive-mirror to RecursiveMirror.-r   )titlereplace)r    name_strings     r   r'   zWinTool._CommandifyNameJ   s    &&sB//r   c                     t        |      j                         dd j                  d      }|D cg c]  }|j                  dd       }}t        |      S c c}w )z@Gets the saved environment from a file for a given architecture.N =r   )openreadsplitdict)r    archpairsitemkvss        r   _GetEnvzWinTool._GetEnvN   sS    
 JOOcr"((.E*/
0$4::c1
0C
09 1s   Ac                 8    t        |d      j                          y)zSimple stamp command.wN)r3   close)r    paths     r   	ExecStampzWinTool.ExecStampW   s    sOr   c                    t         j                  j                  |      rt         j                  j                  |      rd }t	        j
                  ||       n]t        j                  |t         j                        s$t        j                  |t        j                         t        j                  |       t         j                  j                  |      rt	        j                  ||       yt	        j                  ||       y)z)Emulation of rm -rf out && cp -af in out.c                     t        j                  |t         j                        s$t        j                  |t        j
                          | |       y r   )r   accessW_OKchmodstatS_IWRITE)fnr?   excinfos      r   	_on_errorz.WinTool.ExecRecursiveMirror.<locals>._on_error_   s/     4)HHT4==)
T(r   )onerrorN)r   r?   existsisdirshutilrmtreerC   rD   rE   rF   rG   unlinkcopytreecopy2)r    sourcedestrJ   s       r   ExecRecursiveMirrorzWinTool.ExecRecursiveMirror[   s    	ww~~d	t		 	dI.yyrww'
((4
'
		$	ww}}Voofd#ll64 r   c                 8   | j                  |      }|dk(  r| j                  ||       t        j                  dk(  r#t	        |      }|d   j                  dd      |d<   t        j                  |t        j                  dk(  |t        j                  t        j                  d      }|j                         \  }}|j                         D ]C  }|j                  d      r|j                  d	      r'|j                  d
      r9t        |       E |j                  S )zFilter 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.
    Truewin32r   /\Tshellr!   stdoutstderruniversal_newlinesz   Creating library zGenerating codezFinished generating code)r;   r%   r   platformlistr-   
subprocessPopenPIPESTDOUTcommunicate
splitlines
startswithprint
returncode)	r    r7   use_separate_mspdbsrvr
   r!   linkr   _lines	            r   ExecLinkWrapperzWinTool.ExecLinkWrapperq   s    
 ,,t
C&
T*
||w$ZdQT*d1g D(?S#-??:;L;L/35D FC  oo45oo/0oo89d	
 ??r   c	                 R   t         j                  |||||||dj                  |	      d	}
d}|	rRt        j                  d|
z         |dk(  r5t        j                  d|
z         t        j                  d|
z         d|
z  }t        j                  ||z          |	rt        j                  d	|
z         d
|
z  }d|
z  }t        |d      5 }t        |d      5 }t        j                  dd|j                               }t        j                  dd|j                               }ddd       ddd       k7  rZt        j                  |       d } ||        ||        ||       t         j                  j                  d|d|d|d       yyy# 1 sw Y   rxY w# 1 sw Y   vxY w)zZA wrapper for handling creating a manifest resource and then executing
    a link command. )	pythonr7   r   ldcmdresnamemtrcintermediate_manifest	manifestsr   zn%(python)s gyp-win-tool manifest-wrapper %(arch)s %(mt)s -nologo -manifest %(manifests)s -out:%(out)s.manifestrW   z`%(python)s gyp-win-tool manifest-to-rc %(arch)s %(out)s.manifest %(out)s.manifest.rc %(resname)szF%(python)s gyp-win-tool rc-wrapper %(arch)s %(rc)s %(out)s.manifest.rcz %(out)s.manifest.resz%(python)s gyp-win-tool manifest-wrapper %(arch)s %(mt)s -nologo -manifest %(out)s.manifest %(intermediate_manifest)s -out:%(out)s.assert.manifestz%(out)s.assert.manifestz%(out)s.manifestrz\s+Nc                 :   t        | t        j                         t        dt        j                         t        | d      5 }t        |j	                         t        j                         t        dt        j                         d d d        y # 1 sw Y   y xY w)N)filez-----ry   )ri   r   r^   r3   r4   )filenamefs     r   dumpz+WinTool.ExecLinkWithManifests.<locals>.dump   sa    
szz
*
cjj
)Hc" ,a!&&(,'

+, , ,s   ABBzLinker generated manifest "z" added to final manifest "z" (result in "z8"). Were /MANIFEST switches used in #pragma statements? r   )r   
executablejoinrb   
check_callr3   r   r   r4   r   rP   r^   write)r    r7   embed_manifestr   rs   rt   ru   rv   rw   rx   	variables	add_to_ldassert_manifestour_manifestour_fassert_four_dataassert_datar~   s                      r   ExecLinkWithManifestszWinTool.ExecLinkWithManifests   s    488I&
I I:<EFG 
6	!-/89	: 	"$-.	/ ,i7	%)+,  )+456 2I=o')3l c" <e/3' 	<8VVFB

5(vr8==?;+	<< 
[	 
		#	, 	"#\_

 $\?D	E
 ! 
! 	< 	<< <s%   FAF FF	FF&c                     | j                  |      }t        j                  |d|t        j                  t        j                  d      }|j                         \  }}|j                         D ]  }|sd|vst        |        |j                  S )zRun manifest tool with environment set. Strip out undesirable warning
    (some XML blocks are recognized by the OS loader, but not the manifest
    tool).Tr[   z#manifest authoring warning 81010002)	r;   rb   rc   rd   re   rf   rg   ri   rj   r    r7   r
   r!   popenr   rm   rn   s           r   ExecManifestWrapperzWinTool.ExecManifestWrapper   s     ,,t
CT3$.OOJ<M<M046E  FC  	7tCd r   c           
          |\  }}}t        |d      5 }|j                  d|dt        j                  j	                  |      j                  dd      d       ddd       y# 1 sw Y   yxY w)zCreates 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).r=   z#include <windows.h>
z RT_MANIFEST "rZ   rY   "N)r3   r   r   r?   abspathr-   )r    r7   r
   manifest_pathresource_pathresource_nameoutputs          r   ExecManifestToRczWinTool.ExecManifestToRc   sb     37/M=-	mS	! <Vll
&..tS9; << < <s   AA""A+c	                    ddgt        |	      z   d|d|d|d|d|d||gz   }
| j                  |      }t        j                  |
d	|t        j                  t        j
                  d	
      }|j                         \  }}|j                         }dt        fd|D              }|D ]$  }|j                        r||vst        |       & |j                  S )zjFilter noisy filenames output from MIDL compile step that isn't
    quietable via command line flags.
    midlz/nologoz/outz/tlbz/hz/dlldataz/iidz/proxyTr[   )zProcessing z64 bit Processing c              3   ~   K   | ]4  }|j                        r!t        j                  j                  |       6 y wr   )rh   r   r?   basename).0xprefixess     r   	<genexpr>z*WinTool.ExecMidlWrapper.<locals>.<genexpr>  s3      ?q||H'= WW%%a( ?s   :=)ra   r;   rb   rc   rd   re   rf   rg   setrh   ri   rj   )r    r7   outdirtlbhdlldataiidproxyidlflagsr
   r!   r   r   rm   lines
processingrn   r   s                     @r   ExecMidlWrapperzWinTool.ExecMidlWrapper   s    
 Ie,aG%0 D ,,t
CT3$.OOJ<M<M046E  FC
 NNE4H ?#? ?J __X&4z+Ad r   c                    | j                  |      }t        j                  |d|t        j                  t        j                  d      }|j                         \  }}|j                         D ]F  }|j                  d      r|j                  d      r'|j                  d      r9|s<t        |       H |j                  S )z/Filter logo banner from invocations of asm.exe.Tr[   #Copyright (C) Microsoft CorporationzMicrosoft (R) Macro Assemblerz Assembling: 
r;   rb   rc   rd   re   rf   rg   rh   ri   rj   r   s           r   ExecAsmWrapperzWinTool.ExecAsmWrapper  s    
,,t
CT3$.OOJ<M<M046E  FC  ooCDoo=>ooo.
d r   c                 ^   | j                  |      }t        j                  |d|t        j                  t        j                  d      }|j                         \  }}|j                         D ]4  }|j                  d      r|j                  d      r'|s*t        |       6 |j                  S )zgFilter logo banner from invocations of rc.exe. Older versions of RC
    don't support the /nologo flag.Tr[   z+Microsoft (R) Windows (R) Resource Compilerr   r   r   s           r   ExecRcWrapperzWinTool.ExecRcWrapper#  s     ,,t
CT3$.OOJ<M<M046E  FC  ooKLooCD
d	
 r   c                     | j                  |      }t        j                  j                         D ]  \  }}||vs|||<    t	        |      j                         }|r|d   nd}t        j                  |d||      S )zRuns an action command line from a response file using the environment
    for |arch|. If |dir| is supplied, use that as the working directory.r   NT)r\   r!   cwd)r;   r   environitemsr3   r4   rb   call)r    r7   rspfiledirr!   kvr
   s           r   ExecActionWrapperzWinTool.ExecActionWrapper2  sz     ,,t
C 

  " 1	
#A =D#a&TC??4t#>>r   c                 6   t         j                  j                  |t              }|j	                  d      }|D cg c]%  }t         j                  j                  ||      dz   ' }}dg}|j                  |       t        j                  |dt              S c c}w )zfExecuted by msvs-ninja projects when the 'ClCompile' target is used to
    build selected C/C++ files.;z^^z	ninja.exeT)r\   r   )	r   r?   relpathBASE_DIRr5   r   extendrb   r   )r    project_dirselected_filesr|   ninja_targetscmds         r   ExecClCompilezWinTool.ExecClCompile?  s     ''//+x8K#))#.N&( WW\\+x84? (M (-CJJ}??3d99	(s   *BN)__name__
__module____qualname____doc__r%   r   r'   r;   r@   rU   ro   r   r   r   r   r   r   r   r    r   r   r   r   #   sU    @/6,0!,<L\<>?	:r   r   __main__r   )r   
__future__r   r   r   rN   rb   rF   stringr   r?   dirnamer   __file__r   compile
IGNORECASEr   r   objectr   r   r	   argvr   r   r   <module>r      s   
 & 	 	     
77??277??845 BJJ2BMMB e:f e:N	 z
#((4 r   