o bcv@sLdZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z m Z ddlmZddlmZddlZejZejZejZejZejejejejfZej dkoWej!dkZ"e"rad Z#d Z$d Z%nd Z#d Z$dZ%dddZ&GdddZ'GdddZ(ddZ)ddZ*ddZ+ddZ,d$ddZ-e)Z.e.d kred!e.Gd"d#d#e Z/dS)%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)DistutilsExecErrorDistutilsPlatformError CompileErrorLibError LinkError) CCompilergen_lib_options)log) get_platformwin32lz1Software\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\.NETFrameworkx86amd64r z win-amd64c@sPeZdZdZddZeeZddZeeZddZeeZdd Ze eZd S) Regz2Helper class to read values from the registry cCs6tD]}|||}|r||vr||Sqt|N)HKEYS read_valuesKeyError)clspathkeybasedr./usr/lib/python3.10/distutils/msvc9compiler.py get_value?s    z Reg.get_valuecCsfzt||}Wn tyYdSwg}d} zt||}Wn ty(Y|Sw|||d7}q)zReturn list of registry keys.NrT) RegOpenKeyExRegError RegEnumKeyappend)rrrhandleLikrrr read_keysGs"   z Reg.read_keysc Cs~zt||}Wn tyYdSwi}d} z t||\}}}Wn ty+Y|Sw|}|||||<|d7}q)z`Return dict of registry keys and values. All names are converted to lowercase. NrTr)rr RegEnumValuelower convert_mbcs) rrrr!rr#namevaluetyperrrrYs$  zReg.read_valuescCs<t|dd}|durz|d}W|StyY|Sw|S)Ndecodembcs)getattr UnicodeError)sdecrrrr(os   zReg.convert_mbcsN) __name__ __module__ __qualname____doc__r classmethodr%rr( staticmethodrrrrr;s rc@s,eZdZddZddZddZddZd S) MacroExpandercCsi|_t||_||dSr)macrosVS_BASEvsbase load_macros)selfversionrrr__init__{s zMacroExpander.__init__cCst|||jd|<dS)Nz$(%s))rrr9)r=macrorrrrr set_macroszMacroExpander.set_macroc Cs|d|jdd|d|jdd|dtdz|dkr(|d td ntd Wn ty8td w|d krN|d |jd|dtddSd}tD])}zt||}Wn tydYqRwt |d}t |d||f}|d|j d<qRdS)N VCInstallDirz \Setup\VC productdir VSInstallDirz \Setup\VS FrameworkDir installroot @FrameworkSDKDirzsdkinstallrootv2.0aPython 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 WindowsSdkDircurrentinstallfolderz.Software\Microsoft\NET Framework Setup\Productrz%s\%sr>z$(FrameworkVersion)) rAr;NET_BASErr WINSDK_BASErrrrrrr9)r=r>prhrrrrrr<s:   zMacroExpander.load_macroscCs$|jD] \}}|||}q|Sr)r9itemsreplace)r=r0r$vrrrsubszMacroExpander.subN)r2r3r4r?rAr<rSrrrrr8ys  r8cCsd}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)prefixr#r0rest majorVersion minorVersionrrrget_build_versions  rdcCs0g}|D]}tj|}||vr||q|S)znReturn a list of normalized paths with duplicates removed. The current order of paths is maintained. )osrnormpathr )paths reduced_pathsrNnprrrnormalize_and_reduce_pathss  rjcCs<|tj}g}|D] }||vr||q tj|}|S)z8Remove duplicate values of an environment variable. )r^repathsepr join)variableoldListnewListr# newVariablerrrremoveDuplicatess   rqcCst|}z td|d}Wntytdd}Ynw|r'tj|sbd|}tj |d}|r[tj|r[tj |tj tj d}tj |}tj|sZtd|dSntd||sktd dStj |d }tj|rz|Std dS) 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\VCrCz%Unable to find productdir in registryNzVS%0.f0COMNTOOLSVCz%s is not a valid directoryz Env var %s is not set or invalidzNo productdir foundz vcvarsall.batUnable to find vcvarsall.bat)r:rrrr debugrerisdirenvirongetrlpardirabspathisfile)r>r;rCtoolskeytoolsdir vcvarsallrrrfind_vcvarsalls8        r~c CsFt|}hd}i}|durtdtd||tjd||ftjtjd}z\|\}}|dkr;t| d| d}| d D]2}t |}d |vrQqE| }| d d \} } | } | |vrw| tjrq| dd } t| || <qEW|j|jn |j|jwt|t|krttt||S) zDLaunch vcvarsall.bat and read the settings from its environment >librincludelibpathNrsz'Calling 'vcvarsall.bat %s' (version=%s)z "%s" %s & set)stdoutstderrrr- =rrT)r~rr rt subprocessPopenPIPE communicatewaitr,r^rr(stripr'endswithrerkrqrcloserr] ValueErrorstrlistkeys) r>archr} interestingresultpopenrrlinerr*rrrquery_vcvarsallsF         rrGz(VC %0.1f is not supported by this modulec@seZdZdZdZiZdgZgdZdgZdgZ eeee Z dZ dZ d Z d Zd ZZd Zd,ddZd-ddZ d.ddZ d/ddZ  d0ddZ         d1ddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd2d(d)Zd*d+ZdS)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.exercCs8t||||t|_d|_g|_d|_d|_d|_dS)NzSoftware\Microsoft\VisualStudioF) rr?VERSION_MSVCCompiler__version_MSVCCompiler__root_MSVCCompiler__paths plat_name_MSVCCompiler__arch initialized)r=verbosedry_runforcerrrr?Hs zMSVCCompiler.__init__NcCs|jrJd|durt}d}||vrtd|fdtjvr:dtjvr:|dr:d|_d|_d|_d |_ d |_ na|tksC|d krHt |}n t td t |}t t |}|d tj|_|dtjd<|dtjd<t|jdkr}td|j|d|_|d|_|d|_|d |_ |d |_ ztjd dD]}|j|qWn tyYnwt|j|_d|jtjd <d|_|jdkrgd|_gd|_n gd|_gd|_gd|_|jdkrgd|_dg|_d|_dS)Nzdon't init multiple timesrz--plat-name must be one of %sDISTUTILS_USE_SDKMSSdkzcl.exezlink.exezlib.exezrc.exezmc.exer _rrrrzxPython was built with %s, and extensions need to be built with the same version of the compiler, but it isn't installed.;r )/nologo/Ox/MD/W3/DNDEBUG)r/Od/MDdr/Z7/D_DEBUG)rrrr/GS-r)rrrrrrr)/DLLrz/INCREMENTAL:NO)rrz/INCREMENTAL:noz/DEBUGrT)rr rrervfind_execclinkerrrcmcPLAT_TO_VCVARSrrr^rkrr]_MSVCCompiler__productr rrjrlpreprocess_optionsrcompile_optionscompile_options_debugldflags_sharedrldflags_shared_debugldflags_static)r=rok_plats plat_specvc_envrNrrr initializeSsh                   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)NrrzDon't know how to compile %s)rersplitext splitdriveisabssrc_extensionsrbasename_rc_extensionsr rl res_extension_mc_extensions obj_extension)r=source_filenames strip_dir output_dir obj_namessrc_namerextrrrobject_filenamess,         zMSVCCompiler.object_filenamesc  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-rrz"Don't know how to compile %s to %sz/Fo)rr_setup_compiler extendrrrrerry _c_extensions_cpp_extensionsrspawnrrrrdirnamerrrrlr)r=sourcesrr9 include_dirsrt extra_preargsextra_postargsdepends compile_infoobjectspp_optsbuild compile_optsobjsrcr input_opt output_optmsgh_dirrc_dirrrrc_filerrrcompiles                  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)) rr_fix_object_argslibrary_filename _need_linkrrrrr rt) r=routput_libnamerrt target_langoutput_filenamelib_argsrrrrcreate_static_libs" zMSVCCompiler.create_static_libc Cs<|js||||\}}||||}|\}}}|r&|dt|t||||}|dur8tj ||}| ||r|t j krV| rN|j dd}n|jdd}n | r\|j }n|j}g}|pdgD] }|d|qe||||d|g}tj|d} |durtjtj|\}}tj | ||}|d|||| || r| |dd<| r|| |tj|z ||jg|Wnty}zt|d}~ww|||}|dur|\}}d||f}z |dd d ||gWdSty}zt|d}~wwdStd |dS) Nz5I don't know what to do with 'runtime_library_dirs': rz/EXPORT:rrz/IMPLIB:z-outputresource:%s;%szmt.exez-nologoz -manifestr)rrr _fix_lib_argswarnrrrerrlrr EXECUTABLErrr rrrrmanifest_setup_ldargsrmkpathrrrrmanifest_get_embed_infor rt)r= target_descrrr libraries library_dirsruntime_library_dirsexport_symbolsrtrr build_tempr fixed_argslib_optsldflags export_optssymld_argsdll_namedll_ext implib_filermfinfo mffilenamemfidout_argrrrlink5s             zMSVCCompiler.linkcCs,tj|tj|d}|d|dS)Nz .manifest/MANIFESTFILE:)rerrlrr )r=rrr  temp_manifestrrrrs z"MSVCCompiler.manifest_setup_ldargscCs^|D]}|dr|ddd}nqdS|tjkrd}nd}||}|dur+dS||fS)Nr:rrY) startswithr^rr_remove_visual_c_ref)r=rr argrrrrrrs   z$MSVCCompiler.manifest_get_embed_infocCszUt|}z |}W|n|wtdtj}t|d|}d}t|d|}tdtj}t||dur>WdSt|d}z |||W|WS|wt y_YdSw)NzU|)rz*\s*zI|)w) openreadrrerDOTALLrSsearchwriteOSError)r= manifest_file manifest_f manifest_bufpatternrrrrs4     z!MSVCCompiler._remove_visual_c_refcCsd|S)Nz /LIBPATH:rr=dirrrrlibrary_dir_optionszMSVCCompiler.library_dir_optioncCstd)NzsR  >. #)