a oeL@s dZddlZddlZddlZddlZddlmZeeddl Z Wdn1sX0Yddl m Z m Z m Z mZmZddlmZmZddlmZddlmZddlmZd d Zd d Zd ddddZddZddZdddZd ddddZGdddeZ 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)DistutilsExecErrorDistutilsPlatformError CompileErrorLibError LinkError) CCompilergen_lib_options)log) get_platform)countc CsztjtjdtjtjBd}Wnty<tdYdS0d}d}|tD]}zt ||\}}}WntyYqYn0|rR|tj krRt j |rRztt|}WnttfyYqRYn0|dkrR||krR||}}qRWdn1s0Y||fS)Nz'Software\Microsoft\VisualStudio\SxS\VC7)accesszVisual C++ is not registeredNNr)winreg OpenKeyExHKEY_LOCAL_MACHINEKEY_READKEY_WOW64_32KEYOSErrorr debugr EnumValueREG_SZospathisdirintfloat ValueError TypeError)key best_versionbest_dirivZvc_dirZvtversionr&DC:\Program Files\Certbot\pkgs\setuptools\_distutils\_msvccompiler.py _find_vc2015's2       ,r(c Cstjdptjd}|s dSz8tjtj|dddddd d d d d dg ddd}Wntjt t fytYdS0tj|ddd}tj |rd|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*mbcsstrict)encodingerrorsZVCZ AuxiliaryZBuild) renvironget subprocess check_outputrjoinstripCalledProcessErrorrUnicodeDecodeErrorr)rootrr&r&r' _find_vc2017Ds4   r8x86Zx64ZarmZarm64)r9 x86_amd64x86_arm x86_arm64cCs\t\}}|st\}}|s*tddStj|d}tj|sTtd|dS|dfS)Nz$No suitable Visual C++ version foundrz vcvarsall.batz%s cannot be found)r8r(r rrrr3isfile) plat_spec_r"r! vcvarsallr&r&r'_find_vcvarsallvs     rAc CstdrddtjDSt|\}}|s6tdz,tjd|d|dtjdj d d d }WnBtj y}z(t |j td |jWYd}~n d}~00d ddd|DD}|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-16lereplace)r-zError executing cSs$i|]\}}}|r|r||qSr&rB)rDr r?rEr&r&r'rFscss|]}|dVqdS)=N) partition)rDliner&r&r' rGz_get_vc_env..)rgetenvr/itemsrArr1r2ZSTDOUTdecoder5r erroroutputcmd splitlines)r>r@r?outexcenvr&r&r' _get_vc_envs&    &rXcCsN|stdtj}|D].}tjtj||}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)rrNsplitpathseprr3abspathr=)Zexepathspfnr&r&r' _find_exes   r_r:r;r<)win32z win-amd64z win-arm32z win-arm64c seZdZdZdZiZdgZgdZdgZdgZ eeee Z dZ dZ d Z d Zd ZZd Zd+fdd ZeddZeddZd,ddZefddZd-ddZd.ddZd/ddZfdd Zejfd!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)selfverbosedry_runforce __class__r&r'rdszMSVCCompiler.__init__cCs,||dd|_||dd|_dS)z3 Set class-level include/lib dirs. ZincludelibN) _parse_pathr0 include_dirs library_dirs)clsvc_envr&r&r' _configureszMSVCCompiler._configurecCsdd|tjDS)NcSsg|]}|r|tjqSr&)rstriprsep)rDdirr&r&r' rGz,MSVCCompiler._parse_path..)rYrrZ)valr&r&r'roszMSVCCompiler._parse_pathNcCs|jrJd|durt}|tvr6tdttt|}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|ddd|_g|ddd|_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_VCVARSrtuplerXrtr0_pathsrYrrZr_cclinkerrnrcmcmtZpreprocess_optionscompile_optionscompile_options_debugZ ldflags_exeZldflags_exe_debugZldflags_sharedZldflags_shared_debugZldflags_staticZldflags_static_debugrZ EXECUTABLEZ SHARED_OBJECTZSHARED_LIBRARY_ldflags)rgrer>rsr\ldflagsZ ldflags_debugr&r&r' initializesx                      zMSVCCompiler.initializecs&itjfddjjDS)Ncsi|] }|jqSr&) res_extension)rDextrgr&r'rFEsz/MSVCCompiler.out_extensions..)rcout_extensions_rc_extensions_mc_extensionsrrkrr'rAs  zMSVCCompiler.out_extensionsc  Cs|js||||||||} | \}} }} } |p6g} | d|rT| |jn | |jd}| D]}z| |\}}WntyYqhYn0|rtj |}||j vrd|}nL||j vrd|}d}n2||j vr@|}d|}z||jg| ||gWqhty:}zt|WYd}~qhd}~00qhn||jvrtj |}tj |}z\||jd|d||gtj tj |\}}tj ||d }||jd||gWqhty}zt|WYd}~qhd}~00qhntd |d ||jg| | }|r(|d ||d |f||z||Wqhty}zt|WYd}~qhd}~00qh| S)Nz/cFz/Tcz/TpTz/foz-hz-rrbzDon't know how to compile z to z/EHscz/Fo)rfrZ_setup_compileappendextendrrKeyErrorrrr[ _c_extensions_cpp_extensionsrspawnrrrrdirnamersplitextbasenamer3r)rgZsources output_dirZmacrosrpr extra_preargsextra_postargsZdependsZ compile_infoobjectsZpp_optsbuildZ compile_optsZ add_cpp_optsobjsrcrZ input_optZ output_optmsgZh_dirZrc_dirbaser?Zrc_fileargsr&r&r'compileKsl                 zMSVCCompiler.compilec Cs|js||||\}}|j||d}|||r|d|g}|rJz,td|jd|| |jg|Wqt y}zt |WYd}~qd}~00n td|dS)N)r/OUT:Executing "%s" %s skipping %s (up-to-date)) rfr_fix_object_argslibrary_filename _need_linkr rrnr3rrr) rgrZoutput_libnamerr target_langoutput_filenameZlib_argsrr&r&r'create_static_libs  zMSVCCompiler.create_static_libc Cs|js||||\}}||||}|\}}}|rL|dt|t||||}|durptj ||}| ||r|j || f}dd|pgD}||||d|g}tj |d} |dur tj tj|\}}tj | ||}|d|| r| |dd<| r.|| tj tj|}||z,td|jd |||jg|Wn.ty}zt|WYd}~n d}~00n td |dS) Nz5I don't know what to do with 'runtime_library_dirs': cSsg|] }d|qS)z/EXPORT:r&)rDZsymr&r&r'rxrGz%MSVCCompiler.link..rrz/IMPLIB:rrr)rfrrZ _fix_lib_argswarnstrr rrr3rrrrrrrrr[Zmkpathr rrrrr)rgZ target_descrrrZ librariesrqZruntime_library_dirsZexport_symbolsrrrZ build_temprZ fixed_argsZlib_optsrZ export_optsZld_argsZdll_nameZdll_extZ implib_filerr&r&r'linksL        zMSVCCompiler.linkcsRttj|jd}||| }tj||dWdS1sB0Y|jS)N)PATH)rW)dictrr/r_fallback_spawnrcrrE)rgrSrWfallbackrkr&r'rs.zMSVCCompiler.spawnc #stddi}z |VWn2tyJ}zdt|vr6WYd}~nd}~00dStdtjd|t ||_ Wdn1s0YdS)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) typerrwarningsrmockZpatchrrcrrE)rgrSrWZbagrVrkr&r'rs   zMSVCCompiler._fallback_spawncCsd|S)Nz /LIBPATH:r&rgrwr&r&r'library_dir_optionszMSVCCompiler.library_dir_optioncCs tddS)Nz:don't know how to set runtime library search path for MSVC)rrr&r&r'runtime_library_dir_option"sz'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)rrr3rr=)rgdirsrnrZ try_namesrwnameZlibfiler&r&r'find_library_file*s zMSVCCompiler.find_library_file)rrr)N)NNNrNNN)NrN) NNNNNrNNNN)r)&__name__ __module__ __qualname____doc__Z compiler_typeZ executablesrrrrZsrc_extensionsrZ obj_extensionZstatic_lib_extensionZshared_lib_extensionZstatic_lib_formatZshared_lib_formatZ exe_extensionrd classmethodrt staticmethodrorpropertyrrrrr contextlibcontextmanagerrrrrr __classcell__r&r&rkr'rasd   R  _  E ra)N)!rrr1rrZ unittest.mockrsuppress ImportErrorrr-rrrrrZ ccompilerrr Z_logr utilr itertoolsr r(r8ZPLAT_SPEC_TO_RUNTIMErArXr_r~rar&r&r&r's8  &   +