o
    Ee\                     @   s  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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yt   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yq   ed	 Y nw Y nw erejejej ej!fZ"e#d
e$ 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re-d e,Z.ddl/m,Z, ddl/m(Z( dS dS )zdistutils.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.zmsvccompiler is deprecated and slated to be removed in the future. Please discontinue use or file an issue with pypa/distutils describing your use case.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   Tr   )RegOpenKeyExRegError
RegEnumKeyappend)basekeyhandleLik r   c/var/www/bmteknikk.ddns.net/venv/lib/python3.10/site-packages/setuptools/_distutils/msvccompiler.py	read_keysJ   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_values\   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   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__}   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_macro   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y?   tdw d}tD ](}zt||}W n	 tyV   Y qDw t|d}t|d||}|d | j	d< qDd 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{}\{}r+   z$(FrameworkVersion))
r0   KeyErrorr   r-   r   r   r   r   formatr(   )	r*   r+   vsbasenetpr   hr   r   r   r   r   r)      s4   
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&   |   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 )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   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+ f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  ZS )2MSVCCompilerztConcrete 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                    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)superr,   rU   _MSVCCompiler__versionrY   _MSVCCompiler__arch_MSVCCompiler__rootr&   _MSVCCompiler__macros_MSVCCompiler__productinitialized)r*   verbosedry_runforce	__class__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rg 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)ru   /Od/MDdrx   ry   /Z7/D_DEBUG)ru   rv   rw   rx   /GS-rz   )ru   r{   r|   rx   r   r}   r~   )/DLLru   z/INCREMENTAL:NOrc   )r   ru   /INCREMENTAL:no/DEBUG)r   ru   r   z	/pdb:Noner   ru   T)_MSVCCompiler__pathsrZ   environfind_execclinkerrr   rcmcget_msvc_pathsrN   r   ri   set_path_env_varrO   r   r8   r_   joinpreprocess_optionsrf   compile_optionscompile_options_debugldflags_sharedre   ldflags_shared_debugldflags_staticrj   )r*   r<   r   r   r   
initialize  sZ   












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_filenamesd  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 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||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 {} to {}z/Fo)rj   r   _setup_compiler   extendr   r   r8   rZ   r/   abspath_c_extensions_cpp_extensionsr   spawnr   r   r   r   dirnamer   r   r   r   r9   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   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))rj   r   _fix_object_argslibrary_filename
_need_linkr   rr   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rt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   )rj   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  s^   

	

zMSVCCompiler.linkc                 C   s   d| S )Nz	/LIBPATH:r   r*   dirr   r   r   library_dir_optionB  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_optionE  s   z'MSVCCompiler.runtime_library_dir_optionc                 C   s
   |  |S r'   )r   )r*   rr   r   r   r   library_optionJ  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*   dirsrr   r   	try_namesr   r   libfiler   r   r   find_library_fileM  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'.
        Pathrt   )r   rZ   r/   r   r   isfiler   rO   )r*   exer<   fnr   r   r   r   _  s   
	zMSVCCompiler.find_exex86c                 C   s   t sg S |d }| jdkrd| j| j}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 )
zGet 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   z8{}\{:0.1f}\VC\VC_OBJECTS_PLATFORM_INFO\Win32\Directoriesz?%s\6.0\Build System\Components\Platforms\Win32 (%s)\Directoriesrt   rF   z%s\6.0NzIt 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_regre   r9   rg   r-   r   rh   rA   rO   r   )r*   r/   platformr   r   r   r   r   r   r   u  s:   



zMSVCCompiler.get_msvc_pathsc                 C   s:   |dkr
|  d}n|  |}|rd|tj|< dS dS )zSet environment variable 'name' to an MSVC path type value.

        This is equivalent to a SET command prior to execution of spawned
        commands.
        rr   libraryrt   N)r   r   rZ   r   )r*   r   r<   r   r   r   r     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   __classcell__r   r   rn   r   r`      s\    
S
_

T

*r`   g       @z3Importing new compiler from distutils.msvc9compiler)r`   )r&   )0r   rL   rZ   warningserrorsr   r   r   r   r   	ccompilerr   r	   _logr
   r   winreghkey_mod	OpenKeyExr   EnumKeyr   	EnumValuer   errorr   ImportErrorwin32apiwin32coninfo
HKEY_USERSHKEY_CURRENT_USERHKEY_LOCAL_MACHINEHKEY_CLASSES_ROOTr-   r   DeprecationWarningr   r   r   r&   rU   rY   r_   r`   r   OldMSVCCompilerdistutils.msvc9compilerr   r   r   r   <module>   sz    



/   
O
