
    dO                         d 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mZ d Zd	 Zd
ddddZd Zd ZddZd
ddddZ G d de          ZdS )a  distutils._msvccompiler

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

The module is compatible with VS 2015 and later. You can find legacy support
for older versions in distutils.msvc9compiler and distutils.msvccompiler.
    N)DistutilsExecErrorDistutilsPlatformErrorCompileErrorLibError	LinkError)	CCompilergen_lib_options)log)get_platform)countc                  j   	 t          j        t           j        dt           j        t           j        z            } n%# t
          $ r t          j        d           Y dS w xY wd}d }| 5  t                      D ]}	 t          j	        | |          \  }}}n# t
          $ r Y  n{w xY w|rt|t           j
        k    rdt          j                            |          rE	 t          t          |                    }n# t           t"          f$ r Y w xY w|dk    r
||k    r||}}d d d            n# 1 swxY w Y   ||fS )Nz'Software\Microsoft\VisualStudio\SxS\VC7)accesszVisual C++ is not registeredNNr      )winreg	OpenKeyExHKEY_LOCAL_MACHINEKEY_READKEY_WOW64_32KEYOSErrorr
   debugr   	EnumValueREG_SZospathisdirintfloat
ValueError	TypeError)keybest_versionbest_dirivvc_dirvtversions           )  /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/distutils/_msvccompiler.py_find_vc2015r*      s   %6?V%;;
 
 

    	0111zz LH	 = = 	= 	=A & 0a 8 8622    =R6=((RW]]6-B-B(!%((mmGG"I.   Hb==W|%;%;-4f(L= = = = = = = = = = = = = = = !!si   8; AA&D&8BD&
B D&B  4D&C21D&2DD&DD&&D*-D*c                     t           j                            d          pt           j                            d          } | sdS 	 t          j        t           j                            | ddd          ddd	d
ddddg	dd                                          }n## t          j        t          t          f$ r Y dS w xY wt           j                            |ddd          }t           j                            |          rd|fS dS )aJ  Returns "15, path" based on the result of invoking vswhere.exe
    If no install is found, returns "None, None"

    The version is returned to avoid unnecessarily changing the function
    result. It may be ignored when the path is not None.

    If vswhere.exe is not available, by definition, VS 2017 is not
    installed.
    zProgramFiles(x86)ProgramFilesr   zMicrosoft Visual Studio	Installerzvswhere.exez-latestz-prereleasez	-requiresz1Microsoft.VisualStudio.Component.VC.Tools.x86.x64z	-propertyinstallationPathz	-products*mbcsstrict)encodingerrorsVC	AuxiliaryBuild   )r   environget
subprocesscheck_outputr   joinstripCalledProcessErrorr   UnicodeDecodeErrorr   )rootr   s     r)   _find_vc2017rA   8   s    :>>-..P"*..2P2PD z
&GLL8+}UUL+(
 8- - - .3UWW 	 )74FG   zz 7<<dK99D	w}}T 4x:s   AB B76B7x86x64armarm64)rB   	x86_amd64x86_arm	x86_arm64c                 .   t                      \  }}|st                      \  }}|st          j        d           dS t          j                            |d          }t          j                            |          st          j        d|           dS |d fS )Nz$No suitable Visual C++ version foundr   zvcvarsall.batz%s cannot be found)rA   r*   r
   r   r   r   r<   isfile)	plat_spec_r#   r"   	vcvarsalls        r)   _find_vcvarsallrN   _   s    ..KAx 0!-h 	8999zX77I7>>)$$ 	&	222zd?    c                 X   t          j        d          r(d t           j                                        D             S t	          |           \  }}|st          d          	 t          j        d                    ||           t          j	                  
                    dd          }nW# t          j        $ rE}t          j        |j                   t          d	                    |j                            d }~ww xY wd
 d |                                D             D             }|S )NDISTUTILS_USE_SDKc                 >    i | ]\  }}|                                 |S  lower).0r!   values      r)   
<dictcomp>z_get_vc_env.<locals>.<dictcomp>s   s6     
 
 
U IIKK
 
 
rO   zUnable to find vcvarsall.batzcmd /u /c "{}" {} && set)stderrzutf-16lereplace)r3   zError executing {}c                 H    i | ]\  }}}||
|                                 | S rS   rT   )rV   r!   rL   rW   s       r)   rX   z_get_vc_env.<locals>.<dictcomp>   sH       CE	 			U  rO   c              3   @   K   | ]}|                     d           V  dS )=N)	partition)rV   lines     r)   	<genexpr>z_get_vc_env.<locals>.<genexpr>   s.      ::		::::::rO   )r   getenvr8   itemsrN   r   r:   r;   formatSTDOUTdecoder>   r
   erroroutputcmd
splitlines)rK   rM   rL   outexcenvs         r)   _get_vc_envrm   q   sS   	y$%% 

 
 j..00
 
 
 	

 #9--LIq E$%CDDD"%&--iCC$
 
 
 &I&
.
. 	 ( " " "	#*$%9" " 	""
  	;:)9)9:::  C Js   !A	B+ +C?:A C::C?c                 6   |s1t          j        d                              t           j                  }|D ]b}t           j                            t           j                            |          |           }t           j                            |          r|c S c| S )at  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'.
    r   )r   ra   splitpathsepr   r<   abspathrJ   )exepathspfns       r)   	_find_exerv      s      4	&!!''
33  W\\"'//!,,c227>>" 	III	JrO   rF   rG   rH   )win32z	win-amd64z	win-arm32z	win-arm64c                        e Zd ZdZdZi ZdgZg dZdgZdgZ	eez   ez   e	z   Z
dZdZd	Zd
ZdxZZdZddZddZ	 	 ddZ	 	 ddZ	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 d dZ fdZd Zd Zd Zd!dZ xZS )"MSVCCompilerzwConcrete class that implements an interface to Microsoft Visual C++,
       as defined by the CCompiler abstract class.msvcz.c)z.ccz.cppz.cxx.rcz.mcz.resz.objz.libz.dllz%s%sz.exer   c                 P    t          j        | |||           d | _        d| _        d S )NF)r   __init__	plat_nameinitialized)selfverbosedry_runforces       r)   r}   zMSVCCompiler.__init__   s.    D'7E::: rO   Nc                 ~   | j         r
J d            |t                      }|t          vr4t          d                    t          t                                        t          |         }t          |          }|st          d          |                    dd          | _        | j        	                    t          j                  }t          d|          | _        t          d|          | _        t          d|          | _        t          d	|          | _        t          d
|          | _        t          d|          | _        |                    dd          	                    t          j                  D ]6}|r2|                     |                    t          j                             7|                    dd          	                    t          j                  D ]6}|r2|                     |                    t          j                             7d | _        g d| _        g d| _        g d}g d}g |d| _        g |d| _        g |ddd| _        g |ddd| _        g || _        g || _        t@          j!        d f| j        t@          j!        df| j        t@          j!        df| j        t@          j"        d f| j        t@          j"        df| j        t@          j"        df| j        t@          j#        d f| j        t@          j#        df| j        t@          j#        df| j        i	| _$        d| _         d S )Nzdon't init multiple timesz--plat-name must be one of {}z7Unable to find a compatible Visual Studio installation.r    cl.exezlink.exezlib.exezrc.exezmc.exezmt.exeincludelib)/nologoz/Ox/W3z/GLz/DNDEBUGz/MD)r   z/Odz/MDdz/Zir   z/D_DEBUG)r   /INCREMENTAL:NO/LTCG)r   r   r   z/DEBUG:FULLz/MANIFEST:EMBED,ID=1z/DLLz/MANIFEST:EMBED,ID=2z/MANIFESTUAC:NOFT)%r   r   PLAT_TO_VCVARSr   rc   tuplerm   r9   _pathsro   r   rp   rv   cclinkerr   rcmcmtadd_include_dirrstripsepadd_library_dirpreprocess_optionscompile_optionscompile_options_debugldflags_exeldflags_exe_debugldflags_sharedldflags_shared_debugldflags_staticldflags_static_debugr   
EXECUTABLESHARED_OBJECTSHARED_LIBRARY_ldflags)r   r~   rK   vc_envrs   dirldflagsldflags_debugs           r)   
initializezMSVCCompiler.initialize   sW   #@@%@@@@$IN**()H*0&~1F1F*G*GI I I #9-	Y'' 	/( *. / / / jj,,!!"*--He,,
E22Y..He,,He,,He,,::i,,222:>> 	9 	9C 9$$SZZ%7%7888::eR((..rz:: 	9 	9C 9$$SZZ%7%7888"& 
  
  
&
 &
 &
"
 
 

 
 
 >W=&<=!I=!I2H!I[[[1G[IZ[$gm$gV$g=S$gUf$g!(j$4m$4! !4($*:!5)4+;!4($*@$d+T-@$e,d.A$d+T-F%t,d.A%u-t/B%t,d.G

  rO   r   c                      i  fd j         D              fd j         j        z   D             pdfd}t          t	          ||                    S )Nc                      i | ]
}|j         S rS   )obj_extensionrV   extr   s     r)   rX   z1MSVCCompiler.object_filenames.<locals>.<dictcomp>"  s    FFF3sD&FFFrO   c                      i | ]
}|j         S rS   )res_extensionr   s     r)   rX   z1MSVCCompiler.object_filenames.<locals>.<dictcomp>#  s    \\\3sD&\\\rO   r   c                    t           j                            |           \  }}r t           j                            |          }nat           j                            |          \  }}|                    t           j        j        t           j        j        f          r
|dd          }	 t           j                            ||         z             S # t          $ r# t          d                    |                     w xY w)N   zDon't know how to compile {})r   r   splitextbasename
splitdrive
startswithr   altsepr<   LookupErrorr   rc   )rt   baser   rL   ext_map
output_dir	strip_dirs       r)   make_out_pathz4MSVCCompiler.object_filenames.<locals>.make_out_path(  s    ((++ID# $w''--',,T224??BGK#@AA $8D	M w||Jws|0CDDD M M M ##A#H#H#K#KLLL	Ms   ((C -C>)src_extensions_rc_extensions_mc_extensionslistmap)r   source_filenamesr   r   r   r   s   ` `` @r)   object_filenameszMSVCCompiler.object_filenames  s    
FFFF$2EFFF
\\\\$2EH[2[\\\

  %2
	M 	M 	M 	M 	M 	M 	M& C'788999rO   c	           	         | j         s|                                  |                     ||||||          }	|	\  }}
}}}|pg }|                    d           |r|                    | j                   n|                    | j                   d}|
D ]}	 ||         \  }}n# t          $ r Y w xY w|rt          j	        
                    |          }g }dt          j        v rPt          j	                            | j                  dk    r(|                    dt          j        d         z              || j        v rd|z   }n|| j        v r	d|z   }d}n|| j        v rO|}d	|z   }	 |                     | j        g|z   ||gz              n!# t&          $ r}t)          |          d }~ww xY w|| j        v rt          j	                            |          }t          j	                            |          }	 |                     | j        d
|d||g           t          j	                            t          j	                            |                    \  }}t          j	                            ||dz             }|                     | j        d	|z   |g           n!# t&          $ r}t)          |          d }~ww xY w*t)          d                    ||                    | j        g|z   |z   |z   }|r|                    d           |                    |           |                    d|z              |                    |           	 |                     |           # t&          $ r}t)          |          d }~ww xY w|
S )Nz/cFSRC_DIRr   z/d1trimfile:z/Tcz/TpTz/foz-hz-rr{   z"Don't know how to compile {} to {}z/EHscz/Fo)r   r   _setup_compileappendextendr   r   KeyErrorr   r   rq   r8   r   r   _c_extensions_cpp_extensionsr   spawnr   r   r   r   dirnamer   r   r<   rc   )r   sourcesr   macrosinclude_dirsr   extra_preargsextra_postargsdependscompile_infoobjectspp_optsbuildcompile_optsadd_cpp_optsobjsrcr   d1trimfile_opts	input_opt
output_optmsgh_dirrc_dirr   rL   rc_fileargss                               r)   compilezMSVCCompiler.compile>  s     	OO**:v|+2G^M M:F7%$*D!!! 	6 :;;;; 4555  H	( H	(C :SS    + gooc**
 !OBJ&&27+;+;DG+D+D+P+P&&~
98M'MNNNd(((!CK		,,,!CK	#+++	"S[
,JJy72j)5LLMMMM) , , ,&s+++,+++ ,,--	,JJudFCHIII g..rw/?/?/E/EFFGD! gll64%<@@GJJg>????) , , ,&s+++, ##G$*F3$4$46 6 6 G9|+g5GD %G$$$KK	"""KK$$$KK'''(

4    % ( ( ("3'''( s[   B""
B/.B/&#F


F(F##F(6B"J
J7#J22J7
M!!
M?+M::M?c                    | j         s|                                  |                     ||          \  }}|                     ||          }|                     ||          r||d|z   gz   }|r	 	 t          j        d| j        d                    |                     | 	                    | j        g|z              d S # t          $ r}t          |          d }~ww xY wt          j        d|           d S )N)r   /OUT:Executing "%s" %s skipping %s (up-to-date))r   r   _fix_object_argslibrary_filename
_need_linkr
   r   r   r<   r   r   r   )	r   r   output_libnamer   r   target_langoutput_filenamelib_argsr   s	            r)   create_static_libzMSVCCompiler.create_static_lib  s     	OO"33GZHH//;E 0 G G ??7O44 
	C'O";!<<H $	-tx(9K9KLLL

DH:011111% $ $ $smm#$ I0/BBBBBs   /AB= =
CCCc                 8   | j         s|                                  |                     ||          \  }}|                     |||          }|\  }}}|r%|                     dt          |          z              t          | |||          }| t          j        	                    ||          }| 
                    ||          r| j        ||	f         }d |pg D             }||z   |z   |z   d|z   gz   }t          j                            |d                   }|t          j                            t          j                            |                    \  }}t          j        	                    ||                     |                    }|                    d|z              |
r|
|d d<   |r|                    |           t          j                            t          j                            |                    }|                     |           	 t)          j        d| j        d	                    |                     |                     | j        g|z              d S # t0          $ r}t3          |          d }~ww xY wt)          j        d|           d S )	Nz5I don't know what to do with 'runtime_library_dirs': c                     g | ]}d |z   S )z/EXPORT:rS   )rV   syms     r)   
<listcomp>z%MSVCCompiler.link.<locals>.<listcomp>  s    NNN:+NNNrO   r   r   z/IMPLIB:r   r   r   )r   r   r   _fix_lib_argswarnstrr	   r   r   r<   r   r   r   r   r   r   r   r   rq   mkpathr
   r   r   r   r   r   )r   target_descr   r   r   	librarieslibrary_dirsruntime_library_dirsexport_symbolsr   r   r   
build_tempr   
fixed_argslib_optsr   export_optsld_argsdll_namedll_extimplib_filer   s                          r)   linkzMSVCCompiler.link  s     	OO"33GZHH''	<(<> >
8B5	<!5 	4IIM1223 4 4 4 #4#/1E#,. . ! gll:GGO??7O44 #	CmK$67GNN8L"NNNK)K7")O";!<=G 44J)&(g&6&6G$$_55'7 '7#7 gll))(335 5 
[ 8999 ,+ /~...)I)IJJJKK
###%	-t{CHHW<M<MNNN

DK=7233333% % % %nn$% I0/BBBBBs   AI$ $
J.I==Jc                     t          j        d          }	 | j        t           j        d<   t	                                          |          |t           j        d<   S # |t           j        d<   w xY w)Nr   )r   ra   r   r8   superr   )r   rh   old_path	__class__s      r)   r   zMSVCCompiler.spawn  s_    9V$$	*!%BJv77==%%!)BJvBJv))))s   4A A,c                     d|z   S )Nz	/LIBPATH:rS   r   r   s     r)   library_dir_optionzMSVCCompiler.library_dir_option
  s    S  rO   c                      t          d          )Nz:don't know how to set runtime library search path for MSVC)r   r  s     r)   runtime_library_dir_optionz'MSVCCompiler.runtime_library_dir_option  s    $JL L 	LrO   c                 ,    |                      |          S N)r   )r   r   s     r)   library_optionzMSVCCompiler.library_option  s    $$S)))rO   c                     |r|dz   |g}n|g}|D ]_}|D ]Z}t           j                            ||                     |                    }t           j                            |          r|c c S [`d S )N_d)r   r   r<   r   rJ   )r   dirsr   r   	try_namesr   namelibfiles           r)   find_library_filezMSVCCompiler.find_library_file  s      	tS)III 	 	C! # #',,sD,A,A$,G,GHH7>>'** #"NNNNN## 4rO   )r   r   r   r  )r   r   )NNNr   NNN)Nr   N)
NNNNNr   NNNN)r   )__name__
__module____qualname____doc__compiler_typeexecutablesr   r   r   r   r   r   r   static_lib_extensionshared_lib_extensionstatic_lib_formatshared_lib_formatexe_extensionr}   r   r   r   r   r	  r   r  r  r  r  __classcell__)r  s   @r)   ry   ry      s       6 6 M K FM---OWNWN $o5$%'56NMM!!,22)M! ! ! !J  J  J  J ` $%$&: : : :D HIAE^ ^ ^ ^H &* !&*C C C C< "&  CC CC CC CCJ* * * * *! ! !L L L* * *       rO   ry   r  )r   r   r:   r   distutils.errorsr   r   r   r   r   distutils.ccompilerr   r	   	distutilsr
   distutils.utilr   	itertoolsr   r*   rA   PLAT_SPEC_TO_RUNTIMErN   rm   rv   r   ry   rS   rO   r)   <module>r/     s    
			     ? ? ? ? ? ? ? ? ? ? ? ? ? ? : : : : : : : :       ' ' ' ' ' '      " " "8  B 	    $  <   * 	 x x x x x9 x x x x xrO   