MMaO@s*dZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z m Z ddlmZddlmZddlZddlmZdd Zd d Zdd d ZddddiZddddddiZedgZGddde 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 $Csy)tjtjddtjtjB}Wn#tk rNtjdd SYnX|d}d}xtD]}ytj ||\}}}Wntk rPYnX|rl|tj krlt j j |rlytt|}Wnttfk rwlYnX|dkrl||krl||}}qlW|sBtjdd St j j|d} t j j| s}tjd| d Sd} tj|} | rt j j|| j|} t j j| stjd| d} | | fSWdQRXdS) Nz'Software\Microsoft\VisualStudio\SxS\VC7accesszVisual C++ is not registeredrz$No suitable Visual C++ version foundz vcvarsall.batz%s cannot be found)NN)NN)NN)winregZ OpenKeyExHKEY_LOCAL_MACHINEZKEY_READZKEY_WOW64_32KEYOSErrorr debugr Z EnumValueZREG_SZospathisdirintfloat ValueError TypeErrorjoinisfile _VCVARS_PLAT_TO_VCRUNTIME_REDISTgetformat) plat_speckeyZ best_versionZbest_dirivZvc_dirZvtversion vcvarsall vcruntimeZvcruntime_specr%Ns z_get_vc_env..zUnable to find vcvarsall.batzcmd /u /c "{}" {} && setstderrzutf-16leerrorsreplacezError executing {}cSs4i|]*\}}}|r|r||jqSr%)r()r)r_r*r%r%r&r+as  css|]}|jdVqdS)=N) partition)r)liner%r%r& dsz_get_vc_env..py_vcruntime_redist)rgetenvenvironitemsr'r subprocessZ check_outputrZSTDOUTdecodeZCalledProcessErrorr erroroutputcmd splitlines)rr#r$outexcenvr%r%r& _get_vc_envLs(    "  rAcCsm|s!tjdjtj}xE|D]=}tjjtjj||}tjj|r(|Sq(W|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)rr5splitpathseprrabspathr)Zexepathspfnr%r%r& _find_exels  !rHwin32Zx86z win-amd64Z x86_amd64z1redist\x86\Microsoft.VC{0}0.CRT\vcruntime{0}0.dllamd64z1redist\x64\Microsoft.VC{0}0.CRT\vcruntime{0}0.dllzvcruntime140.dllc smeZdZdZdZiZdgZdddgZdgZdgZ eeee Z d Z d Z d Z d Zd ZZdZdddddZdddZddddZdddddddddZdddddZdddddddddddd ZddZfd d!Zd"d#Zd$d%Zd&d'Zdd(d)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,tj||||d|_d|_dS)NF)r__init__ plat_name initialized)selfverboseZdry_runZforcer%r%r&rLs zMSVCCompiler.__init__NcCs%|dkrt}|tkr<tdjttt|}t|}|sdtd|jdd|_|jjt j }t d||_ t d||_ t d||_t d||_t d ||_t d ||_|jd d|_x9|jd djt j D]}|r.|j|q.Wx9|jd djt j D]}|rj|j|qjWd|_dddddg|_|jj|jrdndddddddg|_dddg}|js|jd$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|jt j#d"f|jt j#d#f|ji |_$d#|_%dS))Nz--plat-name must be one of {}z7Unable to find a compatible Visual Studio installation.rzcl.exezlink.exezlib.exezrc.exezmc.exezmt.exer4includelibz/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)rTrU)rV)rV)rWrXrY)rWrXrY)&r PLAT_TO_VCVARSrrtuplerAr_pathsrBrrCrHcclinkerrSrcmcZmt_vcruntime_redistZadd_include_dirZadd_library_dirZpreprocess_optionscompile_optionsappendcompile_options_debugextendZ ldflags_exeZldflags_exe_debugZldflags_sharedZldflags_shared_debugZldflags_staticZldflags_static_debugrZ EXECUTABLEZ SHARED_OBJECTZSHARED_LIBRARY_ldflagsrN)rOrMrZvc_envrEdirldflagsZ ldflags_debugr%r%r& initializes`       %%     zMSVCCompiler.initializerQcsvfddjDfddjjDpHdfdd}tt||S)Ncsi|]}j|qSr%) obj_extension)r)ext)rOr%r&r+s z1MSVCCompiler.object_filenames..csi|]}j|qSr%) res_extension)r)rk)rOr%r&r+s rQc stjj|\}}r3tjj|}nItjj|\}}|jtjjtjjfr||dd}ytjj||SWn't k rt dj |YnXdS)NzDon't know how to compile {}) rrsplitextbasename splitdrive startswithsepaltsepr LookupErrorrr)rFbaserkr/)ext_map output_dir strip_dirr%r& make_out_paths! z4MSVCCompiler.object_filenames..make_out_path)src_extensions_rc_extensions_mc_extensionslistmap)rOZsource_filenamesrxrwryr%)rvrwrOrxr&object_filenames s & zMSVCCompiler.object_filenamesc Cs?|js|j|j||||||} | \}} }} } |pOg} | jd|rx| j|jn| j|jd}x| D]}y| |\}}Wntk rwYnX|rtj j |}||j krd|}n||j krd|}d}n||j kr|}d|}y%|j|jg| ||gWqtk r}zt|WYdd}~XqXqn||jkrtj j|}tj j|}y|j|jd|d||gtj jtj j|\}}tj j||d }|j|jd||gWqtk r}zt|WYdd}~XqXqntd j|||jg| | }|r|jd |j||jd ||j|y|j|Wqtk r6}zt|WYdd}~XqXqW| S) Nz/cFz/Tcz/TpTz/foz-hz-rz.rcz"Don't know how to compile {} to {}z/EHscz/Fo)rNriZ_setup_compilercrerdrbKeyErrorrrrD _c_extensions_cpp_extensionsr{spawnr_rrr|dirnamer`rnrorrr])rOZsourcesrwZmacrosZ include_dirsr extra_preargsextra_postargsZdependsZ compile_infoobjectsZpp_optsZbuildZ compile_optsZ add_cpp_optsobjsrcrkZ input_optZ output_optmsgZh_dirZrc_dirrur/Zrc_fileargsr%r%r&compile+sn          % "$!    #zMSVCCompiler.compilec Cs|js|j|j||\}}|j|d|}|j||r|d|g}|riy:tjd|jdj||j |jg|Wqt k r}zt |WYdd}~XqXntjd|dS)Nrwz/OUT:zExecuting "%s" %s zskipping %s (up-to-date)) rNri_fix_object_argslibrary_filename _need_linkr rrSrrrr) rOrZoutput_libnamerwr target_langoutput_filenameZlib_argsrr%r%r&create_static_libs    "zMSVCCompiler.create_static_libcCsX|js|j|j||\}}|j|||}|\}}}|rl|jdt|t||||}|dk rtjj ||}|j ||rD|j || f}dd|pgD}||||d|g}tjj |d} |dk rrtjj tjj|\}}tjj | |j|}|jd|| r| |dd<| r|j| tjj tjj|}|j|yGtjd|jdj ||j|jg||j|WqTtk r@}zt|WYdd}~XqTXntjd |dS) Nz5I don't know what to do with 'runtime_library_dirs': cSsg|]}d|qS)z/EXPORT:r%)r)Zsymr%r%r& s z%MSVCCompiler.link..z/OUT:rz/IMPLIB:zExecuting "%s" %srzskipping %s (up-to-date))rNrirZ _fix_lib_argswarnstrrrrrrrfrrnrorrcrerDZmkpathr rr^r_copy_vcruntimerr)rOZ target_descrrrwZ librariesZ library_dirsZruntime_library_dirsZexport_symbolsrrrZ build_temprZ fixed_argsZlib_optsrhZ export_optsZld_argsZdll_nameZdll_extZ implib_filerr%r%r&linksN            "zMSVCCompiler.linkcCs|j}| s#tjj| r'dStjj|jtkrIdStjd|t j ||}tj |t j dS)Nz Copying "%s")rarrrror( _BUNDLED_DLLSr rshutilcopychmodstatS_IWRITE)rOrwr$r%r%r&rs zMSVCCompiler._copy_vcruntimec sHtjd}z$|jtjds(    (  .