U e5dRN@sddlZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z m Z ddlmZddlmZddlmZddZd d Zd d d ddZddZddZdddZd ddddZGddde ZdS)N)DistutilsExecErrorDistutilsPlatformError CompileErrorLibError LinkError) CCompilergen_lib_options)log) get_platform)countc CsztjtjdtjtjBd}Wn tk r>tdYdSXd}d}|tD]}zt ||\}}}Wntk rYqYnX|rT|tj krTt j |rTztt|}Wnttfk rYqTYnX|dkrT||krT||}}qTW5QRX||fS)Nz'Software\Microsoft\VisualStudio\SxS\VC7)accesszVisual C++ is not registeredNNr)winregZ OpenKeyExHKEY_LOCAL_MACHINEZKEY_READZKEY_WOW64_32KEYOSErrorr debugr Z EnumValueZREG_SZospathisdirintfloat ValueError TypeError)key best_versionbest_dirivZvc_dirZvtversionr //usr/lib64/python3.8/distutils/_msvccompiler.py _find_vc2015s2     r"c Csddl}tjdptjd}|s(dSz8tjtj|ddddd d d d d ddg ddd}Wntj t t fk r~YdSXtj|ddd}tj |rd|fSdS)NrzProgramFiles(x86)Z ProgramFilesr zMicrosoft Visual StudioZ Installerz vswhere.exez-latestz -prereleasez -requiresz1Microsoft.VisualStudio.Component.VC.Tools.x86.x64z -propertyZinstallationPathz -products*mbcsstrict)encodingerrorsZVCZ AuxiliaryZBuild) jsonrenvironget subprocess check_outputrjoinstripCalledProcessErrorrUnicodeDecodeErrorr)r)rootrr r r! _find_vc2017:s2  r3x86Zx64ZarmZarm64)r4 x86_amd64x86_arm x86_arm64cCs\t\}}|st\}}|s*tddStj|d}tj|sTtd|dS|dfS)Nz$No suitable Visual C++ version foundr z vcvarsall.batz%s cannot be found)r3r"r rrrr.isfile) plat_spec_rr vcvarsallr r r!_find_vcvarsallcs     r<c CstdrddtjDSt|\}}|s6tdz&tjd||tj dj ddd }Wn@tj k r}z t |jtd |jW5d}~XYnXd dd d |DD}|S)NZDISTUTILS_USE_SDKcSsi|]\}}||qSr lower).0rvaluer r r! wsz_get_vc_env..zUnable to find vcvarsall.batzcmd /u /c "{}" {} && set)stderrzutf-16lereplace)r'zError executing {}cSs$i|]\}}}|r|r||qSr r=)r?rr:r@r r r!rAs css|]}|dVqdS)=N) partition)r?liner r r! sz_get_vc_env..)rgetenvr*itemsr<rr,r-formatZSTDOUTdecoder0r erroroutputcmd splitlines)r9r;r:outexcenvr r r! _get_vc_envus0     rScCsN|stdtj}|D].}tjtj||}tj|r|Sq|SNr)rrHsplitpathseprr.abspathr8)Zexepathspfnr r r! _find_exes   r[r5r6r7)Zwin32z win-amd64z win-arm32z win-arm64c seZdZdZiZdgZdddgZdgZdgZeeeeZ dZ d Z d Z d Z d ZZd Zd'ddZd(ddZd)ddZd*ddZd+ddZd,ddZfddZdd Zd!d"Zd#d$Zd-d%d&ZZS). MSVCCompilerZmsvcz.cz.ccz.cppz.cxx.rcz.mcz.resz.objz.libz.dllz%s%sz.exercCs t||||d|_d|_dS)NF)r__init__ plat_name initialized)selfverboseZdry_runZforcer r r!r^szMSVCCompiler.__init__NcCs|dkrt}|tkr(tdttt|}t|}|sDtd|dd|_|jt j }t d||_ t d||_ t d||_t d||_t d ||_t d ||_|d dt j D]}|r||t jq|d dt j D]}|r||t jqd|_d dddddg|_d dddddg|_d ddg}d dddg}|d |_|d!|_|d"|_|d#|_||_||_tj df|jtj df|jtj df|jtj!df|jtj!df|jtj!df|jtj"df|jtj"df|jtj"df|ji |_#d|_$dS)$Nz--plat-name must be one of {}z7Unable to find a compatible Visual Studio installation.rzcl.exezlink.exezlib.exezrc.exezmc.exezmt.exeZincludelibz/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)re)re)rfrgrh)rfrgrh)%r PLAT_TO_VCVARSrrJtuplerSr+_pathsrUrrVr[cclinkerrdrcmcZmtZadd_include_dirrstripsepZadd_library_dirZpreprocess_optionscompile_optionscompile_options_debugZ ldflags_exeZldflags_exe_debugZldflags_sharedZldflags_shared_debugZldflags_staticZldflags_static_debugrZ EXECUTABLEZ SHARED_OBJECTZSHARED_LIBRARY_ldflagsr`)rar_r9Zvc_envrXdirldflagsZ ldflags_debugr r r! initializes           zMSVCCompiler.initializerccsTfddjDfddjjDp4dfdd}tt||S)Ncsi|] }|jqSr ) obj_extensionr?extrar r!rA&sz1MSVCCompiler.object_filenames..csi|] }|jqSr ) res_extensionryr{r r!rA'srccstj|\}}r"tj|}n2tj|\}}|tjjtjjfrT|dd}ztj||WSt k rt d |YnXdS)NzDon't know how to compile {}) rrsplitextbasename splitdrive startswithrqaltsepr. LookupErrorrrJ)rYbaserzr:)ext_map output_dir strip_dirr r! make_out_path,s z4MSVCCompiler.object_filenames..make_out_path)src_extensions_rc_extensions_mc_extensionslistmap)raZsource_filenamesrrrr )rrrarr!object_filenames!s zMSVCCompiler.object_filenamesc  Cs|js||||||||} | \}} }} } |p6g} | d|rT| |jn | |jd}| D]}z| |\}}Wntk rYqhYnX|rtj |}||j krd|}nD||j krd|}d}n*||j kr@|}d|}z||jg| ||gWqhtk r:}z t|W5d}~XYqhXqhn||jkrtj |}tj |}z\||jd|d||gtj tj |\}}tj ||d }||jd||gWqhtk r}z t|W5d}~XYqhXqhntd |||jg| | }|r"|d |||d |||z||Wqhtk r~}z t|W5d}~XYqhXqh| S) Nz/cFz/Tcz/TpTz/foz-hz-rr]z"Don't know how to compile {} to {}z/EHscz/Fo)r`rwZ_setup_compileappendextendrsrrKeyErrorrrrW _c_extensions_cpp_extensionsrspawnrnrrrdirnameror~rr.rJrl)raZsourcesrZmacrosZ include_dirsr extra_preargsextra_postargsZdependsZ compile_infoobjectsZpp_optsZbuildZ compile_optsZ add_cpp_optsobjsrcrzZ input_optZ output_optmsgZh_dirZrc_dirrr:Zrc_fileargsr r r!compileBsx               zMSVCCompiler.compilec Cs|js||||\}}|j||d}|||r|d|g}|rJz,td|jd|| |jg|Wqt k r}z t |W5d}~XYqXn td|dS)N)r/OUT:Executing "%s" %s skipping %s (up-to-date)) r`rw_fix_object_argslibrary_filename _need_linkr rrdr.rrr) rarZoutput_libnamerr target_langoutput_filenameZlib_argsrr r r!create_static_libs zMSVCCompiler.create_static_libc Cs|js||||\}}||||}|\}}}|rL|dt|t||||}|dk rptj ||}| ||r|j || f}dd|pgD}||||d|g}tj |d} |dk r tj tj|\}}tj | ||}|d|| r| |dd<| r.|| tj tj|}||z,td|jd |||jg|Wn,tk r}z t|W5d}~XYnXn td |dS) Nz5I don't know what to do with 'runtime_library_dirs': cSsg|] }d|qS)z/EXPORT:r )r?Zsymr r r! sz%MSVCCompiler.link..rrz/IMPLIB:rrr)r`rwrZ _fix_lib_argswarnstrrrrr.rrtrr~rrrrrWZmkpathr rrmrrr)raZ target_descrrrZ librariesZ library_dirsZruntime_library_dirsZexport_symbolsrrrZ build_temprZ fixed_argsZlib_optsrvZ export_optsZld_argsZdll_nameZdll_extZ implib_filerr r r!links`       zMSVCCompiler.linkc s8td}z|jtjd<t|WS|tjd<XdSrT)rrHr*rksuperr)rarNZold_path __class__r r!rs   zMSVCCompiler.spawncCsd|S)Nz /LIBPATH:r rarur 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)rardr r r!library_optionszMSVCCompiler.library_optioncCs\|r|d|g}n|g}|D]:}|D]0}tj|||}tj|r$|Sq$qdS)NZ_d)rrr.rr8)radirsrdrZ try_namesrunameZlibfiler r r!find_library_files zMSVCCompiler.find_library_file)rrr)N)rrc)NNNrNNN)NrN) NNNNNrNNNN)r)__name__ __module__ __qualname__Z compiler_typeZ executablesrrrrrr|rxZstatic_lib_extensionZshared_lib_extensionZstatic_lib_formatZshared_lib_formatZ exe_extensionr^rwrrrrrrrrr __classcell__r r rr!r\sd   P " ]  E r\)N)rZshutilstatr,rZdistutils.errorsrrrrrZdistutils.ccompilerrrZ distutilsr Zdistutils.utilr itertoolsr r"r3ZPLAT_SPEC_TO_RUNTIMEr<rSr[rir\r r r r!s2   #