o
    ugv                     @   sL  d Z ddl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ZejZejZejZejZejejejejfZej dkoWej!dkZ"e"rad	Z#d
Z$dZ%ndZ#dZ$dZ%dddZ&G dd dZ'G dd dZ(dd Z)dd Z*dd Z+dd Z,d$ddZ-e) Z.e.d k red!e. G d"d# d#eZ/dS )%a  distutils.msvc9compiler

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

The module is compatible with VS 2005 and VS 2008. You can find legacy support
for older versions of VS in distutils.msvccompiler.
    N)DistutilsExecErrorDistutilsPlatformErrorCompileErrorLibError	LinkError)	CCompilergen_lib_options)log)get_platformwin32l        z1Software\Wow6432Node\Microsoft\VisualStudio\%0.1fz5Software\Wow6432Node\Microsoft\Microsoft SDKs\Windowsz,Software\Wow6432Node\Microsoft\.NETFrameworkz%Software\Microsoft\VisualStudio\%0.1fz)Software\Microsoft\Microsoft SDKs\Windowsz Software\Microsoft\.NETFrameworkx86amd64r   z	win-amd64c                   @   sP   e Zd ZdZdd ZeeZdd ZeeZdd ZeeZdd	 Ze	eZd
S )Regz2Helper class to read values from the registry
    c                 C   s6   t D ]}| ||}|r||v r||   S qt|N)HKEYSread_valuesKeyError)clspathkeybased r   e/var/www/html/ecg_monitoring/venv/lib/python3.10/site-packages/setuptools/_distutils/msvc9compiler.py	get_value?   s   zReg.get_valuec                 C   sf   zt ||}W n
 ty   Y dS w g }d}	 zt||}W n
 ty(   Y |S w || |d7 }q)zReturn list of registry keys.Nr   T   )RegOpenKeyExRegError
RegEnumKeyappend)r   r   r   handleLikr   r   r   	read_keysG   s"   
zReg.read_keysc           	      C   s~   zt ||}W n
 ty   Y dS w i }d}	 z
t||\}}}W n
 ty+   Y |S w | }| ||| |< |d7 }q)z`Return dict of registry keys and values.

        All names are converted to lowercase.
        Nr   Tr   )r   r   RegEnumValuelowerconvert_mbcs)	r   r   r   r!   r   r#   namevaluetyper   r   r   r   Y   s$   zReg.read_valuesc                 C   s<   t | dd }|d urz|d} W | S  ty   Y | S w | S )Ndecodembcs)getattrUnicodeError)sdecr   r   r   r(   o   s   
zReg.convert_mbcsN)
__name__
__module____qualname____doc__r   classmethodr%   r   r(   staticmethodr   r   r   r   r   ;   s    r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
MacroExpanderc                 C   s   i | _ t| | _| | d S r   )macrosVS_BASEvsbaseload_macros)selfversionr   r   r   __init__{   s   
zMacroExpander.__init__c                 C   s   t ||| jd| < d S )Nz$(%s))r   r   r9   )r=   macror   r   r   r   r   	set_macro   s   zMacroExpander.set_macroc              	   C   s   |  d| jd d |  d| jd d |  dtd z|dkr(|  d	td
 ntd
W n ty8   tdw |dkrN|  d| jd |  dtd d S d}tD ])}zt||}W n	 tyd   Y qRw t	|d}t
|d||f }|d | jd< qRd S )NVCInstallDirz	\Setup\VC
productdirVSInstallDirz	\Setup\VSFrameworkDirinstallroot       @FrameworkSDKDirzsdkinstallrootv2.0a  Python was built with Visual Studio 2008;
extensions must be built with a compiler than can generate compatible binaries.
Visual Studio 2008 was not found on this system. If you have Cygwin installed,
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.g      "@FrameworkVersionzclr versionWindowsSdkDircurrentinstallfolderz.Software\Microsoft\NET Framework Setup\Productr   z%s\%sr>   z$(FrameworkVersion))rA   r;   NET_BASEr   r   WINSDK_BASEr   r   r   r   r   r   r9   )r=   r>   pr   hr   r   r   r   r   r<      s:   
zMacroExpander.load_macrosc                 C   s$   | j  D ]
\}}|||}q|S r   )r9   itemsreplace)r=   r0   r$   vr   r   r   sub   s   zMacroExpander.subN)r2   r3   r4   r?   rA   r<   rS   r   r   r   r   r8   y   s
    r8   c                  C   s   d} t j| }|dkrdS |t|  }t j|d dd\}}t|dd d }|dkr3|d7 }t|d	d
 d }|dkrCd}|dkrK|| S dS )zReturn the version of MSVC that was used to build Python.

    For Python 2.3 and up, the version number is included in
    sys.version.  For earlier versions, assume the compiler is MSVC 6.
    zMSC v.   N r            g      $@r   )sysr>   findlensplitint)prefixr#   r0   restmajorVersionminorVersionr   r   r   get_build_version   s   rd   c                 C   s0   g }| D ]}t j|}||vr|| q|S )znReturn a list of normalized paths with duplicates removed.

    The current order of paths is maintained.
    )osr   normpathr    )pathsreduced_pathsrN   npr   r   r   normalize_and_reduce_paths   s   
rj   c                 C   s<   |  tj}g }|D ]}||vr|| q
tj|}|S )z8Remove duplicate values of an environment variable.
    )r^   re   pathsepr    join)variableoldListnewListr#   newVariabler   r   r   removeDuplicates   s   
rq   c                 C   s  t |  }z
td| d}W n ty   td d}Y nw |r'tj|sbd|  }tj	
|d}|r[tj|r[tj|tjtjd}tj|}tj|sZtd|  dS ntd|  |sktd	 dS tj|d
}tj|rz|S td dS )zFind the vcvarsall.bat file

    At first it tries to find the productdir of VS 2008 in the registry. If
    that fails it falls back to the VS90COMNTOOLS env var.
    z%s\Setup\VCrC   z%Unable to find productdir in registryNzVS%0.f0COMNTOOLSVCz%s is not a valid directoryz Env var %s is not set or invalidzNo productdir foundzvcvarsall.batUnable to find vcvarsall.bat)r:   r   r   r   r	   debugre   r   isdirenvirongetrl   pardirabspathisfile)r>   r;   rC   toolskeytoolsdir	vcvarsallr   r   r   find_vcvarsall   s8   



r~   c                 C   sF  t | }h d}i }|du rtdtd||  tjd||f tjtjd}z\| \}}| dkr;t|	d|	d}|
d	D ]2}t|}d
|vrQqE| }|
d
d\}	}
|	 }	|	|v rw|
tjrq|
dd }
t|
||	< qEW |j  |j  n|j  |j  w t|t|krttt| |S )zDLaunch vcvarsall.bat and read the settings from its environment
    >   libr   includelibpathNrs   z'Calling 'vcvarsall.bat %s' (version=%s)z"%s" %s & set)stdoutstderrr   r-   
=r   rT   )r~   r   r	   rt   
subprocessPopenPIPEcommunicatewaitr,   r^   r   r(   stripr'   endswithre   rk   rq   r   closer   r]   
ValueErrorstrlistkeys)r>   archr}   interestingresultpopenr   r   liner   r*   r   r   r   query_vcvarsall   sF   



r   rG   z(VC %0.1f is not supported by this modulec                   @   s   e Zd ZdZdZi ZdgZg dZdgZdgZ	ee e e	 Z
dZdZd	Zd
Zd ZZdZd,ddZd-ddZ		d.ddZ		d/ddZ			d0ddZ										d1ddZdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd2d(d)Zd*d+ ZdS )3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                 C   s8   t | ||| t| _d| _g | _d | _d | _d| _d S )NzSoftware\Microsoft\VisualStudioF)	r   r?   VERSION_MSVCCompiler__version_MSVCCompiler__root_MSVCCompiler__paths	plat_name_MSVCCompiler__archinitialized)r=   verbosedry_runforcer   r   r   r?   H  s   
zMSVCCompiler.__init__Nc                 C   s  | j rJ d|d u rt }d}||vrtd|f dtjv r:dtjv r:| dr:d| _d| _d| _d	| _	d
| _
na|t ksC|dkrHt| }ntt  d t|  }tt|}|d tj| _|d tjd< |d tjd< t| jdkr}td| j | d| _| d| _| d| _| d	| _	| d
| _
ztjd dD ]}| j| qW n	 ty   Y nw t| j| _d| jtjd< d | _| jdkrg d| _g d| _n
g d| _g d| _g d| _| jdkrg d| _dg| _d| _ d S )Nzdon't init multiple timesr   z--plat-name must be one of %sDISTUTILS_USE_SDKMSSdkzcl.exezlink.exezlib.exezrc.exezmc.exer   _r   r   r   r   zxPython was built with %s, and extensions need to be built with the same version of the compiler, but it isn't installed.;r   )/nologo/O2/MD/W3/DNDEBUG)r   /Od/MDdr   /Z7/D_DEBUG)r   r   r   r   /GS-r   )r   r   r   r   r   r   r   )/DLLr   z/INCREMENTAL:NO   )r   r   z/INCREMENTAL:noz/DEBUGr   T)r   r
   r   re   rv   find_execclinkerr   rcmcPLAT_TO_VCVARSr   r   r^   rk   r   r]   _MSVCCompiler__productr    r   rj   rl   preprocess_optionsr   compile_optionscompile_options_debugldflags_sharedr   ldflags_shared_debugldflags_static)r=   r   ok_plats	plat_specvc_envrN   r   r   r   
initializeS  sh   









zMSVCCompiler.initialize c                 C   s   |d u rd}g }|D ]b}t j|\}}t j|d }|t j|d  }|| jvr1td| |r9t j|}|| jv rL|	t j
||| j  q
|| jv r_|	t j
||| j  q
|	t j
||| j  q
|S )Nr   r   zDon't know how to compile %s)re   r   splitext
splitdriveisabssrc_extensionsr   basename_rc_extensionsr    rl   res_extension_mc_extensionsobj_extension)r=   source_filenames	strip_dir
output_dir	obj_namessrc_namer   extr   r   r   object_filenames  s,   


zMSVCCompiler.object_filenamesc	                 C   s8  | j s|   | ||||||}	|	\}}
}}}|pg }|d |r*|| j n|| j |
D ]}z|| \}}W n	 tyE   Y q2w |rNtj	
|}|| jv rXd| }n|| jv rbd| }n|| jv r|}d| }z| | jg| |g |g  W n ty } zt|d }~ww q2|| jv rtj	|}tj	|}z6| | jgd|d|g |g  tj	tj	|\}}tj	||d }| | jgd| g |g  W n ty } zt|d }~ww q2td||f d	| }z| | jg| | ||g |  W q2 ty } zt|d }~ww |
S )
Nz/cz/Tcz/Tpz/foz-hz-rr   z"Don't know how to compile %s to %sz/Fo)r   r   _setup_compiler    extendr   r   r   re   r   ry   _c_extensions_cpp_extensionsr   spawnr   r   r   r   dirnamer   r   r   rl   r   )r=   sourcesr   r9   include_dirsrt   extra_preargsextra_postargsdependscompile_infoobjectspp_optsbuildcompile_optsobjsrcr   	input_opt
output_optmsgh_dirrc_dirr   r   rc_filer   r   r   compile  s   













zMSVCCompiler.compilec           	   
   C   s   | j s|   | ||\}}| j||d}| ||rC|d| g }|r&	 z| | jg|  W d S  tyB } zt|d }~ww t	
d| d S )N)r   /OUT:skipping %s (up-to-date))r   r   _fix_object_argslibrary_filename
_need_linkr   r   r   r   r	   rt   )	r=   r   output_libnamer   rt   target_langoutput_filenamelib_argsr   r   r   r   create_static_lib  s"   zMSVCCompiler.create_static_libc              
   C   s<  | j s|   | ||\}}| |||}|\}}}|r&| dt|  t| |||}|d ur8tj	||}| 
||r|tjkrV|	rN| jdd  }n| jdd  }n	|	r\| j}n| j}g }|pdg D ]	}|d|  qe|| | | d| g }tj|d }|d urtjtj|\}}tj	|| |}|d|  | ||| |
r|
|d d< |r|| | tj| z| | jg|  W n ty } zt|d }~ww | ||}|d ur|\}}d||f }z| dd	d
||g W d S  ty } zt|d }~ww d S td| d S )Nz5I don't know what to do with 'runtime_library_dirs': r   z/EXPORT:r   r   z/IMPLIB:z-outputresource:%s;%szmt.exez-nologoz	-manifestr   )r   r   r   _fix_lib_argswarnr   r   re   r   rl   r   r   
EXECUTABLEr   r   r    r   r   r   r   manifest_setup_ldargsr   mkpathr   r   r   r   manifest_get_embed_infor	   rt   )r=   target_descr   r   r   	librarieslibrary_dirsruntime_library_dirsexport_symbolsrt   r   r   
build_tempr   
fixed_argslib_optsldflagsexport_optssymld_argsdll_namedll_extimplib_filer   mfinfo
mffilenamemfidout_argr   r   r   link5  s   






	zMSVCCompiler.linkc                 C   s,   t j|t j|d }|d|  d S )Nz	.manifest/MANIFESTFILE:)re   r   rl   r   r    )r=   r   r  r  temp_manifestr   r   r   r     s
   z"MSVCCompiler.manifest_setup_ldargsc                 C   s^   |D ]}| dr|ddd } nqd S |tjkrd}nd}| |}|d u r+d S ||fS )Nr  :r   rY   )
startswithr^   r   r   _remove_visual_c_ref)r=   r   r  argr  r  r   r   r   r     s   


z$MSVCCompiler.manifest_get_embed_infoc                 C   s   zUt |}z
| }W |  n|  w tdtj}t|d|}d}t|d|}tdtj}t||d u r>W d S t |d}z|| |W |  W S |  w  t	y_   Y d S w )NzU<assemblyIdentity.*?name=("|')Microsoft\.VC\d{2}\.CRT("|').*?(/>|</assemblyIdentity>)r   z*<dependentAssembly>\s*</dependentAssembly>zI<assemblyIdentity.*?name=(?:"|')(.+?)(?:"|').*?(?:/>|</assemblyIdentity>)w)
openreadr   rer   DOTALLrS   searchwriteOSError)r=   manifest_file
manifest_fmanifest_bufpatternr   r   r   r    s4   	


z!MSVCCompiler._remove_visual_c_refc                 C   s   d| S )Nz	/LIBPATH:r   r=   dirr   r   r   library_dir_option  s   zMSVCCompiler.library_dir_optionc                 C   s   t d)Nz<don't know how to set runtime library search path for MSVC++)r   r&  r   r   r   runtime_library_dir_option  s   z'MSVCCompiler.runtime_library_dir_optionc                 C   s
   |  |S r   )r   )r=   r   r   r   r   library_option  s   
zMSVCCompiler.library_optionc                 C   s\   |r	|d |g}n|g}|D ]}|D ]}t j|| |}t j|r*|    S qqd S )N_d)re   r   rl   r   exists)r=   dirsr   rt   	try_namesr'  r)   libfiler   r   r   find_library_file  s   zMSVCCompiler.find_library_filec                 C   sz   | j D ]}tjtj||}tj|r|  S qtjd dD ]}tjtj||}tj|r:|  S q#|S )a  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'.
        Pathr   )r   re   r   rl   ry   rz   rv   r^   )r=   exerN   fnr   r   r   r      s   
	zMSVCCompiler.find_exe)r   r   r   r   )r   r   )NNNr   NNN)Nr   N)
NNNNNr   NNNN)r   ) r2   r3   r4   r5   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)  r*  r0  r   r   r   r   r   r   *  sd    

W
 
X

_+
r   )r   )0r5   re   r   r[   r  distutils.errorsr   r   r   r   r   distutils.ccompilerr   r   	distutilsr	   distutils.utilr
   winreg	OpenKeyExr   EnumKeyr   	EnumValuer&   errorr   
HKEY_USERSHKEY_CURRENT_USERHKEY_LOCAL_MACHINEHKEY_CLASSES_ROOTr   platformmaxsizeNATIVE_WIN64r:   rM   rL   r   r   r8   rd   rj   rq   r~   r   r   r   r   r   r   r   <module>   sR    >.
#)