U ÙAT^«Uc@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)ZaccesszVisual C++ is not registered©NNri)ÚwinregZ OpenKeyExZHKEY_LOCAL_MACHINEZKEY_READZKEY_WOW64_32KEYÚOSErrorrÚdebugr Z EnumValueZREG_SZÚosÚpathÚisdirZintZfloatZ ValueErrorZ TypeError)ÚkeyÚ best_versionÚbest_dirZiZvZvc_dirZvtZversion©rú//usr/lib64/python3.8/distutils/_msvccompiler.pyÚ _find_vc2015s2 ý     rc 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 -productsZ*ZmbcsZstrict)ZencodingÚerrorsZVCZ AuxiliaryZBuildi) ÚjsonrÚenvironÚgetÚ subprocessÚ check_outputrÚjoinZstripÚCalledProcessErrorr ZUnicodeDecodeErrorr)rZrootrrrrÚ _find_vc2017:s2 úù r Úx86Úx64ZarmZarm64)r!Ú 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)NZamd64r"r!z..ZredistZMSVCz**zMicrosoft.VC14*.CRTúvcruntime140.dllrT)Z recursiveiÿÿÿÿzMicrosoft.VC140.CRTz$No suitable Visual C++ version foundr z vcvarsall.batz%s cannot be found) r ÚPLAT_SPEC_TO_RUNTIMErrrÚglobZ ImportErrorr Ú LookupErrorrrrÚisfile) Ú plat_specÚ_rÚ vcruntimeZvcruntime_platZvcredistr(rÚ vcvarsallrrrÚ_find_vcvarsallcsD  ÿ   ÿ    r/c 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ÚvaluerrrÚ Œsÿz_get_vc_env..zUnable to find vcvarsall.batzcmd /u /c "{}" {} && set)Zstderrzutf-16leZreplace)rzError executing {}cSs$i|]\}}}|r|r| ¡|“qSrr0)r2rr,r3rrrr4Ÿs ýcss|]}| d¡VqdS)z=N)Z partition)r2ZlinerrrZ ¢sz_get_vc_env..Úpy_vcruntime_redist)rÚgetenvrZitemsr/rrrÚformatZSTDOUTZdecoderrZerrorZoutputÚcmdZ splitlines)r+r.r-ZoutZexcZenvrrrÚ _get_vc_envŠs4 þ  þý  ÿýr9cCsN|st d¡ tj¡}|D].}tj tj |¡|¡}tj |¡r|Sq|S©Nr)rr6ÚsplitÚpathseprrÚabspathr*)ZexeÚpathsÚpZfnrrrÚ _find_exeªs   r@r#r$r%)Zwin32z win-amd64z win-arm32z win-arm64r&c 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)ÚselfZverboseZdry_runZforcerrrrCê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.exer5ZincludeÚ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©rIrM©rJrKrLrN)(r ÚPLAT_TO_VCVARSrr7Ztupler9rÚ_pathsr;rr<r@ÚccÚlinkerrHÚrcÚmcZmtÚ_vcruntime_redistZadd_include_dirZrstripÚ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Ú_ldflagsrE)rFrDr+Zvc_envr>ÚdirÚldflagsZ ldflags_debugrrrÚ initializeðsšÿ      ÿÿÿ ÿ    ÷ zMSVCCompiler.initializerGcsT‡fdd„ˆjDƒ‡fdd„ˆjˆjDƒ–‰ˆp4d‰‡‡‡fdd„}tt||ƒƒS)Ncói|] }|ˆj“qSr)Ú obj_extension©r2Úext©rFrrr4Góz1MSVCCompiler.object_filenames..cr_r)Ú res_extensionrarcrrr4HrdrGcs”tj |¡\}}ˆr"tj |¡}n2tj |¡\}}| tjjtjjf¡rT|dd…}ztj ˆ|ˆ|¡WSt k rŽt d  |¡ƒ‚YnXdS)NizDon't know how to compile {}) rrÚsplitextÚbasenameZ splitdriveZ startswithrVZaltseprr)rr7)r?Úbaserbr,)Úext_mapÚ output_dirÚ strip_dirrrÚ make_out_pathMs z4MSVCCompiler.object_filenames..make_out_path)Úsrc_extensionsÚ_rc_extensionsÚ_mc_extensionsZlistZmap)rFZsource_filenamesrkrjrlr)rirjrFrkrÚ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-rrBz"Don't know how to compile {} to {}z/EHscz/Fo)rEr^Z_setup_compilerXrZrYrWZKeyErrorrrr=Ú _c_extensionsÚ_cpp_extensionsrnÚspawnrSrrroÚdirnamerTrfrgrr7rQ)rFZsourcesrjZmacrosZ include_dirsrÚ extra_preargsÚextra_postargsZdependsZ compile_infoÚobjectsZpp_optsZbuildZ compile_optsZ add_cpp_optsZobjZsrcrbZ input_optZ output_optÚmsgZh_dirZrc_dirrhr,Zrc_fileZargsrrrÚ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)rjú/OUT:úExecuting "%s" %sú úskipping %s (up-to-date)) rEr^Ú_fix_object_argsÚlibrary_filenameÚ _need_linkrrrHrrsrr) rFrwZoutput_libnamerjrÚ target_langÚoutput_filenameZlib_argsrxrrrÚ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)r2ZsymrrrZ úsz%MSVCCompiler.link..rzrz/IMPLIB:r{r|r})rEr^r~Z _fix_lib_argsZwarnZstrrrrrr€r[rtrfrgrrXrZr=ZmkpathrrrRrsÚ_copy_vcruntimerr)rFZ target_descrwr‚rjZ librariesZ library_dirsZruntime_library_dirsZexport_symbolsrrurvZ build_temprZ fixed_argsZlib_optsr]Z export_optsZld_argsZdll_nameZdll_extZ implib_filerxrrrÚlink×sbÿ ÿþ ÿÿ  ÿþ   zMSVCCompiler.linkcCs\|j}|rtj |¡sdStj |¡ ¡tkr2dSt d|¡t   ||¡}t  |t j ¡dS)Nz Copying "%s")rUrrr*rgr1Ú _BUNDLED_DLLSrrÚshutilZcopyZchmodÚstatZS_IWRITE)rFrjr-rrrr„s  zMSVCCompiler._copy_vcruntimec s8t d¡}z|jtjd<tƒ |¡W¢S|tjd<XdSr:)rr6rrPZsuperrs)rFr8Zold_path©Z __class__rrrs)s   zMSVCCompiler.spawncCsd|S)Nz /LIBPATH:r©rFr\rrrÚlibrary_dir_option5ózMSVCCompiler.library_dir_optioncCs tdƒ‚dS)Nz:don't know how to set runtime library search path for MSVC)rrŠrrrÚruntime_library_dir_option8sÿz'MSVCCompiler.runtime_library_dir_optioncCs | |¡S©N)r)rFrHrrrÚlibrary_option<rŒzMSVCCompiler.library_optioncCs\|r|d|g}n|g}|D]:}|D]0}tj || |¡¡}tj |¡r$|Sq$qdS)NZ_d)rrrrr*)rFZdirsrHrZ try_namesr\ZnameZlibfilerrrÚfind_library_file?s zMSVCCompiler.find_library_file)rrrrŽ)rrG)NNNrNNN)NrN) NNNNNrNNNN)r)Z__name__Z __module__Z __qualname__Z compiler_typeZ executablesrqrrrnrormrer`Zstatic_lib_extensionZshared_lib_extensionZstatic_lib_formatZshared_lib_formatZ exe_extensionrCr^rpryrƒr…r„rsr‹rrrZ __classcell__rrr‰rrAËsf ÿÿ  Tý "þ ]û ó F rArŽ)rr‡rˆrr Zdistutils.errorsrrrrrZdistutils.ccompilerrrZ distutilsrZdistutils.utilr Z itertoolsr rr r'r/r9r@rOZ frozensetr†rArrrrZs4   #ü' ü