o
    ´!<fô[  ã                   @   s€  d 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ZzddlZdZeZejZejZejZejZW n2 eyp   zddlZddlZdZeZejZejZejZejZW n eym   e d¡ Y nw Y nw er}ejejejej fZ!d	d
„ Z"dd„ Z#dd„ Z$G dd„ dƒZ%dd„ Z&dd„ Z'dd„ Z(G dd„ de
ƒZ)e&ƒ dkr¾e *d¡ e)Z+ddl,m)Z) ddl,m%Z% dS dS )z‚distutils.msvccompiler

Contains MSVCCompiler, an implementation of the abstract CCompiler class
for the Microsoft Visual Studio.
é    N)ÚDistutilsExecErrorÚDistutilsPlatformErrorÚCompileErrorÚLibErrorÚ	LinkError)Ú	CCompilerÚgen_lib_options)ÚlogFTzWarning: Can't read registry to find the necessary compiler setting
Make sure that Python modules winreg, win32api or win32con are installed.c                 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)ÚbaseÚkeyÚhandleÚLÚiÚk© r   úY/var/www/html/kck/venv/lib/python3.10/site-packages/setuptools/_distutils/msvccompiler.pyÚ	read_keys7   s"   ÿü
úr   c                 C   sz   zt | |ƒ}W n
 ty   Y dS w i }d}	 z
t||ƒ\}}}W n
 ty+   Y |S w | ¡ }t|ƒ|t|ƒ< |d7 }q)zXReturn dict of registry keys and values.

    All names are converted to lowercase.
    Nr   Tr
   )r   r   ÚRegEnumValueÚlowerÚconvert_mbcs)r   r   r   Údr   ÚnameÚvalueÚtyper   r   r   Úread_valuesH   s$   ÿûùr   c                 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   ]   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 | _ |  |¡ d S ©N)ÚmacrosÚload_macros)ÚselfÚversionr   r   r   Ú__init__g   s   zMacroExpander.__init__c                 C   s4   t D ]}t||ƒ}|r|| | jd| <  d S qd S )Nz$(%s))ÚHKEYSr   r(   )r*   ÚmacroÚpathr   r   r   r   r   r   Ú	set_macrok   s   
þþzMacroExpander.set_macroc           
   
   C   sè   d| }|   d|d d¡ |   d|d d¡ d}|   d|d	¡ z|d
kr,|   d|d¡ n|   d|d¡ W n tyD } ztdƒ‚d }~ww d}tD ](}zt||ƒ}W n	 ty[   Y qIw t|dƒ}t|d||f ƒ}	|	d | jd< qId S )Nz%Software\Microsoft\VisualStudio\%0.1fÚVCInstallDirz	\Setup\VCÚ
productdirÚVSInstallDirz	\Setup\VSz Software\Microsoft\.NETFrameworkÚFrameworkDirÚinstallrootg      @ÚFrameworkSDKDirzsdkinstallrootv1.1Úsdkinstallroota  Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible binaries.
Visual Studio 2003 was not found on this system. If you have Cygwin installed,
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.z.Software\Microsoft\NET Framework Setup\Productr   z%s\%sr+   z$(FrameworkVersion))	r0   ÚKeyErrorr   r-   r   r   r   r   r(   )
r*   r+   ÚvsbaseÚnetÚexcÚpr   Úhr   r   r   r   r   r)   r   s6   €ÿ€ÿÿ
ùzMacroExpander.load_macrosc                 C   s$   | j  ¡ D ]
\}}| ||¡}q|S r'   )r(   ÚitemsÚreplace)r*   r$   r   Úvr   r   r   ÚsubŽ   s   zMacroExpander.subN)Ú__name__Ú
__module__Ú__qualname__r,   r0   r)   rA   r   r   r   r   r&   f   s
    r&   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 )zÃReturn 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   r$   ÚrestÚmajorVersionÚminorVersionr   r   r   Úget_build_version“   s   rU   c                  C   s@   d} t j | ¡}|dkrdS t j d|¡}t j|t| ƒ |… S )zUReturn the processor architecture.

    Possible results are "Intel" or "AMD64".
    z bit (rE   ÚIntelú))rL   r+   rM   rN   )rQ   r   Újr   r   r   Úget_build_architecture¬   s   rY   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_pathsr<   Únpr   r   r   Únormalize_and_reduce_paths¹   s   
€r_   c                   @   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„ Z		d,dd„Z		d-dd„Z			d.dd„Z										d/dd„Zdd„ Zdd„ Zd d!„ Zd0d"d#„Zd$d%„ Zd1d'd(„Zd)d*„ ZdS )2Ú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   sv   t  | |||¡ tƒ | _tƒ | _| jdkr.| jdkr$d| _t| jƒ| _nd| _d| j | _	nd| jd  | _	d| _
d S )	NrV   é   zSoftware\Microsoft\VisualStudiozSoftware\Microsoft\DevstudiozVisual Studio version %szMicrosoft SDK compiler %srF   F)r   r,   rU   Ú_MSVCCompiler__versionrY   Ú_MSVCCompiler__archÚ_MSVCCompiler__rootr&   Ú_MSVCCompiler__macrosÚ_MSVCCompiler__productÚinitialized)r*   ÚverboseÚdry_runÚforcer   r   r   r,   æ   s   


zMSVCCompiler.__init__c                 C   sŠ  g | _ dtjv r"dtjv r"|  d¡r"d| _d| _d| _d| _d| _n<|  	d¡| _ t
| j ƒd	kr6td
| j ƒ‚|  d¡| _|  d¡| _|  d¡| _|  d¡| _|  d¡| _|  d¡ |  d¡ ztjd  d¡D ]}| j  |¡ qgW n	 tyz   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r·g d¢| _ng d¢| _dg| _d| _d S )NÚDISTUTILS_USE_SDKÚMSSdkzcl.exezlink.exezlib.exezrc.exezmc.exer/   r   zxPython was built with %s, and extensions need to be built with the same version of the compiler, but it isn't installed.ÚlibÚincludeú;rV   )ú/nologoú/O2ú/MDú/W3ú/GXú/DNDEBUG)rr   ú/Odú/MDdru   rv   ú/Z7ú/D_DEBUG)rr   rs   rt   ru   ú/GS-rw   )rr   rx   ry   ru   r|   rz   r{   )ú/DLLrr   z/INCREMENTAL:NOrc   )r}   rr   ú/INCREMENTAL:noú/DEBUG)r}   rr   r~   z	/pdb:Noner   rr   T)Ú_MSVCCompiler__pathsrZ   ÚenvironÚfind_exeÚccÚlinkerro   ÚrcÚmcÚget_msvc_pathsrN   r   rh   Úset_path_env_varrO   r   r8   r_   ÚjoinÚpreprocess_optionsre   Úcompile_optionsÚcompile_options_debugÚldflags_sharedrd   Úldflags_shared_debugÚldflags_staticri   )r*   r<   r   r   r   Ú
initializeø   sP   ý

ÿÿ







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)rZ   r/   ÚsplitextÚ
splitdriveÚisabsÚsrc_extensionsr   ÚbasenameÚ_rc_extensionsr   r‰   Úres_extensionÚ_mc_extensionsÚobj_extension)r*   Úsource_filenamesÚ	strip_dirÚ
output_dirÚ	obj_namesÚsrc_namer   Úextr   r   r   Úobject_filenames8  s,   

ÿ
ÿÿzMSVCCompiler.object_filenamesNc	                 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 rét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-rrb   z"Don't know how to compile %s to %sz/Fo)ri   r   Ú_setup_compiler   ÚextendrŒ   r‹   r8   rZ   r/   ÚabspathÚ_c_extensionsÚ_cpp_extensionsr—   Úspawnr…   r   r   r™   Údirnamer†   r’   r–   r‰   rƒ   )r*   Úsourcesr   r(   Úinclude_dirsÚdebugÚextra_preargsÚextra_postargsÚdependsÚcompile_infoÚobjectsÚpp_optsÚbuildÚcompile_optsÚobjÚsrcr    Ú	input_optÚ
output_optÚmsgÚh_dirÚrc_dirr   Ú_Úrc_filer   r   r   ÚcompileW  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))ri   r   Ú_fix_object_argsÚlibrary_filenameÚ
_need_linkr§   ro   r   r   r	   r«   )	r*   r°   Úoutput_libnamer   r«   Ú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rU|	rM| jdd … }n| jdd … }n	|	r[| j}n| j}g }|pcg D ]	}| d| ¡ qd|| | | d| g }|d ur¢tj tj |¡¡\}}tj 	tj |d ¡|  |¡¡}| d| ¡ |
rª|
|d d…< |r±| |¡ |  tj |¡¡ z|  | jg| ¡ W d S  tyÖ } zt|ƒ‚d }~ww t d|¡ d S )Nz5I don't know what to do with 'runtime_library_dirs': r
   z/EXPORT:r¾   r   z/IMPLIB:r¿   )ri   r   rÀ   Ú_fix_lib_argsÚwarnÚstrr   rZ   r/   r‰   rÂ   r   Ú
EXECUTABLErŽ   r   r   r’   r–   r¨   rÁ   r£   Ú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_optsÚldflagsÚexport_optsÚsymÚld_argsÚdll_nameÚdll_extÚimplib_filer¸   r   r   r   ÚlinkÅ  sl   ÿ
ÿþ

ÿÿ
ÿþ
€ÿzMSVCCompiler.linkc                 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*   ro   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)rZ   r/   r‰   rÁ   Úexists)r*   Údirsro   r«   Ú	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'.
        ÚPathrq   )r€   rZ   r/   r‰   r¤   Úisfiler   rO   )r*   Úexer<   Úfnr   r   r   r‚   5  s   
	ÿÿzMSVCCompiler.find_exeÚx86c                 C   sÄ   t sg S |d }| jdkrd| j| jf }nd| j|f }tD ]$}t||ƒ}|rC| jdkr:| j || ¡ d¡  S ||  d¡  S q| jdkr`tD ]}t|d| j ƒdur_|  d	¡  g S qKg S )
zÐGet a list of devstudio directories (include, lib or path).

        Return a list of strings.  The list will be empty if unable to
        access the registry or appropriate registry keys not found.
        z dirsrc   z6%s\%0.1f\VC\VC_OBJECTS_PLATFORM_INFO\Win32\Directoriesz?%s\6.0\Build System\Components\Platforms\Win32 (%s)\Directoriesrq   rF   z%s\6.0Nz´It seems you have Visual Studio 6 installed, but the expected registry settings are not present.
You must at least run the Visual Studio GUI once so that these entries are created.)	Ú_can_read_regrd   rf   r-   r   rg   rA   rO   rÉ   )r*   r/   Úplatformr   r   r   r   r   r   r‡   K  s2   

ÿÿ

ü

úzMSVCCompiler.get_msvc_pathsc                 C   s:   |dkr
|   d¡}n|   |¡}|rd |¡tj|< dS dS )z¡Set environment variable 'name' to an MSVC path type value.

        This is equivalent to a SET command prior to execution of spawned
        commands.
        ro   Úlibraryrq   N)r‡   r‰   rZ   r   )r*   r   r<   r   r   r   rˆ   o  s   
ÿzMSVCCompiler.set_path_env_var)r   r   r   )r   r‘   )NNNr   NNN)Nr   N)
NNNNNr   NNNN)r   )rì   )rB   rC   rD   Ú__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‚   r‡   rˆ   r   r   r   r   r`   È   sb    ÿÿ
B
ý 
þX
û
óS

$r`   g       @z3Importing new compiler from distutils.msvc9compiler)r`   )r&   )-rð   rL   rZ   Údistutils.errorsr   r   r   r   r   Údistutils.ccompilerr   r   Ú	distutilsr	   rí   ÚwinregÚhkey_modÚ	OpenKeyExr   ÚEnumKeyr   Ú	EnumValuer   Úerrorr   ÚImportErrorÚwin32apiÚwin32conÚinfoÚ
HKEY_USERSÚHKEY_CURRENT_USERÚHKEY_LOCAL_MACHINEÚHKEY_CLASSES_ROOTr-   r   r   r   r&   rU   rY   r_   r`   r«   ÚOldMSVCCompilerÚdistutils.msvc9compilerr   r   r   r   Ú<module>   sj    



û€õý	-   
9
û