
    擖g;                     T   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKr\R                  R                  \R                  R                  \5      5      r\R                  " S\R                  5      rS r " S S5      r\S:X  a&  \R&                  " \" \R(                  SS 5      5        gg)	zuUtility functions for Windows builds.

These functions are executed via gyp-win-tool when using the ninja generator.
    Nz/OUT:(?P<out>.+)$c                 n    [        5       nUR                  U 5      nUb  [        R                  " U5        g g N)WinToolDispatchsysexit)argsexecutor	exit_codes      ./usr/lib/python3/dist-packages/gyp/win_tool.pymainr      s0    yH!!$'I     c                   r    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rSrg)r   #   zThis class performs all the Windows tooling steps. The methods can either
be executed directly, or dispatched from an argument list.c           	      ,   [        U5      S:  a  [        S5      eUS   S:w  a  gSnU H`  n[        R                  U5      nU(       d  M!  [        R
                  " SSSUR                  S	5      [        R                  " 5       4-  5      n  O   Uc  gX1S
'   g)zSAllows 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   _UseSeparateMspdbsrvWinTool._UseSeparateMspdbsrv'   s     t9q=2337j  C!'',Aq "B1775>299;*G G!    
 &3!"r   c                     [        U5      S:  a  [        S5      eSU R                  US   5      -  n[        X5      " USS 6 $ )z(Dispatches a string command to a method.r   r   zExec%sr   N)r   r   _CommandifyNamegetattr)r    r	   methods      r   r   WinTool.DispatchC   sH    t9q=233D00a99t$d12h//r   c                 B    UR                  5       R                  SS5      $ )z@Transforms a tool name like recursive-mirror to RecursiveMirror.-r   )titlereplace)r    name_strings     r   r(   WinTool._CommandifyNameK   s      "**333r   c                     [        U5      R                  5       SS R                  S5      nU Vs/ s H  o3R                  SS5      PM     nn[        U5      $ s  snf )z@Gets the saved environment from a file for a given architecture.N =r   )openreadsplitdict)r    archpairsitemkvss        r   _GetEnvWinTool._GetEnvO   sR    
 T
!#2&,,T2.34edzz#q!e4Cy 5s   Ac                 8    [        US5      R                  5         g)zSimple stamp command.wN)r6   close)r    paths     r   	ExecStampWinTool.ExecStampX   s    T3r   c                 0   [         R                  R                  U5      (       a  [         R                  R                  U5      (       a  S n[        R
                  " X#S9  Oe[         R                  " U[         R                  5      (       d%  [         R                  " U[        R                  5        [         R                  " U5        [         R                  R                  U5      (       a  [        R                  " X5        g[        R                  " X5        g)z)Emulation of rm -rf out && cp -af in out.c                     [         R                  " U[         R                  5      (       d%  [         R                  " U[        R
                  5        U " U5        g r   )r   accessW_OKchmodstatS_IWRITE)fnrC   excinfos      r   	_on_error.WinTool.ExecRecursiveMirror.<locals>._on_errora   s2     99T27733t}}5tHr   )onerrorN)r   rC   existsisdirshutilrmtreerH   rI   rJ   rK   rL   unlinkcopytreecopy2)r    sourcedestrO   s       r   ExecRecursiveMirrorWinTool.ExecRecursiveMirror\   s    77>>$ww}}T"" d6yyrww//HHT4==1		$77==  OOF)LL&r   c                 z   U R                  U5      nUS:X  a  U R                  XC5        [        R                  S:X  a#  [	        U5      nUS   R                  SS5      US'   [        R                  " U[        R                  S:H  U[        R                  [        R                  S9nUR                  5       S   R                  S5      nUR                  5        HV  nUR                  S5      (       a  M  UR                  S	5      (       a  M3  UR                  S
5      (       a  MK  [        U5        MX     UR                  $ )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   /\shellr!   stdoutstderrutf-8z   Creating library zGenerating codezFinished generating code)r>   r%   r   platformlistr/   
subprocessPopenPIPESTDOUTcommunicatedecode
splitlines
startswithprint
returncode)r    r:   use_separate_mspdbsrvr	   r!   linkr   lines           r   ExecLinkWrapperWinTool.ExecLinkWrappert   s    
 ll4  F*%%c0<<7":D1gooc40DG ,,')??$$
  #**73NN$DOO$:;;(9::(BCCd % r   c	                    [         R                  UUUUUUUSR                  U	5      S.	n
SnU	(       aV  [        R                  " SU
-  5        US:X  a7  [        R                  " SU
-  5        [        R                  " SU
-  5        SU
-  n[        R                  " XK-   5        U	(       Ga  [        R                  " S	U
-  5        S
U
-  nSU
-  n[        U5       n[        U5       n[        R                  SS[        R                  5      nUR                  5       R                  U5      nUR                  5       R                  U5      nSSS5        SSS5        WW:w  a^  [        R                  " U5        S nU" U5        U" U5        U" U5        [         R                  R                  SU< SU< SU< S35        ggg! , (       d  f       N|= f! , (       d  f       N= f)zVA wrapper for handling creating a manifest resource and then executing
a link command. )	pythonr:   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.manifestr^   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.manifestNc                 *   [        U [        R                  S9  [        S[        R                  S9  [        U 5       n[        UR	                  5       [        R                  S9  [        S[        R                  S9  S S S 5        g ! , (       d  f       g = f)N)filez-----)rq   r   re   r6   r7   )filenamefs     r   dump+WinTool.ExecLinkWithManifests.<locals>.dump   sS    (4'

3h1affhSZZ8gCJJ7 (s   ?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joinri   
check_callr6   str	maketransstring
whitespacer7   	translater   rV   re   write)r    r:   embed_manifestr   r{   r|   r}   r~   r   r   	variables	add_to_ldassert_manifestour_manifestour_fassert_f
translatorour_dataassert_datar   s                       r   ExecLinkWithManifestsWinTool.ExecLinkWithManifests   s   2 nn%:),

	 	!!@BKL '%%79BC %%*,56 4i?	e/0  !!/1:;
 8)CO-	9L l#ud?.Cx ]]2r63D3DE
 ::<11*=&mmo77
C /D# ;&		#8 *+\"_%

   -lOM ' '!  /D.C##s%   G#A$F=G=
G	G
Gc                 N   U R                  U5      n[        R                  " USU[        R                  [        R                  S9nUR                  5       S   R                  S5      nUR                  5        H  nU(       d  M  SU;  d  M  [        U5        M!     UR                  $ )zRun manifest tool with environment set. Strip out undesirable warning
(some XML blocks are recognized by the OS loader, but not the manifest
tool).Trb   r   rf   z#manifest authoring warning 81010002)
r>   ri   rj   rk   rl   rm   rn   ro   rq   rr   r    r:   r	   r!   popenr   ru   s          r   ExecManifestWrapperWinTool.ExecManifestWrapper   s     ll4   #joojFWFW
 !!$++G4NN$Dt=TId % r   c           
          Uu  p4n[        US5       nUR                  SU< S[        R                  R	                  U5      R                  SS5      < S35        SSS5        g! , (       d  f       g= f)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).rA   z#include <windows.h>
z RT_MANIFEST "ra   r`   "N)r6   r   r   rC   abspathr/   )r    r:   r	   manifest_pathresource_pathresource_nameoutputs          r   ExecManifestToRcWinTool.ExecManifestToRc  sW     7;3m-%LL "''//-"@"H"Hs"SU &%%s   AA##
A1c	                 L   SS/[        U	5      -   SUSUSUSUSUSUU/-   n
U R                  U5      n[        R                  " U
S	U[        R                  [        R
                  S
9nUR                  5       S   R                  S5      nUR                  5       nSnU Vs1 s H:  nUR                  U5      (       d  M  [        R                  R                  U5      iM<     nnU H.  nUR                  U5      (       a  M  UU;  d  M#  [        U5        M0     UR                  $ s  snf )zbFilter noisy filenames output from MIDL compile step that isn't
quietable via command line flags.
midlz/nologoz/outz/tlbz/hz/dlldataz/iidz/proxyTrb   r   rf   )zProcessing z64 bit Processing )rh   r>   ri   rj   rk   rl   rm   rn   ro   rp   r   rC   basenamerq   rr   )r    r:   outdirtlbhdlldataiidproxyidlflagsr	   r!   r   r   linesprefixesx
processingru   s                      r   ExecMidlWrapperWinTool.ExecMidlWrapper  s$   
 Y5k  	& ll4   #joojFWFW
 !!$++G4
  838S5aALL<R)bgg&&q)5
SD??8,,Z1Gd  	 Ts   D!<#D!c                    U R                  U5      n[        R                  " USU[        R                  [        R                  S9nUR                  5       S   R                  S5      nUR                  5        H_  nUR                  S5      (       a  M  UR                  S5      (       a  M3  UR                  S5      (       a  MK  U(       d  MT  [        U5        Ma     UR                  $ )z/Filter logo banner from invocations of asm.exe.Trb   r   rf   #Copyright (C) Microsoft CorporationzMicrosoft (R) Macro Assemblerz Assembling: r>   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   r   s          r   ExecAsmWrapperWinTool.ExecAsmWrapper8  s    ll4   #joojFWFW
 !!$++G4NN$DOO$IJJ(GHH88Dd % r   c                    U R                  U5      n[        R                  " USU[        R                  [        R                  S9nUR                  5       S   R                  S5      nUR                  5        HG  nUR                  S5      (       a  M  UR                  S5      (       a  M3  U(       d  M<  [        U5        MI     UR                  $ )zcFilter logo banner from invocations of rc.exe. Older versions of RC
don't support the /nologo flag.Trb   r   rf   z+Microsoft (R) Windows (R) Resource Compilerr   r   r   s          r   ExecRcWrapperWinTool.ExecRcWrapperI  s     ll4   #joojFWFW
 !!$++G4NN$DOO$QRR(MNNDd % r   c                    U R                  U5      n[        R                  R                  5        H  u  pVXT;  d  M  XdU'   M     [	        U5      R                  5       nU(       a  US   OSn[        R                  " USXCS9$ )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)rc   r!   cwd)r>   r   environitemsr6   r7   ri   call)r    r:   rspfiledirr!   kvr	   s           r   ExecActionWrapperWinTool.ExecActionWrapperZ  sm     ll4  JJ$$&DA|A ' G}!!#c!ft4SBBr   c                 6   [         R                  R                  U[        5      nUR	                  S5      nU Vs/ s H%  n[         R                  R                  X5      S-   PM'     nnS/nUR                  U5        [        R                  " US[        S9$ s  snf )zbExecuted by msvs-ninja projects when the 'ClCompile' target is used to
build selected C/C++ files.;z^^z	ninja.exeT)rc   r   )	r   rC   relpathBASE_DIRr8   r   extendri   r   )r    project_dirselected_filesr   ninja_targetscmds         r   ExecClCompileWinTool.ExecClCompileg  s     ggook8<'--c2GU
GU8BGGLL/$6~ 	 
 m

=!s$H==
s   ,B N)__name__
__module____qualname____firstlineno____doc__r%   r   r(   r>   rD   r[   rv   r   r   r   r   r   r   r   r   __static_attributes__r   r   r   r   r   #   sX    @3804 '0"H]~ 	& P " "C
>r   r   __main__r   )r   r   r   rT   ri   rK   r   r   rC   dirnamer   __file__r   compile
IGNORECASEr   r   r   r   r   argvr   r   r   <module>r      s    
 	     
77??277??845 JJ2BMMB N> N>b
 zHHT#((12,  r   