B ‰qOA%ã@sÄdZddlZddlZddlZddlZddlZddlmZmZm Z m Z m Z ddl m Z mZddlmZddlmZddlmZdd „Zd d „Zd d „Zdd„Zddd„Zdddœ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 CsüytjtjdtjtjBd}Wntk r<t d¡dSXd}d}|¤xœtƒD]’}yt  ||¡\}}}Wntk r„PYnX|rT|tj krTt j   |¡rTytt|ƒƒ}Wnttfk rÊwTYnX|dkrT||krT||}}qTWWdQRX||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ú:/opt/alt/python37/lib/python3.7/distutils/_msvccompiler.pyÚ _find_vc2015s0  r!c Cs¨ddl}tj d¡ptj d¡}|s(dSy8tjtj |ddd¡d d d d d dddg ddd ¡}Wntj t t fk r|dSXtj |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. rNzProgramFiles(x86)Z ProgramFiles)NNzMicrosoft Visual StudioZ Installerz vswhere.exez-latestz -prereleasez -requiresz1Microsoft.VisualStudio.Component.VC.Tools.x86.x64z -propertyZinstallationPathz -productsÚ*ÚmbcsÚstrict)ÚencodingÚerrorsZVCZ AuxiliaryZBuildé) ÚjsonrÚenvironÚgetÚ subprocessÚ check_outputrÚjoinÚstripÚCalledProcessErrorrÚUnicodeDecodeErrorr)r(Úrootrrrr Ú _find_vc2017:s&  r2cCs\tƒ\}}|stƒ\}}|s*t d¡dStj |d¡}tj |¡sTt d|¡dS|dfS)Nz$No suitable Visual C++ version found)NNz vcvarsall.batz%s cannot be found)r2r!r rrrr-Úisfile)Ú plat_specÚ_rrÚ vcvarsallrrr Ú_find_vcvarsall\s     r7c Cs¾t d¡rdd„tj ¡DƒSt|ƒ\}}|s6tdƒ‚y&tjd ||¡tj dj ddd }Wn@tj k rœ}z t   |j¡td  |j¡ƒ‚Wdd}~XYnXd d„d d „| ¡DƒDƒ}|S)NZDISTUTILS_USE_SDKcSsi|]\}}|| ¡“qSr)Úlower)Ú.0rÚvaluerrr ú psz_get_vc_env..zUnable to find vcvarsall.batzcmd /u /c "{}" {} && set)Ústderrzutf-16leÚreplace)r&zError executing {}cSs$i|]\}}}|r|r|| ¡“qSr)r8)r9rr5r:rrr r;ƒscss|]}| d¡VqdS)ú=N)Ú partition)r9Úlinerrr ú †sz_get_vc_env..)rÚgetenvr)Úitemsr7rr+r,ÚformatZSTDOUTÚdecoder/r ÚerrorÚoutputÚcmdÚ splitlines)r4r6r5ÚoutÚexcÚenvrrr Ú _get_vc_envns$     rMcCsN|st d¡ tj¡}x2|D]*}tj tj |¡|¡}tj |¡r|SqW|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)rrBÚsplitÚpathseprr-Úabspathr3)ZexeÚpathsÚpÚfnrrr Ú _find_exeŒs   rTZx86Z x86_amd64)Zwin32z win-amd64c sÎeZdZdZdZiZdgZdddgZdgZdgZ eeee Z d Z d Z d Z d Zd ZZdZd(dd„Zd)dd„Zd*dd„Zd+dd„Zd,dd„Zd-dd„Z‡fdd„Zd d!„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.cz.ccz.cppz.cxxz.rcz.mcz.resz.objz.libz.dllz%s%sz.exercCs t ||||¡d|_d|_dS)NF)rÚ__init__Ú plat_nameÚ initialized)ÚselfÚverboseZdry_runZforcerrr rVÄszMSVCCompiler.__init__NcCs|jrtdƒ‚|dkrtƒ}|tkr6td ttƒ¡ƒ‚t|}t|ƒ}|sRtdƒ‚| dd¡|_ |j   t j ¡}t d|ƒ|_t d|ƒ|_t d|ƒ|_t d |ƒ|_t d |ƒ|_t d |ƒ|_x2| d d¡  t j ¡D]}|rÌ| | t j¡¡qÌWx6| d d¡  t j ¡D]}|r| | t j¡¡qWd|_ddddddg|_ddddddg|_dddg}ddddg}|d!•|_|d"•|_|d#•|_|d$•|_|•|_|•|_ t!j"df|jt!j"df|jt!j"d f|jt!j#df|jt!j#df|jt!j#d f|jt!j$df|jt!j$df|jt!j$d f|j i |_%d |_dS)%Nzdon't init multiple timesz--plat-name must be one of {}z7Unable to find a compatible Visual Studio installation.rÚzcl.exezlink.exezlib.exezrc.exezmc.exezmt.exeZincludeÚlibz/nologoz/Oxz/W3z/GLz/DNDEBUGz/MDz/Odz/MDdz/Ziz/D_DEBUGz/INCREMENTAL:NOz/LTCGz /DEBUG:FULLú/MANIFEST:EMBED,ID=1ú/DLLú/MANIFEST:EMBED,ID=2ú/MANIFESTUAC:NOFT)r])r])r^r_r`)r^r_r`)&rXÚAssertionErrorr ÚPLAT_TO_VCVARSrrDÚtuplerMr*Ú_pathsrNrrOrTÚccÚlinkerr\ÚrcÚmcZmtZadd_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Ú_ldflags)rYrWr4Zvc_envrQÚdirÚldflagsZ ldflags_debugrrr Ú initializeÊsZ                     zMSVCCompiler.initializer[csT‡fdd„ˆjDƒ‡fdd„ˆjˆjDƒ–‰ˆp4d‰‡‡‡fdd„}tt||ƒƒS)Ncsi|] }ˆj|“qSr)Ú obj_extension)r9Úext)rYrr r;sz1MSVCCompiler.object_filenames..csi|] }ˆj|“qSr)Ú res_extension)r9rr)rYrr r;sr[cs’tj |¡\}}ˆr"tj |¡}n2tj |¡\}}| tjjtjjf¡rT|dd…}ytj ˆ|ˆ|¡St k rŒt d  |¡ƒ‚YnXdS)NézDon't know how to compile {}) rrÚsplitextÚbasenameÚ splitdriveÚ startswithrjÚaltsepr-Ú LookupErrorrrD)rRÚbaserrr5)Úext_mapÚ output_dirÚ strip_dirrr Ú make_out_path#s z4MSVCCompiler.object_filenames..make_out_path)Úsrc_extensionsÚ_rc_extensionsÚ_mc_extensionsÚlistÚmap)rYZsource_filenamesr~r}rr)r|r}rYr~r Úobject_filenamess zMSVCCompiler.object_filenamesc  CsŠ|js| ¡| ||||||¡} | \}} }} } |p6g} |  d¡|rT|  |j¡n |  |j¡d}x| D]}y| |\}}Wntk r˜wlYnX|rªtj   |¡}||j krÀd|}nD||j krÚd|}d}n*||j krB|}d|}y| |jg| ||g¡Wqltk r<}z t|ƒ‚Wdd}~XYqlXqlnÂ||jkrôtj  |¡}tj  |¡}y\| |jd|d||g¡tj  tj  |¡¡\}}tj  ||d ¡}| |jd||g¡Wqltk rî}z t|ƒ‚Wdd}~XYqlXqlntd  ||¡ƒ‚|jg| | }|r$| d ¡| |¡| d |¡| |¡y| |¡Wqltk r€}z t|ƒ‚Wdd}~XYqlXqlW| S) Nz/cFz/Tcz/TpTz/foz-hz-rz.rcz"Don't know how to compile {} to {}z/EHscz/Fo)rXrpZ_setup_compileÚappendÚextendrlrkÚKeyErrorrrrPÚ _c_extensionsÚ_cpp_extensionsrÚspawnrgrrr‚Údirnamerhrurvr-rDre)rYZsourcesr}ZmacrosZ include_dirsrÚ extra_preargsÚextra_postargsZdependsZ compile_infoÚobjectsZpp_optsZbuildZ compile_optsZ add_cpp_optsÚobjÚsrcrrZ input_optZ output_optÚmsgZh_dirZrc_dirr{r5Zrc_fileÚargsrrr Úcompile9sn               zMSVCCompiler.compilec Cs´|js| ¡| ||¡\}}|j||d}| ||¡r¤|d|g}|rJy,t d|jd |¡¡|  |jg|¡Wq°t k r }z t |ƒ‚Wdd}~XYq°Xn t d|¡dS)N)r}z/OUT:zExecuting "%s" %sú zskipping %s (up-to-date)) rXrpÚ_fix_object_argsÚlibrary_filenameÚ _need_linkr rr\r-r‹rr) rYrZoutput_libnamer}rÚ target_langÚoutput_filenameZlib_argsr’rrr Úcreate_static_lib“s zMSVCCompiler.create_static_libc Cs¸|js| ¡| ||¡\}}| |||¡}|\}}}|rL| dt|ƒ¡t||||ƒ}|dk rptj  ||¡}|  ||¡r¨|j || f}dd„|p˜gDƒ}||||d|g}tj  |d¡} |dk r tj  tj |¡¡\}}tj  | | |¡¡}| d|¡| r| |dd…<| r.| | ¡tj  tj |¡¡}| |¡y,t d|jd  |¡¡| |jg|¡Wn,tk r¤}z t|ƒ‚Wdd}~XYnXn t d |¡dS) Nz5I don't know what to do with 'runtime_library_dirs': cSsg|] }d|‘qS)z/EXPORT:r)r9Zsymrrr ú Ðsz%MSVCCompiler.link..z/OUT:rz/IMPLIB:zExecuting "%s" %sr•zskipping %s (up-to-date))rXrpr–Z _fix_lib_argsÚwarnÚstrrrrr-r˜rmrŒrurvr—r†r‡rPZmkpathr rrfr‹rr)rYZ target_descrršr}Z librariesZ library_dirsZruntime_library_dirsZexport_symbolsrrrŽZ build_tempr™Z fixed_argsZlib_optsroZ export_optsZld_argsZdll_nameZdll_extZ implib_filer’rrr Úlink­sL       zMSVCCompiler.linkc s4t d¡}z|jtjd<tƒ |¡S|tjd<XdS)Nr)rrBrdr)Úsuperr‹)rYrHZold_path)Ú __class__rr r‹òs    zMSVCCompiler.spawncCsd|S)Nz /LIBPATH:r)rYrnrrr Úlibrary_dir_optionþszMSVCCompiler.library_dir_optioncCs tdƒ‚dS)Nz:don't know how to set runtime library search path for MSVC)r)rYrnrrr Úruntime_library_dir_optionsz'MSVCCompiler.runtime_library_dir_optioncCs | |¡S)N)r—)rYr\rrr Úlibrary_optionszMSVCCompiler.library_optioncCs`|r|d|g}n|g}xB|D]6}x0|D](}tj || |¡¡}tj |¡r(|Sq(WqWdSdS)NZ_d)rrr-r—r3)rYÚdirsr\rZ try_namesrnÚnameZlibfilerrr Úfind_library_files    zMSVCCompiler.find_library_file)rrr)N)rr[)NNNrNNN)NrN) NNNNNrNNNN)r)Ú__name__Ú __module__Ú __qualname__Ú__doc__Z compiler_typeZ executablesr‰rŠrr‚r€rsrqZstatic_lib_extensionZshared_lib_extensionZstatic_lib_formatZshared_lib_formatZ exe_extensionrVrpr…r”r›rŸr‹r¢r£r¤r§Ú __classcell__rr)r¡r rU¥sL   P  [  8 rU)N)r«rZshutilÚstatr+rZdistutils.errorsrrrrrZdistutils.ccompilerrrZ distutilsr Zdistutils.utilr Ú itertoolsr r!r2r7rMrTrbrUrrrr Ús$   "