3 \KT@sdZddlZddlZddlZddlZddlZddlmZmZm Z m Z m Z ddl m Z mZddlmZddlmZddlmZdd Zd d Zd d ZddZdddZdddZedgZGddde 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)DistutilsExecErrorDistutilsPlatformError CompileErrorLibError LinkError) CCompilergen_lib_options)log) get_platform)countc$CsytjtjdtjtjBd}Wntk r<tjddSXd}d}|xtD]}ytj ||\}}}Wntk rPYnX|rT|tj krTt j j |rTytt|}Wnttfk rwTYnX|dkrT||krT||}}qTWWdQRX||fS)Nz'Software\Microsoft\VisualStudio\SxS\VC7)accesszVisual C++ is not registeredr)NN)winregZ OpenKeyExHKEY_LOCAL_MACHINEZKEY_READZKEY_WOW64_32KEYOSErrorr debugr Z EnumValueZREG_SZospathisdirintfloat ValueError TypeError)key best_versionbest_dirivvc_dirZvtversionr %/usr/lib64/python3.6/_msvccompiler.py _find_vc2015s0  r"c sddlddl}d }d}gfdd}|j|d}|j|jxD]~\}}}}d|krLtjj|ddd} tjj| sqLytd d |j d D} Wnt t fk rwLYnX| |krL| | }}qLWy |d}Wnt k rd}YnX||fS) NrcsjjdS)N)extendfindallr )_distutils_findvs all_packagesr r!_getallDsz_find_vc2017.._getall)targetz1Microsoft.VisualStudio.Component.VC.Tools.x86.x64ZVCZ AuxiliaryZBuildcss|]}t|VqdS)N)r).0rr r r! Psz_find_vc2017...)r) r% threadingZThreadstartjoinrrrtuplesplitrr IndexError) r,rrr'tnameZ version_strrZpackagesrrr )r%r&r! _find_vc2017:s2    r4cCs t\}}d}d|krdnd}|rztjj|ddddddd }yd dl}|j|d d d}Wntttfk rxd}YnX|st\}}|rtjj|d|dd }|st j ddStjj|d}tjj |st j d|dS| ptjj | rt j d|d}||fS)Namd64Zx64x86z..ZredistZMSVCz**zMicrosoft.VC141.CRTzvcruntime140.dllrT) recursivezMicrosoft.VC140.CRTz$No suitable Visual C++ version foundz vcvarsall.batz%s cannot be found)NN)NN) r4rrr.glob ImportErrorr LookupErrorr"r risfile) plat_specrr vcruntimeZvcruntime_platZvcredistr: vcvarsallr r r!_find_vcvarsall[s6        rAcCstjdrddtjjDSt|\}}|s6tdy&tjdj||tj dj ddd }Wn@tj k r}z"t j |jtd j|jWYdd}~XnXd dd d |jDD}|r||d<|S)NZDISTUTILS_USE_SDKcSsi|]\}}||jqSr )lower)r)rvaluer r r! sz_get_vc_env..zUnable to find vcvarsall.batzcmd /u /c "{}" {} && set)stderrzutf-16lereplace)errorszError executing {}cSs$i|]\}}}|r|r||jqSr )rB)r)r_rCr r r!rDscss|]}|jdVqdS)=N) partition)r)liner r r!r*sz_get_vc_env..py_vcruntime_redist)rgetenvenvironitemsrAr subprocessZ check_outputformatZSTDOUTdecodeZCalledProcessErrorr erroroutputcmd splitlines)r>r@r?outexcenvr r r! _get_vc_env}s(     rZcCsN|stjdjtj}x2|D]*}tjjtjj||}tjj|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)rrMr0pathseprr.abspathr=)Zexepathspfnr r r! _find_exes   r`r6Z x86_amd64)Zwin32z win-amd64zvcruntime140.dllc seZdZdZdZiZdgZdddgZdgZdgZ eeee Z d Z d Z d Z d Zd ZZdZd*ddZd+ddZd,ddZd-ddZd.ddZd/ddZddZfd d!Zd"d#Zd$d%Zd&d'Zd0d(d)ZZS)1 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 tj||||d|_d|_dS)NF)r__init__ plat_name initialized)selfverboseZdry_runforcer r r!rbszMSVCCompiler.__init__NcCsN|j std|dkrt}|tkr8tdjttt|}t|}|sTtd|jdd|_ |j j t j }t d||_t d||_t d||_t d ||_t d ||_t d ||_|jd d|_x2|jd dj t j D]}|r|j|jt jqWx6|jddj t j D]}|r|j|jt jqWd|_dddddg|_|jj|jrZdndddddddg|_dddg}|js|jd%ddddg}|d&|_|d'|_|d(|_ |d)|_!||_"||_#t$j%df|jt$j%d#f|jt$j%d$f|jt$j&df|j t$j&d#f|j t$j&d$f|j!t$j'df|j"t$j'd#f|j"t$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.rzcl.exezlink.exezlib.exezrc.exezmc.exezmt.exerLincludelibz/nologoz/Oxz/W3z/GLz/DNDEBUGz/MDz/MTz/Odz/MDdz/Ziz/D_DEBUGz/INCREMENTAL:NOz/LTCG/nodefaultlib:libucrt.libucrt.libz /DEBUG:FULL/MANIFEST:EMBED,ID=1/DLL/MANIFEST:EMBED,ID=2/MANIFESTUAC:NOFT)rkrl)rm)rm)rnrorp)rnrorp))rdAssertionErrorr PLAT_TO_VCVARSrrQr/rZget_pathsr0rr[r`cclinkerrjrcmcZmt_vcruntime_redistZadd_include_dirrstripsepZadd_library_dirZpreprocess_optionscompile_optionsappendcompile_options_debugr#Z ldflags_exeZldflags_exe_debugZldflags_sharedZldflags_shared_debugZldflags_staticZldflags_static_debugrZ EXECUTABLEZ SHARED_OBJECTZSHARED_LIBRARY_ldflags)rercr>Zvc_envr]dirldflagsZ ldflags_debugr r r! initializesb                      zMSVCCompiler.initializerhcsTfddjDfddjjDp4dfdd}tt||S)Ncsi|] }j|qSr ) obj_extension)r)ext)rer r!rD8sz1MSVCCompiler.object_filenames..csi|] }j|qSr ) res_extension)r)r)rer r!rD9srhc stjj|\}}r"tjj|}n2tjj|\}}|jtjjtjjfrT|dd}ytjj||St k rt dj |YnXdS)Nr8zDon't know how to compile {}) rrsplitextbasename splitdrive startswithr{altsepr.r<rrQ)r^baserrH)ext_map output_dir strip_dirr r! make_out_path>s z4MSVCCompiler.object_filenames..make_out_path)src_extensions_rc_extensions_mc_extensionslistmap)reZsource_filenamesrrrr )rrrerr!object_filenames3s zMSVCCompiler.object_filenamesc Cs|js|j|j||||||} | \}} }} } |p6g} | jd|rT| j|jn | j|jd}x| D]}y| |\}}Wntk rwlYnX|rtj j |}||j krd|}nD||j krd|}d}n*||j krB|}d|}y|j|jg| ||gWqltk r<}zt|WYdd}~XqlXqln||jkrtj j|}tj j|}y\|j|jd|d||gtj jtj j|\}}tj j||d }|j|jd||gWqltk r}zt|WYdd}~XqlXqlntd j|||jg| | }|r$|jd |j||jd ||j|y|j|Wqltk r}zt|WYdd}~XqlXqlW| S) Nz/cFz/Tcz/TpTz/foz-hz-rz.rcz"Don't know how to compile {} to {}z/EHscz/Fo)rdrZ_setup_compiler}r#r~r|KeyErrorrrr\ _c_extensions_cpp_extensionsrspawnrwrrrdirnamerxrrr.rQru)reZsourcesrZmacrosZ include_dirsr extra_preargsextra_postargsZdependsZ compile_infoobjectsZpp_optsZbuildZ compile_optsZ add_cpp_optsobjsrcrZ input_optZ output_optmsgZh_dirZrc_dirrrHZrc_fileargsr r r!compileTsn               zMSVCCompiler.compilec Cs|js|j|j||\}}|j||d}|j||r|d|g}|rJy,tjd|jdj||j |jg|Wqt k r}zt |WYdd}~XqXn tjd|dS)N)rz/OUT:zExecuting "%s" %s zskipping %s (up-to-date)) rdr_fix_object_argslibrary_filename _need_linkr rrjr.rrr) rerZoutput_libnamerr target_langoutput_filenameZlib_argsrr r r!create_static_libs zMSVCCompiler.create_static_libcCs|js|j|j||\}}|j|||}|\}}}|rL|jdt|t||||}|dk rptjj ||}|j ||r|j || f}dd|pgD}||||d|g}tjj |d} |dk r tjj tjj|\}}tjj | |j|}|jd|| r| |dd<| r.|j| tjj tjj|}|j|y6tjd|jdj ||j|jg||j|Wn,tk r}zt|WYdd}~XnXn tjd |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..z/OUT:rz/IMPLIB:zExecuting "%s" %srzskipping %s (up-to-date))rdrrZ _fix_lib_argswarnstrrrrr.rrrrrrr}r#r\Zmkpathr rrvr_copy_vcruntimerr)reZ target_descrrrZ librariesZ library_dirsZruntime_library_dirsZexport_symbolsrrrZ build_temprZ fixed_argsZlib_optsrZ export_optsZld_argsZdll_nameZdll_extZ implib_filerr r r!linksN       zMSVCCompiler.linkcCs`|j}| stjj| rdStjj|jtkr6dStjd|t j ||}tj |t j dS)Nz Copying "%s")ryrrr=rrB _BUNDLED_DLLSr rshutilcopychmodstatS_IWRITE)rerr?r r r!rs  zMSVCCompiler._copy_vcruntimec s4tjd}z|jtjd<tj|S|tjd<XdS)Nr)rrMrtrNsuperr)rerUZold_path) __class__r r!rs    zMSVCCompiler.spawncCsd|S)Nz /LIBPATH:r )rerr r r!library_dir_option&szMSVCCompiler.library_dir_optioncCs tddS)Nz:don't know how to set runtime library search path for MSVC)r)rerr r r!runtime_library_dir_option)sz'MSVCCompiler.runtime_library_dir_optioncCs |j|S)N)r)rerjr r r!library_option-szMSVCCompiler.library_optioncCs`|r|d|g}n|g}xB|D]6}x0|D](}tjj||j|}tjj|r(|Sq(WqWdSdS)NZ_d)rrr.rr=)redirsrjrZ try_namesrr3Zlibfiler r r!find_library_file0s    zMSVCCompiler.find_library_file)rrr)N)rrh)NNNrNNN)NrN) NNNNNrNNNN)r)__name__ __module__ __qualname____doc__Z compiler_typeZ executablesrrrrrrrZstatic_lib_extensionZshared_lib_extensionZstatic_lib_formatZshared_lib_formatZ exe_extensionrbrrrrrrrrrrr __classcell__r r )rr!rasN   T  [  9 ra)N)rrrrrPrZdistutils.errorsrrrrrZdistutils.ccompilerrrZ distutilsr Zdistutils.utilr itertoolsr r"r4rArZr`rr frozensetrrar r r r!s&   !"