U e5d/w@sRdZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z m Z mZddlmZddlmZddlZejZejZejZejZejejejejfZ ej!dkoej"dkZ#e#rd Z$d Z%d Z&n d Z$d Z%dZ&dddZ'GdddZ(GdddZ)ddZ*ddZ+ddZ,ddZ-d$ddZ.e*Z/e/d kr>ed!e/Gd"d#d#e Z0dS)%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_preprocess_optionsgen_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\.NETFrameworkx86Zamd64r z win-amd64c@sPeZdZdZddZeeZddZeeZddZeeZdd Ze eZd S) Regz2Helper class to read values from the registry cCs:tD](}|||}|r||kr||Sqt|dSN)HKEYS read_valuesKeyError)clspathkeybasedr//usr/lib64/python3.8/distutils/msvc9compiler.py get_value@s   z Reg.get_valuecCsnzt||}Wntk r$YdSXg}d}zt||}Wntk rTYqjYnX|||d7}q.|S)zReturn list of registry keys.Nr) RegOpenKeyExRegError RegEnumKeyappend)rrrhandleLikrrr read_keysHs   z Reg.read_keysc Cszt||}Wntk r$YdSXi}d}zt||\}}}Wntk rZYqYnX|}|||||<|d7}q.|S)z`Return dict of registry keys and values. All names are converted to lowercase. Nrr)rr RegEnumValuelower convert_mbcs) rrrr!rr#namevaluetyperrrrZs  zReg.read_valuescCs:t|dd}|dk r6z |d}Wntk r4YnX|S)Ndecodembcs)getattr UnicodeError)sZdecrrrr(ps  zReg.convert_mbcsN) __name__ __module__ __qualname____doc__r classmethodr%rr( staticmethodrrrrr<src@s,eZdZddZddZddZddZd S) MacroExpandercCsi|_t||_||dSr)macrosVS_BASEvsbase load_macros)selfversionrrr__init__|s zMacroExpander.__init__cCst|||jd|<dS)Nz$(%s))rrr8)r<Zmacrorrrrr set_macroszMacroExpander.set_macroc Cs|d|jdd|d|jdd|dtdz$|dkrP|d td ntd Wntk rvtd YnX|d kr|d |jd|dtdnbd}tD]X}zt||}Wntk rYqYnXt |d}t |d||f}|d|j d<qdS)NZ VCInstallDirz \Setup\VC productdirZ VSInstallDirz \Setup\VSZ FrameworkDirZ installroot @ZFrameworkSDKDirzsdkinstallrootv2.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"@ZFrameworkVersionz clr versionZ WindowsSdkDirZcurrentinstallfolderz.Software\Microsoft\NET Framework Setup\Productrz%s\%sr=z$(FrameworkVersion)) r?r:NET_BASErr WINSDK_BASErrrrrrr8)r<r=prhrrrrrr;s2    zMacroExpander.load_macroscCs$|jD]\}}|||}q |Sr)r8itemsreplace)r<r0r$vrrrsubszMacroExpander.subN)r1r2r3r>r?r;rIrrrrr7zsr7cCsd}tj|}|dkrdS|t|}tj|ddd\}}t|ddd}|dkrf|d7}t|d d d }|dkrd }|dkr||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#r0restZ majorVersionZ minorVersionrrrget_build_versions  rXcCs0g}|D]"}tj|}||kr||q|S)znReturn a list of normalized paths with duplicates removed. The current order of paths is maintained. )osrnormpathr )pathsZ reduced_pathsrDZnprrrnormalize_and_reduce_pathss   r\cCs<|tj}g}|D]}||kr||qtj|}|S)z8Remove duplicate values of an environment variable. )rTrYpathsepr join)ZvariableZoldListZnewListr#Z newVariablerrrremoveDuplicatess   r_cCst|}ztd|d}Wn"tk r>tdd}YnX|rPtj|sd|}tj |d}|rtj|rtj |tj tj d}tj |}tj|std|dSntd||std dStj |d }tj|r|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\VCr@z%Unable to find productdir in registryNzVS%0.f0COMNTOOLSZVCz%s is not a valid directoryz Env var %s is not set or invalidzNo productdir foundz vcvarsall.batUnable to find vcvarsall.bat)r9rrrr debugrYrisdirenvirongetr^pardirabspathisfile)r=r:r@ZtoolskeyZtoolsdir vcvarsallrrrfind_vcvarsalls4        ric Cs8t|}ddddh}i}|dkr(tdtd||tjd||ftjtjd }z| \}}| d krzt| d | d }| d D]d}t|}d |krq|}| d d\} } | } | |kr| tjr| dd} t| || <qW5|j|j Xt|t|kr4ttt||S)zDLaunch vcvarsall.bat and read the settings from its environment includelibZlibpathrNr`z'Calling 'vcvarsall.bat %s' (version=%s)z "%s" %s & set)stdoutstderrrr- =rrJ)rirr ra subprocessPopenPIPErlclosermZ communicatewaitr,rTrr(stripr'endswithrYr]r_rS ValueErrorstrlistkeys) r=ZarchrhZ interestingresultpopenrlrmlinerr*rrrquery_vcvarsalls>         r~rAz(VC %0.1f is not supported by this modulec @seZdZdZdZiZdgZdddgZdgZdgZ eeee Z d Z d Z d Z d Zd ZZdZd.ddZd/ddZd0ddZd1ddZd2ddZd3ddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd4d*d+Zd,d-ZdS)5 MSVCCompilerzwConcrete class that implements an interface to Microsoft Visual C++, as defined by the CCompiler abstract class.Zmsvcz.cz.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__versionZ_MSVCCompiler__root_MSVCCompiler__paths plat_name_MSVCCompiler__arch initialized)r<verboseZdry_runZforcerrrr>IszMSVCCompiler.__init__NcCs|dkrt}d}||kr(td|fdtjkrfdtjkrf|drfd|_d|_d|_d|_d |_ n|tksx|d krt |}nt td t |}t t |}|d  tj|_|d tjd <|dtjd<t|jdkrtd|j|d|_|d|_|d|_|d|_|d |_ z(tjd  dD]}|j|q:Wntk rfYnXt|j|_d|jtjd <d|_|jdkrdddddg|_ddddddg|_n&ddddddg|_dddddddg|_dddg|_|jdkrddd d!g|_dg|_d"|_dS)#Nrz--plat-name must be one of %sZDISTUTILS_USE_SDKZMSSdkzcl.exezlink.exezlib.exezrc.exezmc.exer _rrkrjrzxPython was built with %s, and extensions need to be built with the same version of the compiler, but it isn't installed.;r z/nologoz/Oxz/MDz/W3z/DNDEBUGz/Odz/MDdz/Z7z/D_DEBUGz/GS-z/DLLz/INCREMENTAL:NOz/INCREMENTAL:noz/DEBUGT)r rrYrcfind_execclinkerrkrcmcPLAT_TO_VCVARSr~rrTr]rrSZ_MSVCCompiler__productr rr\r^Zpreprocess_optionsrcompile_optionscompile_options_debugldflags_sharedrldflags_shared_debugZldflags_staticr)r<rZok_platsZ plat_specZvc_envrDrrr initializeTs~              zMSVCCompiler.initializecCs|dkr d}g}|D]}tj|\}}tj|d}|tj|d}||jkrbtd||rrtj|}||jkr| tj |||j q||j kr| tj |||j q| tj |||j q|S)NrrzDon't know how to compile %s)rYrsplitext splitdriveisabssrc_extensionsrbasename_rc_extensionsr r^ res_extension_mc_extensions obj_extension)r<Zsource_filenamesZ strip_dir output_dirZ obj_namesZsrc_namerextrrrobject_filenamess.        zMSVCCompiler.object_filenamesc  Csp|js||||||||} | \}} }} } |p6g} | d|rT| |jn | |j| D]}z| |\}}Wntk rYqdYnX|rtj |}||j krd|}nT||j krd|}n>||j kr<|}d|}z"||jg| |g|gWqdtk r6}z t|W5d}~XYqdXqdn||jkrtj |}tj |}zl||jgd|d|g|gtj tj |\}}tj ||d}||jgd|g|gWqdtk r}z t|W5d}~XYqdXqdntd||fd |}z&||jg| | ||g|Wqdtk rh}z t|W5d}~XYqdXqd| S) Nz/cz/Tcz/Tpz/foz-hz-rrz"Don't know how to compile %s to %sz/Fo)rrZ_setup_compiler extendrrrrYrrf _c_extensions_cpp_extensionsrspawnrrrrdirnamerrrr^r)r<Zsourcesrr8Z include_dirsra extra_preargsextra_postargsZdependsZ compile_infoobjectsZpp_optsZbuildZ compile_optsobjsrcrZ input_optZ output_optmsgZh_dirZrc_dirrrZrc_filerrrcompiles                   zMSVCCompiler.compilec Cs|js||||\}}|j||d}|||r|d|g}|rJz||jg|Wqtk r}z t|W5d}~XYqXn t d|dS)N)r/OUT:skipping %s (up-to-date)) rr_fix_object_argslibrary_filename _need_linkrrkrrr ra) r<rZoutput_libnamerra target_langoutput_filenameZlib_argsrrrrcreate_static_libs zMSVCCompiler.create_static_libc CsT|js||||\}}||||}|\}}}|rL|dt|t||||}|dk rptj ||}| ||rD|t j kr| r|j dd}q|jdd}n| r|j }n|j}g}|pgD]}|d|q||||d|g}tj|d} |dk rLtjtj|\}}tj | ||}|d|||| || rl| |dd<| r||| |tj|z||jg|Wn,tk r}z t|W5d}~XYnX|||}|dk rP|\}}d||f}z|dd d ||gWn,tk r@}z t|W5d}~XYnXn td |dS) Nz5I don't know what to do with 'runtime_library_dirs': rz/EXPORT:rrz/IMPLIB:z-outputresource:%s;%szmt.exez-nologoz -manifestr)rrrZ _fix_lib_argswarnrxr rYrr^rr EXECUTABLErrr rrrrmanifest_setup_ldargsrZmkpathrrrrmanifest_get_embed_infor ra)r< target_descrrrZ librariesZ library_dirsZruntime_library_dirsZexport_symbolsrarr build_temprZ fixed_argsZlib_optsZldflagsZ export_optsZsymld_argsZdll_nameZdll_extZ implib_filerZmfinfoZ mffilenamemfidZout_argrrrlink6s             zMSVCCompiler.linkcCs,tj|tj|d}|d|dS)Nz .manifest/MANIFESTFILE:)rYrr^rr )r<rrr temp_manifestrrrrs z"MSVCCompiler.manifest_setup_ldargscCs^|D]"}|dr|ddd}q,qdS|tjkr|)rz*\s*zI|)w) openrsreadrerDOTALLrIsearchwriteOSError)r<Z manifest_fileZ manifest_fZ manifest_bufpatternrrrrs2      z!MSVCCompiler._remove_visual_c_refcCsd|S)Nz /LIBPATH:rr<dirrrrlibrary_dir_optionszMSVCCompiler.library_dir_optioncCs tddS)Nzrrrrrrrrrrrrrrrrrr+sl  W  X  _ + r)r )1r4rYrprQrZdistutils.errorsrrrrrZdistutils.ccompilerrrr Z distutilsr Zdistutils.utilr winregZ OpenKeyExrZEnumKeyrZ EnumValuer&errorrZ HKEY_USERSHKEY_CURRENT_USERHKEY_LOCAL_MACHINEZHKEY_CLASSES_ROOTrplatformmaxsizeZ NATIVE_WIN64r9rCrBrrr7rXr\r_rir~rrrrrrsP  >. # )