U iaMQ @sdZddlZddlZddlZddlZddlZeeddl Z W5QRXddl m Z m Z m Z mZmZddlmZmZddlmZddlmZddlmZdd Zd d Zd d dddZddZddZdddZd ddddZGdddeZ dS)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 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)winreg OpenKeyExHKEY_LOCAL_MACHINEZKEY_READZKEY_WOW64_32KEYOSErrorr debugr Z EnumValueREG_SZospathisdirintfloat ValueError TypeError)key best_versionbest_dirivZvc_dirZvtversionr"{/private/var/folders/k6/_7fsz4ts3b78x3b3xwrxjh_c8s8xv7/T/pip-unpacked-wheel-yl_m2el9/setuptools/_distutils/_msvccompiler.py _find_vc2015 s2     r$c Cstjdptjd}|s dSz8tjtj|dddddd d d d d dg ddd}Wntjt t fk rvYdSXtj|ddd}tj |rd|fSdS)aJReturns "15, path" based on the result of invoking vswhere.exe If no install is found, returns "None, None" The version is returned to avoid unnecessarily changing the function result. It may be ignored when the path is not None. If vswhere.exe is not available, by definition, VS 2017 is not installed. zProgramFiles(x86)Z ProgramFilesr zMicrosoft Visual StudioZ Installerz vswhere.exez-latestz -prereleasez -requiresz1Microsoft.VisualStudio.Component.VC.Tools.x86.x64z -propertyZinstallationPathz -products*mbcsstrict)encodingerrorsZVCZ AuxiliaryZBuild) renvironget subprocess check_outputrjoinstripCalledProcessErrorrUnicodeDecodeErrorr)rootrr"r"r# _find_vc2017<s0  r4x86x64armZarm64)r5 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)r4r$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@)rBrr=rCr"r"r#rDs css|]}|dVqdS)=N) partition)rBliner"r"r# sz_get_vc_env..)rgetenvr+itemsr?rr-r.formatSTDOUTdecoder1r erroroutputcmd splitlines)r<r>r=outexcenvr"r"r# _get_vc_envus0     rWcCsN|stdtj}|D].}tjtj||}tj|r|Sq|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)rrKsplitpathseprr/abspathr;)Zexepathspfnr"r"r# _find_exes   r^r8r9r:)win32z win-amd64z win-arm32z win-arm64c seZdZdZdZiZdgZdddgZdgZdgZ eeee Z d Z d Z d Z d Zd ZZdZd*ddZd+ddZd,ddZd-ddZd.ddZd/ddZfddZejfd d!Zd"d#Zd$d%Zd&d'Zd0d(d)ZZ S)1 MSVCCompilerzwConcrete class that implements an interface to Microsoft Visual C++, as defined by the CCompiler abstract class.Zmsvcz.cz.ccz.cppz.cxx.rcz.mcz.resz.objz.libz.dllz%s%sz.exercCs t||||d|_d|_dS)NF)r__init__ plat_name initialized)selfverbosedry_runforcer"r"r#rbszMSVCCompiler.__init__NcCs |jrtd|dkrt}|tkr6tdttt|}t|}|sRtd|dd|_ |j t j }t d||_t d||_t d||_t d ||_t d ||_t d ||_|d d t j D]}|r||t jq|d d t j D]}|r||t jqd|_ddddddg|_ddddddg|_dddg}ddddg}|d!|_|d"|_|d#|_|d$|_||_||_ t!j"df|jt!j"df|jt!j"d f|jt!j#df|jt!j#df|jt!j#d f|jt!j$df|jt!j$df|jt!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.exeincludelibz/nologoz/O2z/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)rl)rl)rmrnro)rmrnro)&rdAssertionErrorr PLAT_TO_VCVARSrrMtuplerWr,_pathsrXrrYr^cclinkerrkrcmcmtZadd_include_dirrstripsepZadd_library_dirZpreprocess_optionscompile_optionscompile_options_debugZ ldflags_exeZldflags_exe_debugZldflags_sharedZldflags_shared_debugZldflags_staticZldflags_static_debugrZ EXECUTABLEZ SHARED_OBJECTZSHARED_LIBRARY_ldflags)rercr<Zvc_envr[dirldflagsZ ldflags_debugr"r"r# initializes           zMSVCCompiler.initializericsTfddjDfddjjDp4dfdd}tt||S)Ncsi|] }|jqSr") obj_extensionrBextrer"r#rD&sz1MSVCCompiler.object_filenames..csi|] }|jqSr") res_extensionrrr"r#rD'sricstj|\}}r"tj|}n2tj|\}}|tjjtjjfrT|dd}ztj||WSt k rt d |YnXdS)NzDon't know how to compile {}) rrsplitextbasename splitdrive startswithrzaltsepr/ LookupErrorrrM)r\baserr=)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_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-rraz"Don't know how to compile {} to {}z/EHscz/Fo)rdrZ_setup_compileappendextendr|r{KeyErrorrrrZ _c_extensions_cpp_extensionsrspawnrvrrrdirnamerwrrr/rMrt)resourcesrmacros include_dirsr extra_preargsextra_postargsdependsZ compile_infoobjectsZpp_optsbuildZ compile_optsZ add_cpp_optsobjsrcrZ 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)) rdr_fix_object_argslibrary_filename _need_linkr rrkr/rrr) rerZoutput_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")rBsymr"r"r# sz%MSVCCompiler.link..rrz/IMPLIB:rrr)rdrrZ _fix_lib_argswarnstrrrrr/rr}rrrrrrrZmkpathr rrurrr)reZ target_descrrr libraries library_dirsruntime_library_dirsexport_symbolsrrr build_temprZ fixed_argsZlib_optsrZ export_optsZld_argsZdll_nameZdll_extZ implib_filerr"r"r#links`       zMSVCCompiler.linkc sFttj|jd}|||}tj||dW5QRSQRX|jS)N)PATH)rV)dictrr+rs_fallback_spawnsuperrrC)rerRrVfallback __class__r"r#rs"zMSVCCompiler.spawnc #stddi}z |VWn0tk rH}zdt|kr8W5d}~XYnXdStdtjd|t ||_ W5QRXdS)z Discovered in pypa/distutils#15, some tools monkeypatch the compiler, so the 'env' kwarg causes a TypeError. Detect this condition and restore the legacy, unsafe behavior. ZBagr"z!unexpected keyword argument 'env'Nz>Fallback spawn triggered. Please update distutils monkeypatch.z os.environ) typerrwarningsrunittestZmockpatchrrrC)rerRrVZbagrUrr"r#rs  zMSVCCompiler._fallback_spawncCsd|S)Nz /LIBPATH:r"rer~r"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_optionsz'MSVCCompiler.runtime_library_dir_optioncCs ||S)N)r)rerkr"r"r#library_option szMSVCCompiler.library_optioncCs\|r|d|g}n|g}|D]:}|D]0}tj|||}tj|r$|Sq$qdS)NZ_d)rrr/rr;)redirsrkrZ try_namesr~nameZlibfiler"r"r#find_library_file#s zMSVCCompiler.find_library_file)rrr)N)rri)NNNrNNN)NrN) NNNNNrNNNN)r)!__name__ __module__ __qualname____doc__ compiler_typeZ executablesrrrrrrrZstatic_lib_extensionshared_lib_extensionZstatic_lib_formatZshared_lib_formatZ exe_extensionrbrrrrrr contextlibcontextmanagerrrrrr __classcell__r"r"rr#r`sj   P " ]  E r`)N)!rrr-rrZ unittest.mockrsuppress ImportErrorrdistutils.errorsrrrrrdistutils.ccompilerrr distutilsr distutils.utilr itertoolsr r$r4ZPLAT_SPEC_TO_RUNTIMEr?rWr^rqr`r"r"r"r#s8    !