a „oe Lã@s dZddlZddlZddlZddlZddlmZe e¡�ddl Z Wdƒn1sX0Yddl m Z m Z m Z mZmZddlmZmZddlmZddlmZddlmZd d „Zd d „Zd ddddœZdd„Zdd„Zddd„Zd ddddœZGdd„deƒZ dS)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ƒn1�sþ0Y||fS)Nz'Software\Microsoft\VisualStudio\SxS\VC7)ÚaccesszVisual C++ is not registered©NNré)ÚwinregÚ OpenKeyExÚHKEY_LOCAL_MACHINEÚKEY_READÚKEY_WOW64_32KEYÚOSErrorr Údebugr Ú EnumValueÚREG_SZÚosÚpathÚisdirÚintÚfloatÚ ValueErrorÚ TypeError)ÚkeyÚ best_versionÚbest_dirÚiÚvZvc_dirZvtÚversion©r&úDC:\Program Files\Certbot\pkgs\setuptools\_distutils\_msvccompiler.pyÚ _find_vc2015's2 ý       ,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 ProgramFilesrzMicrosoft 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_vc2017Ds4 ÿõ ñ r8Úx86Zx64ZarmZarm64)r9Ú x86_amd64Úx86_armÚ x86_arm64cCs\tƒ\}}|stƒ\}}|s*t d¡dStj |d¡}tj |¡sTt d|¡dS|dfS)Nz$No suitable Visual C++ version foundrz vcvarsall.batz%s cannot be found)r8r(r rrrr3Úisfile)Ú plat_specÚ_r"r!Ú vcvarsallr&r&r'Ú_find_vcvarsallvs     rAc CsÆt d¡rdd„tj ¡DƒSt|ƒ\}}|s6tdƒ‚z,tjd|›d|›d�tjd�j d d d �}WnBtj y¤}z(t   |j ¡td |j›�ƒ‚WYd}~n d}~00d d„dd„| ¡DƒDƒ}|S)NZDISTUTILS_USE_SDKcSsi|]\}}| ¡|“qSr&©Úlower)Ú.0r Úvaluer&r&r'Ú ‹óz_get_vc_env..zUnable to find vcvarsall.batz cmd /u /c "z" z && set)Ústderrzutf-16leÚreplace)r-zError executing cSs$i|]\}}}|r|r| ¡|“qSr&rB)rDr r?rEr&r&r'rFšsþcss|]}| d¡VqdS)ú=N)Ú partition)rDÚliner&r&r'Ú œrGz_get_vc_env..)rÚgetenvr/ÚitemsrArr1r2ZSTDOUTÚdecoder5r ÚerrorÚoutputÚcmdÚ splitlines)r>r@r?ÚoutÚexcÚenvr&r&r'Ú _get_vc_env‰s&  þý  &þrXcCsN|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)rrNÚsplitÚpathseprr3Úabspathr=)ZexeÚpathsÚpÚfnr&r&r'Ú _find_exe£s   r_r:r;r<)Úwin32z win-amd64z win-arm32z win-arm64c seZdZdZdZiZdgZgd¢ZdgZdgZ eeee Z dZ dZ d Z d Zd ZZd Zd+‡fdd„ Zedd„ƒZedd„ƒZd,dd„Ze‡fdd„ƒZd-dd„Zd.dd„Zd/dd„Z‡fdd „Zej‡fd!d"„ƒZ d#d$„Z!d%d&„Z"d'd(„Z#d0d)d*„Z$‡Z%S)1Ú MSVCCompilerztConcrete 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.exercs tƒ |||¡d|_d|_dS)NF)ÚsuperÚ__init__Ú plat_nameÚ initialized)ÚselfÚverboseÚdry_runÚforce©Ú __class__r&r'rdÝszMSVCCompiler.__init__cCs,| | dd¡¡|_| | dd¡¡|_dS)z3 Set class-level include/lib dirs. ZincludeÚÚlibN)Ú _parse_pathr0Ú include_dirsÚ library_dirs)ÚclsÚvc_envr&r&r'Ú _configureãszMSVCCompiler._configurecCsdd„| tj¡DƒS)NcSsg|]}|r| tj¡‘qSr&)ÚrstriprÚsep)rDÚdirr&r&r'Ú írGz,MSVCCompiler._parse_path..)rYrrZ)Úvalr&r&r'roëszMSVCCompiler._parse_pathNcCsÂ|jrJdƒ‚|durtƒ}|tvr6tdttƒ›�ƒ‚t|}t|ƒ}|sRtdƒ‚| |¡| dd¡|_|j  t j ¡}t d|ƒ|_ t d|ƒ|_t d|ƒ|_t d |ƒ|_t d |ƒ|_t d |ƒ|_d|_gd ¢|_gd ¢|_gd¢}gd¢}g|¢d‘|_g|¢d‘|_g|¢d‘d‘d‘|_g|¢d‘d‘d‘|_g|¢|_g|¢|_tjdf|jtjdf|jtjdf|jtjdf|jtjdf|jtjdf|jtjdf|jtjdf|jtjdf|ji |_ d|_dS)Nzdon't init multiple timesz--plat-name must be one of z7Unable to find a compatible Visual Studio installation.rrmzcl.exezlink.exezlib.exezrc.exezmc.exezmt.exe)ú/nologoz/O2ú/W3z/GLz/DNDEBUGz/MD)rzz/Odz/MDdz/Zir{z/D_DEBUG)rzú/INCREMENTAL:NOú/LTCG)rzr|r}z /DEBUG:FULLz/MANIFEST:EMBED,ID=1z/DLLz/MANIFEST:EMBED,ID=2z/MANIFESTUAC:NOFT)!rfr ÚPLAT_TO_VCVARSrÚtuplerXrtr0Ú_pathsrYrrZr_ÚccÚlinkerrnÚrcÚmcÚmtZpreprocess_optionsÚcompile_optionsÚcompile_options_debugZ ldflags_exeZldflags_exe_debugZldflags_sharedZldflags_shared_debugZldflags_staticZldflags_static_debugrZ EXECUTABLEZ SHARED_OBJECTZSHARED_LIBRARYÚ_ldflags)rgrer>rsr\ÚldflagsZ ldflags_debugr&r&r'Ú initializeïsx ÿÿ         ÿþýüÿþýü           ÷ zMSVCCompiler.initializecs&itƒj¥‡fdd„ˆjˆjDƒ¥S)Ncsi|] }|ˆj“qSr&)Ú res_extension)rDÚext©rgr&r'rFEsÿz/MSVCCompiler.out_extensions..)rcÚout_extensionsÚ_rc_extensionsÚ_mc_extensionsr�rkr�r'rŽAsÿ  þþzMSVCCompiler.out_extensionsc  Csˆ|js| ¡| ||||||¡} | \}} }} } |p6g} |  d¡|rT|  |j¡n |  |j¡d}| D�]}z| |\}}Wnty”YqhYn0|r¦tj   |¡}||j vr¼d|}�nL||j vrÖd|}d}�n2||j v�r@|}d|}z| |jg| ||g¡Wqht�y:}zt|ƒ‚WYd}~qhd}~00qhnÈ||jv�rôtj  |¡}tj  |¡}z\| |jd|d||g¡tj  tj  |¡¡\}}tj  ||d ¡}| |jd||g¡Wqht�yî}zt|ƒ‚WYd}~qhd}~00qhntd |›d |›�ƒ‚|jg| | }|�r(| d ¡| |d |f¡| |¡z| |¡Wqht�y€}zt|ƒ‚WYd}~qhd}~00qh| S)Nz/cFz/Tcz/TpTz/foz-hz-rrbzDon't know how to compile z to z/EHscz/Fo)rfrŠZ_setup_compileÚappendÚextendr‡r†ÚKeyErrorrrr[Ú _c_extensionsÚ_cpp_extensionsr�Úspawnrƒrrr�Údirnamer„ÚsplitextÚbasenamer3r�)rgZsourcesÚ output_dirZmacrosrprÚ extra_preargsÚextra_postargsZdependsZ compile_infoÚobjectsZpp_optsÚbuildZ compile_optsZ add_cpp_optsÚobjÚsrcrŒZ input_optZ output_optÚmsgZh_dirZrc_dirÚbaser?Zrc_fileÚargsr&r&r'ÚcompileKsl  ÿ               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)) rfrŠÚ_fix_object_argsÚlibrary_filenameÚ _need_linkr rrnr3r–rr) rgr�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¡} |du�r tj  tj |¡¡\}}tj  | | |¡¡}| d|¡| �r| |dd…<| �r.| | ¡tj  tj |¡¡}| |¡z,t d|jd  |¡¡| |jg|¡Wn.t�y¦}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&)rDZsymr&r&r'rxàrGz%MSVCCompiler.link..r¥rz/IMPLIB:r¦r§r¨)rfrŠr©Z _fix_lib_argsÚwarnÚstrr rrr3r«rˆr—r˜r™rªr‘r’r[Zmkpathr rr‚r–rr)rgZ target_descr�r­ršZ librariesrqZruntime_library_dirsZexport_symbolsrr›rœZ build_tempr¬Z fixed_argsZlib_optsr‰Z export_optsZld_argsZdll_nameZdll_extZ implib_filer¡r&r&r'Úlink½sL ÿÿÿ   ÿ    zMSVCCompiler.linkcsRttj|jd�}| ||¡� }tƒj||d�WdƒS1sB0Y|jS)N)ÚPATH)rW)Údictrr/r€Ú_fallback_spawnrcr–rE)rgrSrWÚfallbackrkr&r'r–s.zMSVCCompiler.spawnc #sštddiƒƒ}z |VWn2tyJ}zdt|ƒvr6‚WYd}~nd}~00dSt d¡tj d|¡�tƒ  |¡|_ Wdƒn1sŒ0YdS)zÍ Discovered in pypa/distutils#15, some tools monkeypatch the compiler, so the 'env' kwarg causes a TypeError. Detect this condition and restore the legacy, unsafe behavior. ZBagr&z!unexpected keyword argument 'env'Nz>Fallback spawn triggered. Please update distutils monkeypatch.z os.environ) Útyperr°Úwarningsr¯ÚmockZpatchr³rcr–rE)rgrSrWZbagrVrkr&r'r´s   zMSVCCompiler._fallback_spawncCsd|S)Nz /LIBPATH:r&©rgrwr&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_option"sÿz'MSVCCompiler.runtime_library_dir_optioncCs | |¡S)N)rª)rgrnr&r&r'Úlibrary_option'szMSVCCompiler.library_optioncCs\|r|d|g}n|g}|D]:}|D]0}tj || |¡¡}tj |¡r$|Sq$qdS)NZ_d)rrr3rªr=)rgÚdirsrnrZ try_namesrwÚnameZlibfiler&r&r'Úfind_library_file*s zMSVCCompiler.find_library_file)rrr)N)NNNrNNN)NrN) NNNNNrNNNN)r)&Ú__name__Ú __module__Ú __qualname__Ú__doc__Z compiler_typeZ executablesr”r•r�r�Zsrc_extensionsr‹Z obj_extensionZstatic_lib_extensionZshared_lib_extensionZstatic_lib_formatZshared_lib_formatZ exe_extensionrdÚ classmethodrtÚ staticmethodrorŠÚpropertyrŽr¤r®r±r–Ú contextlibÚcontextmanagerr´rºr»r¼r¿Ú __classcell__r&r&rkr'raÀsd   R ÷ _ÿ ò E ra)N)!rÃrr1rÇr·Z unittest.mockr¸ÚsuppressÚ ImportErrorrr-rrrrrZ ccompilerrr Z_logr Úutilr Ú itertoolsr r(r8ZPLAT_SPEC_TO_RUNTIMErArXr_r~rar&r&r&r'Ús8  &   +ü ü