o bc[ @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-/usr/lib/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)sdecrrrr]s   rc@s,eZdZddZddZddZddZd S) MacroExpandercCsi|_||dSN)macros load_macros)selfversionrrr__init__gszMacroExpander.__init__cCs4tD]}t||}|r|||jd|<dSqdS)Nz$(%s))HKEYSrr()r*macropathrrrrrr 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.1f VCInstallDirz \Setup\VC productdir VSInstallDirz \Setup\VSz Software\Microsoft\.NETFramework FrameworkDir installrootg@FrameworkSDKDirzsdkinstallrootv1.1sdkinstallrootaPython 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)) r0KeyErrorrr-r r r rr() r*r+vsbasenetexcprhrrrrrr)rs6  zMacroExpander.load_macroscCs$|jD] \}}|||}q|Sr')r(itemsreplace)r*r$rvrrrsubszMacroExpander.subN)__name__ __module__ __qualname__r,r0r)rArrrrr&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$rest majorVersion minorVersionrrrget_build_versions  rUcCs@d}tj|}|dkrdStjd|}tj|t||S)zUReturn the processor architecture. Possible results are "Intel" or "AMD64". z bit (rEIntel))rLr+rMrN)rQrjrrrget_build_architectures  rYcCs0g}|D]}tj|}||vr||q|S)znReturn a list of normalized paths with duplicates removed. The current order of paths is maintained. )osr/normpathr)paths reduced_pathsr<nprrrnormalize_and_reduce_pathss  r_c@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.msvcz.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) NrVzSoftware\Microsoft\VisualStudiozSoftware\Microsoft\DevstudiozVisual Studio version %szMicrosoft SDK compiler %srFF) rr,rU_MSVCCompiler__versionrY_MSVCCompiler__arch_MSVCCompiler__rootr&_MSVCCompiler__macros_MSVCCompiler__product initialized)r*verbosedry_runforcerrrr,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)NDISTUTILS_USE_SDKMSSdkzcl.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.libinclude;rV)/nologo/Ox/MD/W3/GX/DNDEBUG)rr/Od/MDdrurv/Z7/D_DEBUG)rrrsrtru/GS-rw)rrrxryrur|rzr{)/DLLrrz/INCREMENTAL:NOrc)r}rr/INCREMENTAL:no/DEBUG)r}rrr~z /pdb:NonerrrT)_MSVCCompiler__pathsrZenvironfind_execclinkerrorcmcget_msvc_pathsrNrrhset_path_env_varrOrr8r_joinpreprocess_optionsrecompile_optionscompile_options_debugldflags_sharedrdldflags_shared_debugldflags_staticri)r*r<rrr 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)Nrr zDon't know how to compile %s)rZr/splitext splitdriveisabssrc_extensionsrbasename_rc_extensionsrr res_extension_mc_extensions obj_extension)r*source_filenames strip_dir output_dir obj_namessrc_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-rrbz"Don't know how to compile %s to %sz/Fo)rir_setup_compilerextendrrr8rZr/abspath _c_extensions_cpp_extensionsrspawnrrrrdirnamerrrrr)r*sourcesrr( include_dirsdebug extra_preargsextra_postargsdepends compile_infoobjectspp_optsbuild compile_optsobjsrcr input_opt output_optmsgh_dirrc_dirr_rc_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)) rir_fix_object_argslibrary_filename _need_linkrrorrr r) r*routput_libnamerr target_langoutput_filenamelib_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)rirr _fix_lib_argswarnstrrrZr/rrr EXECUTABLErrrrrrrrmkpathrrrrr r)r* target_descrrr libraries library_dirsruntime_library_dirsexport_symbolsrrr build_tempr fixed_argslib_optsldflags export_optssymld_argsdll_namedll_ext implib_filerrrrlinksl        zMSVCCompiler.linkcCsd|S)Nz /LIBPATH:rr*dirrrrlibrary_dir_optionszMSVCCompiler.library_dir_optioncCstd)Nzsj        -  9