U ÙAT^«Uã@sÜddlZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z m Z ddlmZddlmZddlmZdd„Zd d „Zd d d ddœZdd„Zdd„Zddd„Zd ddddœZedgƒZGdd„de ƒZdS)éN)ÚDistutilsExecErrorÚDistutilsPlatformErrorÚ CompileErrorÚLibErrorÚ LinkError)Ú CCompilerÚgen_lib_options)Úlog)Ú get_platform)Úcountc CsztjtjdtjtjBd}Wn tk r>t d¡YdSXd}d}|¦tƒD]˜}zt  ||¡\}}}Wntk rˆYqîYnX|rT|tj krTt j   |¡rTztt|ƒƒ}Wnttfk rÐYqTYnX|dkrT||krT||}}qTW5QRX||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.8/distutils/_msvccompiler.pyÚ _find_vc2015s2 ý     r"c Csªddl}tj d¡ptj d¡}|s(dSz8tjtj |ddd¡dd d d d d ddg ddd ¡}Wntj t t fk r~YdSXtj |ddd¡}tj  |¡r¦d|fSdS)NrzProgramFiles(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é) ÚjsonrÚenvironÚgetÚ subprocessÚ check_outputrÚjoinÚstripÚCalledProcessErrorrÚUnicodeDecodeErrorr)r)Úrootrr r r!Ú _find_vc2017:s2 úù r3Úx86Úx64ZarmZarm64)r4Ú x86_amd64Úx86_armÚ x86_arm64c Cstƒ\}}d}|tkr t|}nd|kr,dnd}|rŽtj |ddddd|dd ¡ }zd dl}|j|d d d }Wntttfk rŒd}YnX|s´t ƒ\}}|r´tj |d|dd ¡}|sÆt   d¡dStj |d¡}tj  |¡sðt   d|¡dS|rtj  |¡st   d|¡d}||fS)NZamd64r5r4z..ZredistZMSVCz**zMicrosoft.VC14*.CRTúvcruntime140.dllrT)Ú recursiveéÿÿÿÿzMicrosoft.VC140.CRTz$No suitable Visual C++ version foundr z vcvarsall.batz%s cannot be found) r3ÚPLAT_SPEC_TO_RUNTIMErrr.ÚglobÚ ImportErrorrÚ LookupErrorr"r rÚisfile) Ú plat_specÚ_rÚ vcruntimeZvcruntime_platZvcredistr=rÚ vcvarsallr r r!Ú_find_vcvarsallcsD  ÿ   ÿ    rEc CsÊt d¡rdd„tj ¡DƒSt|ƒ\}}|s6tdƒ‚z&tjd ||¡tj dj ddd }Wn@tj k rœ}z t   |j¡td  |j¡ƒ‚W5d}~XYnXd d„d d „| ¡DƒDƒ}|rÆ||d<|S)NZDISTUTILS_USE_SDKcSsi|]\}}| ¡|“qSr ©Úlower)Ú.0rÚvaluer r r!Ú Œsÿz_get_vc_env..zUnable to find vcvarsall.batzcmd /u /c "{}" {} && set)Ústderrzutf-16leÚreplace)r'zError executing {}cSs$i|]\}}}|r|r| ¡|“qSr rF)rHrrBrIr r r!rJŸs ýcss|]}| d¡VqdS)ú=N)Ú partition)rHÚliner r r!Ú ¢sz_get_vc_env..Úpy_vcruntime_redist)rÚgetenvr*ÚitemsrErr,r-ÚformatÚSTDOUTÚdecoder0r ÚerrorÚoutputÚcmdÚ splitlines)rArDrCÚoutÚexcÚenvr r r!Ú _get_vc_envŠs4 þ  þý  ÿýr^cCsN|st d¡ tj¡}|D].}tj tj |¡|¡}tj |¡r|Sq|S©Nr)rrRÚsplitÚpathseprr.Úabspathr@)ZexeÚpathsÚpÚfnr r r!Ú _find_exeªs   rfr6r7r8)Úwin32z win-amd64z win-arm32z win-arm64r9c sÒeZdZdZiZdgZdddgZdgZdgZeeeeZ dZ d Z d Z d Z d ZZd Zd)dd„Zd*dd„Zd+dd„Zd,dd„Zd-dd„Zd.dd„Zdd„Z‡fdd „Zd!d"„Zd#d$„Zd%d&„Zd/d'd(„Z‡ZS)0Ú MSVCCompilerZmsvcz.cz.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!rjêszMSVCCompiler.__init__NcCs2|dkrtƒ}|tkr(td ttƒ¡ƒ‚t|}t|ƒ}|sDtdƒ‚| dd¡|_|j t j ¡}t d|ƒ|_ t d|ƒ|_ t d|ƒ|_t d|ƒ|_t d |ƒ|_t d |ƒ|_| d d¡|_| d d¡ t j ¡D]}|rÊ| | t j¡¡qÊ| d d¡ t j ¡D]}|rú| | t j¡¡qúd|_dddddg|_|j |jr>dnd¡ddddddg|_dddg}|jsr| d¡ddddg}|d#•|_|d$•|_|d%•|_|d&•|_|•|_ |•|_!t"j#df|jt"j#d!f|jt"j#d"f|jt"j$df|jt"j$d!f|jt"j$d"f|jt"j%df|j t"j%d!f|j t"j%d"f|j!i |_&d"|_'dS)'Nz--plat-name must be one of {}z7Unable to find a compatible Visual Studio installation.rÚzcl.exezlink.exezlib.exezrc.exezmc.exezmt.exerQZincludeÚlibz/nologoz/Oxz/W3z/GLz/DNDEBUGz/MDz/MTz/Odz/MDdz/Ziz/D_DEBUGz/INCREMENTAL:NOz/LTCG)z/nodefaultlib:libucrt.libzucrt.libz /DEBUG:FULLú/MANIFEST:EMBED,ID=1ú/DLLú/MANIFEST:EMBED,ID=2ú/MANIFESTUAC:NOFT)rs)rs)rtrurv)rtrurv)(r ÚPLAT_TO_VCVARSrrTÚtupler^r+Ú_pathsr`rrarfÚccÚlinkerrrÚrcÚmcÚmtÚ_vcruntime_redistZadd_include_dirÚrstripÚsepZadd_library_dirZpreprocess_optionsÚcompile_optionsÚappendÚcompile_options_debugÚextendZ ldflags_exeZldflags_exe_debugZldflags_sharedZldflags_shared_debugZldflags_staticZldflags_static_debugrZ EXECUTABLEZ SHARED_OBJECTZSHARED_LIBRARYÚ_ldflagsrl)rmrkrAZvc_envrcÚdirÚldflagsZ ldflags_debugr r r!Ú initializeðsšÿ      ÿÿÿ ÿ    ÷ zMSVCCompiler.initializerqcsT‡fdd„ˆjDƒ‡fdd„ˆjˆjDƒ–‰ˆp4d‰‡‡‡fdd„}tt||ƒƒS)Ncsi|] }|ˆj“qSr )Ú obj_extension©rHÚext©rmr r!rJGsz1MSVCCompiler.object_filenames..csi|] }|ˆj“qSr )Ú res_extensionr‹rr r!rJHsrqcs”tj |¡\}}ˆr"tj |¡}n2tj |¡\}}| tjjtjjf¡rT|dd…}ztj ˆ|ˆ|¡WSt k rŽt d  |¡ƒ‚YnXdS)NézDon't know how to compile {}) rrÚsplitextÚbasenameÚ splitdriveÚ startswithrÚaltsepr.r?rrT)rdÚbaserŒrB)Úext_mapÚ output_dirÚ strip_dirr r!Ú make_out_pathMs z4MSVCCompiler.object_filenames..make_out_path)Úsrc_extensionsÚ_rc_extensionsÚ_mc_extensionsÚlistÚmap)rmZsource_filenamesr˜r—r™r )r–r—rmr˜r!Úobject_filenamesBs þzMSVCCompiler.object_filenamesc  Cs†|js| ¡| ||||||¡} | \}} }} } |p6g} |  d¡|rT|  |j¡n |  |j¡d}| D]}z| |\}}Wntk r–YqhYnX|r¨tj   |¡}||j kr¾d|}nD||j krØd|}d}n*||j kr@|}d|}z| |jg| ||g¡Wqhtk r:}z t|ƒ‚W5d}~XYqhXqhnÂ||jkròtj  |¡}tj  |¡}z\| |jd|d||g¡tj  tj  |¡¡\}}tj  ||d ¡}| |jd||g¡Wqhtk rì}z t|ƒ‚W5d}~XYqhXqhntd  ||¡ƒ‚|jg| | }|r"| d ¡| |¡| d |¡| |¡z| |¡Wqhtk r~}z t|ƒ‚W5d}~XYqhXqh| S) Nz/cFz/Tcz/TpTz/foz-hz-rriz"Don't know how to compile {} to {}z/EHscz/Fo)rlr‰Z_setup_compilerƒr…r„r‚ÚKeyErrorrrrbÚ _c_extensionsÚ_cpp_extensionsr›Úspawnr|rrrœÚdirnamer}rr‘r.rTrz)rmZsourcesr—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•rBZrc_fileÚargsr r r!Úcompilecsx ÿ           ÿ   zMSVCCompiler.compilec Cs´|js| ¡| ||¡\}}|j||d}| ||¡r¤|d|g}|rJz,t d|jd |¡¡|  |jg|¡Wq°t k r }z t |ƒ‚W5d}~XYq°Xn t d|¡dS)N)r—ú/OUT:úExecuting "%s" %sú úskipping %s (up-to-date)) rlr‰Ú_fix_object_argsÚlibrary_filenameÚ _need_linkr rrrr.r£rr) rmr§Zoutput_libnamer—rÚ target_langÚoutput_filenameZlib_argsrªr r r!Ú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 |¡¡}| |¡z6t d|jd  |¡¡| |jg|¡| |¡Wn,tk r®}z t|ƒ‚W5d}~XYnXn t d |¡dS) Nz5I don't know what to do with 'runtime_library_dirs': cSsg|] }d|‘qS)z/EXPORT:r )rHZsymr r r!Ú úsz%MSVCCompiler.link..r­rz/IMPLIB:r®r¯r°)rlr‰r±Z _fix_lib_argsÚwarnÚstrrrrr.r³r†r¤rr‘r²rƒr…rbZmkpathr rr{r£Ú_copy_vcruntimerr)rmZ target_descr§rµr—Z librariesZ library_dirsZruntime_library_dirsZexport_symbolsrr¥r¦Z build_tempr´Z fixed_argsZlib_optsrˆZ export_optsZld_argsZdll_nameZdll_extZ implib_filerªr r r!Úlink×sbÿ ÿþ ÿÿ  ÿþ   zMSVCCompiler.linkcCs\|j}|rtj |¡sdStj |¡ ¡tkr2dSt d|¡t   ||¡}t  |t j ¡dS)Nz Copying "%s")rrrr@r‘rGÚ _BUNDLED_DLLSr rÚshutilÚcopyÚchmodÚstatÚS_IWRITE)rmr—rCr r r!rºs  zMSVCCompiler._copy_vcruntimec s8t d¡}z|jtjd<tƒ |¡W¢S|tjd<XdSr_)rrRr*ryÚsuperr£)rmrYZold_path©Ú __class__r r!r£)s   zMSVCCompiler.spawncCsd|S)Nz /LIBPATH:r ©rmr‡r r r!Úlibrary_dir_option5szMSVCCompiler.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_option8sÿz'MSVCCompiler.runtime_library_dir_optioncCs | |¡S)N)r²)rmrrr r r!Úlibrary_option<szMSVCCompiler.library_optioncCs\|r|d|g}n|g}|D]:}|D]0}tj || |¡¡}tj |¡r$|Sq$qdS)NZ_d)rrr.r²r@)rmÚdirsrrrZ try_namesr‡ÚnameZlibfiler r r!Úfind_library_file?s zMSVCCompiler.find_library_file)rrr)N)rrq)NNNrNNN)NrN) NNNNNrNNNN)r)Ú__name__Ú __module__Ú __qualname__Z compiler_typeZ executablesr¡r¢r›rœršrŽrŠZstatic_lib_extensionZshared_lib_extensionZstatic_lib_formatZshared_lib_formatZ exe_extensionrjr‰rŸr¬r¶r»rºr£rÆrÇrÈrËÚ __classcell__r r rÃr!rhËsf ÿÿ  Tý "þ ]û ó F rh)N)rr½rÀr,rZdistutils.errorsrrrrrZdistutils.ccompilerrrZ distutilsr Zdistutils.utilr Ú itertoolsr r"r3r<rEr^rfrwÚ frozensetr¼rhr r r r!Ús4   #ü' ü