a ZÚß^'Nã@sÆdZddlZddlZddlZddlmZmZmZmZm Z ddl m Z m Z ddl mZddlmZddlmZdd „Zd d „Zd d dddœZdd„Zdd„Zddd„Zd ddddœZGdd„de ƒZdS)adistutils._msvccompiler Contains MSVCCompiler, an implementation of the abstract CCompiler class for Microsoft Visual Studio 2015. The module is compatible with VS 2015 and later. You can find legacy support for older versions in distutils.msvc9compiler and distutils.msvccompiler. éN)ÚDistutilsExecErrorÚDistutilsPlatformErrorÚ CompileErrorÚLibErrorÚ LinkError)Ú CCompilerÚgen_lib_options)Úlog)Ú get_platform)Úcountc CsztjtjdtjtjBd}Wnty<t d¡YdS0d}d}|¬tƒD]”}zt  ||¡\}}}Wnty„YqèYn0|rR|tj krRt j   |¡rRztt|ƒƒ}WnttfyÊYqRYn0|dkrR||krR||}}qRWdƒn1sþ0Y||fS)Nz'Software\Microsoft\VisualStudio\SxS\VC7)ÚaccesszVisual C++ is not registered©NNré)ÚwinregZ OpenKeyExÚHKEY_LOCAL_MACHINEZKEY_READZKEY_WOW64_32KEYÚOSErrorr Údebugr Z EnumValueZREG_SZÚosÚpathÚisdirÚintÚfloatÚ ValueErrorÚ TypeError)ÚkeyÚ best_versionÚbest_dirÚiÚvZvc_dirZvtÚversion©r ú//usr/lib64/python3.9/distutils/_msvccompiler.pyÚ _find_vc2015s2 ý       ,r"c Cs tj d¡ptj d¡}|s dSz8tjtj |ddd¡ddd d d d d dg ddd ¡}Wntjt t fytYdS0tj |ddd¡}tj  |¡rœd|fSdS)aJReturns "15, path" based on the result of invoking vswhere.exe If no install is found, returns "None, None" The version is returned to avoid unnecessarily changing the function result. It may be ignored when the path is not None. If vswhere.exe is not available, by definition, VS 2017 is not installed. zProgramFiles(x86)Z ProgramFilesr zMicrosoft Visual StudioZ Installerz vswhere.exez-latestz -prereleasez -requiresz1Microsoft.VisualStudio.Component.VC.Tools.x86.x64z -propertyZinstallationPathz -productsÚ*ÚmbcsÚstrict)ÚencodingÚerrorsZVCZ AuxiliaryZBuildé) rÚenvironÚgetÚ subprocessÚ check_outputrÚjoinÚstripÚCalledProcessErrorrÚUnicodeDecodeErrorr)Úrootrr r r!Ú _find_vc20178s( úù r2Úx86Zx64ZarmZarm64)r3Ú x86_amd64Úx86_armÚ x86_arm64cCs\tƒ\}}|stƒ\}}|s*t d¡dStj |d¡}tj |¡sTt d|¡dS|dfS)Nz$No suitable Visual C++ version foundr z vcvarsall.batz%s cannot be found)r2r"r rrrr-Úisfile)Ú plat_specÚ_rrÚ vcvarsallr r r!Ú_find_vcvarsall_s     r;c CsÀt d¡rdd„tj ¡DƒSt|ƒ\}}|s6tdƒ‚z&tjd ||¡tj dj ddd }WnBtj yž}z(t   |j¡td  |j¡ƒ‚WYd}~n d}~00d d„d d „| ¡DƒDƒ}|S)NZDISTUTILS_USE_SDKcSsi|]\}}| ¡|“qSr ©Úlower)Ú.0rÚvaluer r r!Ú ssÿz_get_vc_env..zUnable to find vcvarsall.batzcmd /u /c "{}" {} && set)Ústderrzutf-16leÚreplace)r'zError executing {}cSs$i|]\}}}|r|r| ¡|“qSr r<)r>rr9r?r r r!r@†sýcss|]}| d¡VqdS)ú=N)Ú partition)r>Úliner r r!Ú ‰óz_get_vc_env..)rÚgetenvr)Úitemsr;rr+r,ÚformatÚSTDOUTÚdecoder/r ÚerrorÚoutputÚcmdÚ splitlines)r8r:r9ÚoutÚexcÚenvr r r!Ú _get_vc_envqs. þ  þý  ÿýrTcCsN|st d¡ tj¡}|D].}tj tj |¡|¡}tj |¡r|Sq|S)atReturn 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'. r)rrHÚsplitÚpathseprr-Úabspathr7)ZexeÚpathsÚpÚfnr r r!Ú _find_exes   r[r4r5r6)Úwin32z win-amd64z win-arm32z win-arm64c sÌeZdZdZdZiZdgZgd¢ZdgZdgZ eeee Z dZ dZ d Z d Zd ZZd Zd&dd„Zd'dd„Zd(dd„Zd)dd„Zd*dd„Zd+dd„Z‡fdd„Zdd„Zd d!„Zd"d#„Zd,d$d%„Z‡ZS)-Ú 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.exercCs t ||||¡d|_d|_dS)NF)rÚ__init__Ú plat_nameÚ initialized)ÚselfÚverboseÚdry_runÚforcer r r!r_ÉszMSVCCompiler.__init__NcCs |durtƒ}|tvr(td ttƒ¡ƒ‚t|}t|ƒ}|sDtdƒ‚| dd¡|_|j t j ¡}t d|ƒ|_ t d|ƒ|_ t d|ƒ|_t d|ƒ|_t d |ƒ|_t d |ƒ|_| d d¡ t j ¡D]}|r¼| | t j¡¡q¼| d d¡ t j ¡D]}|rì| | t j¡¡qìd|_gd ¢|_gd¢|_gd¢}gd¢}g|¢d‘|_g|¢d‘|_g|¢d‘d‘d‘|_g|¢d‘d‘d‘|_g|¢|_g|¢|_tj df|jtj df|jtj df|jtj!df|jtj!df|jtj!df|jtj"df|jtj"df|jtj"df|ji |_#d|_$dS)Nz--plat-name must be one of {}z7Unable to find a compatible Visual Studio installation.rÚzcl.exezlink.exezlib.exezrc.exezmc.exezmt.exeZincludeÚlib)ú/nologoz/Oxú/W3z/GLz/DNDEBUGz/MD)rhz/Odz/MDdz/Ziriz/D_DEBUG)rhú/INCREMENTAL:NOú/LTCG)rhrjrkz /DEBUG:FULLz/MANIFEST:EMBED,ID=1z/DLLz/MANIFEST:EMBED,ID=2z/MANIFESTUAC:NOFT)%r ÚPLAT_TO_VCVARSrrJÚtuplerTr*Ú_pathsrUrrVr[ÚccÚlinkerrgÚrcÚmcÚmtZadd_include_dirÚrstripÚsepZadd_library_dirZpreprocess_optionsÚcompile_optionsÚcompile_options_debugZ ldflags_exeZldflags_exe_debugZldflags_sharedZldflags_shared_debugZldflags_staticZldflags_static_debugrZ EXECUTABLEZ SHARED_OBJECTZSHARED_LIBRARYÚ_ldflagsra)rbr`r8Zvc_envrXÚdirÚldflagsZ ldflags_debugr r r!Ú initializeÏs\ÿ                   ÷ zMSVCCompiler.initializerfcsXi‡fdd„ˆjDƒ¥‡fdd„ˆjˆjDƒ¥‰ˆp8d‰‡‡‡fdd„}tt||ƒƒS)Ncsi|] }|ˆj“qSr )Ú obj_extension©r>Úext©rbr r!r@"rGz1MSVCCompiler.object_filenames..csi|] }|ˆj“qSr )Ú res_extensionr}rr r!r@#rGrfcs’tj |¡\}}ˆr"tj |¡}n2tj |¡\}}| tjjtjjf¡rT|dd…}ztj ˆ|ˆ|¡WSt yŒt d  |¡ƒ‚Yn0dS)NézDon't know how to compile {}) rrÚsplitextÚbasenameÚ splitdriveÚ startswithruÚaltsepr-Ú LookupErrorrrJ)rYÚbaser~r9)Úext_mapÚ output_dirÚ strip_dirr r!Ú make_out_path(s  z4MSVCCompiler.object_filenames..make_out_path)Úsrc_extensionsÚ_rc_extensionsÚ_mc_extensionsÚlistÚmap)rbZsource_filenamesr‹rŠrŒr )r‰rŠrbr‹r!Úobject_filenamessÿþzMSVCCompiler.object_filenamesc  CsŠ|js| ¡| ||||||¡} | \}} }} } |p6g} |  d¡|rT|  |j¡n |  |j¡d}| D]}z| |\}}Wnty”YqhYn0|r¦tj   |¡}||j vr¼d|}nH||j vrÖd|}d}n.||j vr@|}d|}z| |jg| ||g¡Wqhty:}zt|ƒ‚WYd}~qhd}~00qhnÄ||jvrôtj  |¡}tj  |¡}z\| |jd|d||g¡tj  tj  |¡¡\}}tj  ||d ¡}| |jd||g¡Wqhtyî}zt|ƒ‚WYd}~qhd}~00qhntd  ||¡ƒ‚|jg| | }|r$| d ¡| |¡| d |¡| |¡z| |¡Wqhty‚}zt|ƒ‚WYd}~qhd}~00qh| S) Nz/cFz/Tcz/TpTz/foz-hz-rr^z"Don't know how to compile {} to {}z/EHscz/Fo)rar{Z_setup_compileÚappendÚextendrwrvÚKeyErrorrrrWÚ _c_extensionsÚ_cpp_extensionsrŽÚspawnrqrrrÚdirnamerrr‚rƒr-rJro)rbZsourcesrŠZmacrosZ include_dirsrÚ extra_preargsÚextra_postargsZdependsZ compile_infoÚobjectsZpp_optsZbuildZ compile_optsZ add_cpp_optsÚobjÚsrcr~Z input_optZ output_optÚmsgZh_dirZrc_dirrˆr9Zrc_fileÚargsr r r!Úcompile>sr ÿ            ÿ    zMSVCCompiler.compilec Cs¶|js| ¡| ||¡\}}|j||d}| ||¡r¦|d|g}|rJz,t d|jd |¡¡|  |jg|¡Wq²t y¢}zt |ƒ‚WYd}~q²d}~00n t d|¡dS)N)rŠú/OUT:úExecuting "%s" %sú úskipping %s (up-to-date)) rar{Ú_fix_object_argsÚlibrary_filenameÚ _need_linkr rrgr-r˜rr) rbrœZoutput_libnamerŠrÚ target_langÚoutput_filenameZlib_argsrŸr r r!Úcreate_static_lib˜sÿ  zMSVCCompiler.create_static_libc Csº|js| ¡| ||¡\}}| |||¡}|\}}}|rL| dt|ƒ¡t||||ƒ}|durptj  ||¡}|  ||¡rª|j || f}dd„|p˜gDƒ}||||d|g}tj  |d¡} |dur tj  tj |¡¡\}}tj  | | |¡¡}| d|¡| r| |dd…<| r.| | ¡tj  tj |¡¡}| |¡z,t d|jd  |¡¡| |jg|¡Wn.ty¦}zt|ƒ‚WYd}~n d}~00n t d |¡dS) Nz5I don't know what to do with 'runtime_library_dirs': cSsg|] }d|‘qS)z/EXPORT:r )r>Zsymr r r!Ú ÕrGz%MSVCCompiler.link..r¢rz/IMPLIB:r£r¤r¥)rar{r¦Z _fix_lib_argsÚwarnÚstrrrrr-r¨rxr™r‚rƒr§r“r”rWZmkpathr rrpr˜rr)rbZ target_descrœrªrŠZ librariesZ library_dirsZruntime_library_dirsZexport_symbolsrršr›Z build_tempr©Z fixed_argsZlib_optsrzZ export_optsZld_argsZdll_nameZdll_extZ implib_filerŸr r r!Úlink²s^ÿ ÿþ ÿÿ  ÿþ    zMSVCCompiler.linkc s@t d¡}z$|jtjd<tƒ |¡W|tjd<S|tjd<0dS)Nr)rrHrnr)Úsuperr˜)rbrOZold_path©Ú __class__r r!r˜÷s    þzMSVCCompiler.spawncCsd|S)Nz /LIBPATH:r ©rbryr r r!Úlibrary_dir_optionszMSVCCompiler.library_dir_optioncCs tdƒ‚dS)Nz:don't know how to set runtime library search path for MSVC)rr³r r r!Úruntime_library_dir_optionsÿz'MSVCCompiler.runtime_library_dir_optioncCs | |¡S)N)r§)rbrgr r r!Úlibrary_option szMSVCCompiler.library_optioncCs\|r|d|g}n|g}|D]:}|D]0}tj || |¡¡}tj |¡r$|Sq$qdS)NZ_d)rrr-r§r7)rbÚdirsrgrZ try_namesryÚnameZlibfiler r r!Úfind_library_file s zMSVCCompiler.find_library_file)rrr)N)rrf)NNNrNNN)NrN) NNNNNrNNNN)r)Ú__name__Ú __module__Ú __qualname__Ú__doc__Z compiler_typeZ executablesr–r—rŽrrr€r|Zstatic_lib_extensionZshared_lib_extensionZstatic_lib_formatZshared_lib_formatZ exe_extensionr_r{r’r¡r«r¯r˜r´rµr¶r¹Ú __classcell__r r r±r!r]ªs\ÿÿ  Pý "þ ]û ó E r])N)r½rr+rZdistutils.errorsrrrrrZdistutils.ccompilerrrZ distutilsr Zdistutils.utilr Ú itertoolsr r"r2ZPLAT_SPEC_TO_RUNTIMEr;rTr[rlr]r r r r!Ús0   !ü ü