o ?Og[ @sdZddlZddlZddlmZmZmZmZmZddl m Z m Z ddl m Z dZzddlZdZeZejZejZejZejZWn2eypzddlZddlZdZeZejZejZejZejZWneyme dYnwYnwer}ejejejej fZ!d d Z"d d Z#d dZ$GdddZ%ddZ&ddZ'ddZ(Gddde Z)e&dkre *de)Z+ddl,m)Z)ddl,m%Z%dSdS)zdistutils.msvccompiler Contains MSVCCompiler, an implementation of the abstract CCompiler class for the Microsoft Visual Studio. N)DistutilsExecErrorDistutilsPlatformError CompileErrorLibError LinkError) CCompilergen_lib_options)logFTzWarning: Can't read registry to find the necessary compiler setting Make sure that Python modules winreg, win32api or win32con are installed.cCsfzt||}Wn tyYdSwg}d} zt||}Wn ty(Y|Sw|||d7}q)zReturn list of registry keys.NrT) RegOpenKeyExRegError RegEnumKeyappend)basekeyhandleLikr=/opt/alt/python310/lib64/python3.10/distutils/msvccompiler.py read_keys7s"   rcCszzt||}Wn tyYdSwi}d} z t||\}}}Wn ty+Y|Sw|}t||t|<|d7}q)zXReturn dict of registry keys and values. All names are converted to lowercase. NrTr )r r RegEnumValuelower convert_mbcs)rrrdrnamevaluetyperrr read_valuesHs$  rcCs<t|dd}|durz|d}W|StyY|Sw|S)Ndecodembcs)getattr UnicodeError)sZdecrrrr]s   rc@s,eZdZddZddZddZddZd S) MacroExpandercCsi|_||dSN)macros load_macros)selfversionrrr__init__gszMacroExpander.__init__cCs4tD]}t||}|r|||jd|<dSqdS)Nz$(%s))HKEYSrr')r)Zmacropathrrrrrr set_macroks zMacroExpander.set_macroc Csd|}|d|dd|d|ddd}|d|d z|d kr,|d |d n|d |d WntyD}ztdd}~wwd}tD](}zt||}Wn ty[YqIwt|d}t|d||f} | d|jd<qIdS)Nz%Software\Microsoft\VisualStudio\%0.1fZ VCInstallDirz \Setup\VCZ productdirZ VSInstallDirz \Setup\VSz Software\Microsoft\.NETFrameworkZ FrameworkDirZ installrootg@ZFrameworkSDKDirzsdkinstallrootv1.1ZsdkinstallrootaPython 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\Productrz%s\%sr*z$(FrameworkVersion)) r.KeyErrorrr,r r r rr') r)r*ZvsbaseZnetexcprhrrrrrr(rs6  zMacroExpander.load_macroscCs$|jD] \}}|||}q|Sr&)r'itemsreplace)r)r$rvrrrsubszMacroExpander.subN)__name__ __module__ __qualname__r+r.r(r6rrrrr%fs  r%cCsd}tj|}|dkrdS|t|}tj|ddd\}}t|ddd}|dkr3|d7}t|d d d }|dkrCd }|dkrK||SdS) 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. zMSC v.N r g$@r)sysr*findlensplitint)prefixrr$restZ majorVersionZ minorVersionrrrget_build_versions  rHcCs@d}tj|}|dkrdStjd|}tj|t||S)zUReturn the processor architecture. Possible results are "Intel" or "AMD64". z bit (r:Intel))rAr*rBrC)rFrjrrrget_build_architectures  rLcCs0g}|D]}tj|}||vr||q|S)znReturn a list of normalized paths with duplicates removed. The current order of paths is maintained. )osr-normpathr)pathsZ reduced_pathsr1Znprrrnormalize_and_reduce_pathss  rPc@seZdZdZdZiZdgZgdZdgZdgZ eeee Z dZ dZ d Z d Zd ZZd Zd+ddZddZ d,ddZ d-ddZ  d.ddZ         d/ddZddZddZd d!Zd0d"d#Zd$d%Zd1d'd(Zd)d*ZdS)2 MSVCCompilerzwConcrete class that implements an interface to Microsoft Visual C++, as defined by the CCompiler abstract class.Zmsvcz.c)z.ccz.cppz.cxx.rcz.mcz.resz.objz.libz.dllz%s%sz.exercCsvt||||t|_t|_|jdkr.|jdkr$d|_t|j|_nd|_d|j|_ nd|jd|_ d|_ dS) NrIzSoftware\Microsoft\VisualStudiozSoftware\Microsoft\DevstudiozVisual Studio version %szMicrosoft SDK compiler %sr;F) rr+rH_MSVCCompiler__versionrL_MSVCCompiler__arch_MSVCCompiler__rootr%_MSVCCompiler__macros_MSVCCompiler__product initialized)r)verboseZdry_runZforcerrrr+s   zMSVCCompiler.__init__cCsg|_dtjvr"dtjvr"|dr"d|_d|_d|_d|_d|_n<| d|_t |jd kr6t d |j |d|_|d|_|d|_|d|_|d|_| d | d ztjdd D]}|j|qgWn tyzYnwt|j|_d |jtjd<d|_|jdkrgd|_gd|_n gd|_gd|_gd|_|jdkrgd|_ngd|_dg|_d|_dS)NZDISTUTILS_USE_SDKZMSSdkzcl.exezlink.exezlib.exezrc.exezmc.exer-rzxPython was built with %s, and extensions need to be built with the same version of the compiler, but it isn't installed.libZinclude;rI)/nologo/Ox/MD/W3/GX/DNDEBUG)r]/Od/MDdr`ra/Z7/D_DEBUG)r]r^r_r`/GS-rb)r]rcrdr`rgrerf)/DLLr]z/INCREMENTAL:NOrS)rhr]/INCREMENTAL:no/DEBUG)rhr]riz /pdb:Nonerjr]T)_MSVCCompiler__pathsrMenvironfind_execclinkerr[rcmcget_msvc_pathsrCrrXset_path_env_varrDrr/rPjoinZpreprocess_optionsrUcompile_optionscompile_options_debugldflags_sharedrTldflags_shared_debugZldflags_staticrY)r)r1rrr initializesP                    zMSVCCompiler.initializecCs|durd}g}|D]b}tj|\}}tj|d}|tj|d}||jvr1td||r9tj|}||jvrL| tj |||j q ||j vr_| tj |||j q | tj |||j q |S)Nrzr zDon't know how to compile %s)rMr-splitext splitdriveisabssrc_extensionsrbasename_rc_extensionsrrt res_extension_mc_extensions obj_extension)r)Zsource_filenamesZ strip_dir output_dirZ obj_namesZsrc_namerextrrrobject_filenames8s,         zMSVCCompiler.object_filenamesNc  Cs8|js||||||||} | \}} }} } |pg} | d|r*| |jn| |j| D]}z| |\}}Wn tyEYq2w|rNtj |}||j vrXd|}n||j vrbd|}n||j vr|}d|}z||jg| |g|gWnty}zt|d}~wwq2||jvrtj |}tj |}z6||jgd|d|g|gtj tj |\}}tj ||d}||jgd|g|gWnty}zt|d}~wwq2td||fd |}z||jg| | ||g|Wq2ty}zt|d}~ww| S) Nz/cz/Tcz/Tpz/foz-hz-rrRz"Don't know how to compile %s to %sz/Fo)rYryZ_setup_compilerextendrvrur/rMr-abspath _c_extensions_cpp_extensionsrspawnrprrrdirnamerqr{rrtrn)r)Zsourcesrr'Z include_dirsdebug extra_preargsextra_postargsZdependsZ compile_infoobjectsZpp_optsZbuildZ compile_optsobjsrcrZ input_optZ output_optmsgZh_dirZrc_dirr_Zrc_filerrrcompileWs                  zMSVCCompiler.compilec Cs|js||||\}}|j||d}|||rC|d|g}|r& z ||jg|WdStyB}zt|d}~wwt d|dS)N)r/OUT:skipping %s (up-to-date)) rYry_fix_object_argslibrary_filename _need_linkrr[rrr r) r)rZoutput_libnamerr target_langoutput_filenameZlib_argsrrrrcreate_static_libs" zMSVCCompiler.create_static_libc Cs|js||||\}}||||}|\}}}|r&|dt|t||||}|dur8tj ||}| ||r|t j krU| rM|j dd}n|jdd}n | r[|j }n|j}g}|pcgD] }|d|qd||||d|g}|durtjtj|\}}tj tj|d||}|d|| r| |dd<| r|| |tj|z ||jg|WdSty}zt|d}~wwtd|dS)Nz5I don't know what to do with 'runtime_library_dirs': r z/EXPORT:rrz/IMPLIB:r)rYryrZ _fix_lib_argswarnstrrrMr-rtrrZ EXECUTABLErxrwrr{rrrrZmkpathrrorrr r)r)Z target_descrrrZ librariesZ library_dirsZruntime_library_dirsZexport_symbolsrrrZ build_temprZ fixed_argsZlib_optsZldflagsZ export_optsZsymZld_argsZdll_nameZdll_extZ implib_filerrrrlinksl        zMSVCCompiler.linkcCsd|S)Nz /LIBPATH:rr)dirrrrlibrary_dir_optionszMSVCCompiler.library_dir_optioncCstd)Nzsj        -  9