
    "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
                            e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                              dS dS )
zuUtility functions for Windows builds.

These functions are executed via gyp-win-tool when using the ninja generator.
    )print_functionNz/OUT:(?P<out>.+)$c                 |    t                      }|                    |           }|t          j        |           d S d S N)WinToolDispatchsysexit)argsexecutor	exit_codes      ./usr/lib/python3/dist-packages/gyp/win_tool.pymainr      sB    YY(%%)HY     c                   l    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dS )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k    rdS d}|D ]_}t                              |          }|rAt	          j        ddd|                    d	          t          j                    fz            } n`|dS ||d
<   dS )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     4yy1}},---Aw*f M  

!
!#
&
&a	
 vrqwwu~~ry{{335 5
 f
 "/Cr   c                     t          |          dk     rt          d          d|                     |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   s[    
4yy1}},---,,T!W555F 74  $qrr(++r   c                 R    |                                                     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          |                                          dd                             d          }d |D             }t          |          S )z@Gets the saved environment from a file for a given architecture.N c                 :    g | ]}|                     d d          S )=r   )split).0items     r   
<listcomp>z#WinTool._GetEnv.<locals>.<listcomp>T   s&    
0
0
0$4::c1
0
0
0r   )openreadr4   dict)r    archpairskvss       r   _GetEnvzWinTool._GetEnvN   sO    
 JJOOcrc"((..E
0
0%
0
0
0C99r   c                 J    t          |d                                           dS )zSimple stamp command.wN)r8   close)r    paths     r   	ExecStampzWinTool.ExecStampW   s"    sOOr   c                    t           j                            |          rt           j                            |          rd }t	          j        ||           nRt          j        |t           j                  st          j        |t          j
                   t          j        |           t           j                            |          rt	          j        ||           dS t	          j        ||           dS )z)Emulation of rm -rf out && cp -af in out.c                     t          j        |t           j                  st          j        |t          j                    | |           d S r   )r   accessW_OKchmodstatS_IWRITE)fnrB   excinfos      r   	_on_errorz.WinTool.ExecRecursiveMirror.<locals>._on_error_   s?     4)) *HT4=)))
"T(((((r   )onerrorN)r   rB   existsisdirshutilrmtreerF   rG   rH   rI   rJ   unlinkcopytreecopy2)r    sourcedestrM   s       r   ExecRecursiveMirrorzWinTool.ExecRecursiveMirror[   s    	w~~d 	t		 	 	 	 	dI.....yrw'' 	(
(4
'
'
'
	$	w}}V !ofd#####l64     r   c                 ^   |                      |          }|dk    r|                     ||           t          j        dk    r.t	          |          }|d                             dd          |d<   t          j        |t          j        dk    |t          j        t          j	        d          }|
                                \  }}|                                D ]P}|                    d          s9|                    d	          s$|                    d
          st          |           Q|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    r;   use_separate_mspdbsrvr
   r!   linkr   _lines	            r   ExecLinkWrapperzWinTool.ExecLinkWrapperq   s!   
 ,,t

C&&
T***
|w$ZZdQT**d1g D(?S#-?:;L/35 5 5D FC    oo455 oo/00oo899 	d?r   c	                    t           j        |||||||d                    |	          d	}
d}|	rPt          j        d|
z             |dk    r3t          j        d|
z             t          j        d|
z             d|
z  }t          j        ||z              |	r*t          j        d	|
z             d
|
z  }d|
z  }t          |d          5 }t          |d          5 }t          j        dd|                                          }t          j        dd|                                          }ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   ||k    ret          j
        |           d } ||            ||            ||           t           j                            d|d|d|d           dS dS dS )zZA 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.manifestrZ   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          | t          j                   t          dt          j                   t          | d          5 }t          |                                t          j                   t          dt          j                   d d d            d S # 1 swxY w Y   d S )N)filez-----r|   )rl   r   ra   r8   r9   )filenamefs     r   dumpz+WinTool.ExecLinkWithManifests.<locals>.dump   s    
sz
*
*
*
*
cj
)
)
)
)Hc"" ,a!&&((,,,,'
++++, , , , , , , , , , , , , , , , , ,s   A	B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joinre   
check_callr8   r   r   r9   r   rS   ra   write)r    r;   embed_manifestr   rv   rw   rx   ry   rz   r{   	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 8:<EFG G G 
6	!	!-/89	: 	: 	: 	"$-.	/ 	/ 	/ ,i7	%)+,,,   )+456 6 6 2I=o')3l c"" <e/3'' 	<8VFB

55(vr8==??;;+	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<< < < < < < < < < < < < < < < 
[	 	 
	#	, 	, 	, 	"###\_
 $##\\\???D	E 	E 	E
 q?  
!	 s7   	EAD7+E7D;	;E>D;	?EEEc                    |                      |          }t          j        |d|t          j        t          j        d          }|                                \  }}|                                D ]}|rd|vr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>   re   rf   rg   rh   ri   rj   rl   rm   r    r;   r
   r!   popenr   rp   rq   s           r   ExecManifestWrapperzWinTool.ExecManifestWrapper   s     ,,t

CT3$.OJ<M046 6 6E   FC    	 7tCCdr   c           
          |\  }}}t          |d          5 }|                    d|dt          j                            |                              dd          d           ddd           dS # 1 swxY w Y   dS )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 "r]   r\   "N)r8   r   r   rB   abspathr-   )r    r;   r
   manifest_pathresource_pathresource_nameoutputs          r   ExecManifestToRczWinTool.ExecManifestToRc   s     37/M=-	mS	!	! <Vlll
&&..tS9999; < < << < < < < < < < < < < < < < < < < <s   AA22A69A6c	                    ddgt          |	          z   d|d|d|d|d|d||gz   }
|                     |          }t          j        |
d	|t          j        t          j        d	
          }|                                \  }}|                                }dt          fd|D                       }|D ]*}|	                              s||vr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   | ]8}|                               t          j                            |          V  9d S r   )rk   r   rB   basename)r5   xprefixess     r   	<genexpr>z*WinTool.ExecMidlWrapper.<locals>.<genexpr>  sW       ? ?q||H'='=?RW%%a(( ? ? ? ? ? ?r   )rd   r>   re   rf   rg   rh   ri   rj   setrk   rl   rm   )r    r;   outdirtlbhdlldataiidproxyidlflagsr
   r!   r   r   rp   lines
processingrq   r   s                     @r   ExecMidlWrapperzWinTool.ExecMidlWrapper   s&   
 Ie,aG%0 D ,,t

CT3$.OJ<M046 6 6E   FC
 NNE4H ? ? ? ?#? ? ? ? ?J  __X&& 4z+A+Adr   c                    |                      |          }t          j        |d|t          j        t          j        d          }|                                \  }}|                                D ]R}|                    d          s;|                    d          s&|                    d          s|rt          |           S|j	        S )z/Filter logo banner from invocations of asm.exe.Tr^   #Copyright (C) Microsoft CorporationzMicrosoft (R) Macro Assemblerz Assembling: 
r>   re   rf   rg   rh   ri   rj   rk   rl   rm   r   s           r   ExecAsmWrapperzWinTool.ExecAsmWrapper  s    
,,t

CT3$.OJ<M046 6 6E   FC    ooCDD oo=>>ooo..  	dr   c                 h   |                      |          }t          j        |d|t          j        t          j        d          }|                                \  }}|                                D ]=}|                    d          s&|                    d          s|rt          |           >|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$.OJ<M046 6 6E   FC    ooKLL ooCDD
 	dr   c                    |                      |          }t          j                                        D ]\  }}||vr|||<   t	          |                                          }|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itemsr8   r9   re   call)r    r;   rspfiledirr!   kvr
   s           r   ExecActionWrapperzWinTool.ExecActionWrapper2  s     ,,t

C 
  ""  1	
#A==D
!#a&&TC?4t#>>>>r   c                     t           j                            t                    |                    d          }fd|D             }dg}|                    |           t          j        |dt                    S )zfExecuted by msvs-ninja projects when the 'ClCompile' target is used to
    build selected C/C++ files.;c                 V    g | ]%}t           j                            |          d z   &S )z^^)r   rB   r   )r5   r   project_dirs     r   r7   z)WinTool.ExecClCompile.<locals>.<listcomp>D  s>     ( ( ( W\\+x884? ( ( (r   z	ninja.exeT)r_   r   )r   rB   relpathBASE_DIRr4   extendre   r   )r    r   selected_filesninja_targetscmds    `   r   ExecClCompilezWinTool.ExecClCompile?  s     '//+x88K#))#..N( ( ( (&( ( (M-CJJ}?3d9999r   N)__name__
__module____qualname____doc__r%   r   r'   r>   rC   rX   rr   r   r   r   r   r   r   r   r    r   r   r   r   #   s       @ @/ / /6, , ,0 0 0    ! ! !,  <L L L\  < < <  >    ? ? ?	: 	: 	: 	: 	:r   r   __main__r   )r   
__future__r   r   r   rQ   re   rI   stringr   rB   dirnamer   __file__r   compile
IGNORECASEr   r   objectr   r   r	   argvr   r   r   <module>r      s"   
 & % % % % % 				 				        



7??27??84455 BJ2BMBB   e: e: e: e: e:f e: e: e:N	 z
#(44 r   