o bc'N@sdZddlZddlZddlZddlmZmZmZmZm Z ddl m Z m Z ddl mZddlmZddlmZdd Zd d Zd d dddZddZddZdddZd ddddZGddde 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 Cs ztjtjdtjtjBd}WntytdYdSwd}d}|_tD]F}z t ||\}}}Wn ty@Yn:w|ro|tj krot j |roztt|}Wn ttfyaYq)w|dkro||kro||}}q)Wd||fSWd||fS1swY||fS)Nz'Software\Microsoft\VisualStudio\SxS\VC7)accesszVisual C++ is not registeredNNr)winreg OpenKeyExHKEY_LOCAL_MACHINEKEY_READKEY_WOW64_32KEYOSErrorr debugr EnumValueREG_SZospathisdirintfloat ValueError TypeError)key best_versionbest_dirivvc_dirvtversionr'./usr/lib/python3.10/distutils/_msvccompiler.py _find_vc2015sH           r)c Cstjdp tjd}|sdSztjtj|dddddd d d d d dg ddd}Wntjt t fy:YdSwtj|ddd}tj |rNd|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) ProgramFilesr zMicrosoft Visual Studio Installerz vswhere.exez-latestz -prereleasez -requiresz1Microsoft.VisualStudio.Component.VC.Tools.x86.x64z -propertyinstallationPathz -products*mbcsstrict)encodingerrorsVC AuxiliaryBuild) renvironget subprocess check_outputrjoinstripCalledProcessErrorrUnicodeDecodeErrorr)rootrr'r'r( _find_vc20178s.  r?x86x64armarm64)r@ x86_amd64x86_arm x86_arm64cCs\t\}}|s t\}}|stddStj|d}tj|s*td|dS|dfS)Nz$No suitable Visual C++ version foundr z vcvarsall.batz%s cannot be found)r?r)r rrrr:isfile) plat_spec_r!r vcvarsallr'r'r(_find_vcvarsall_s     rKc CstdrddtjDSt|\}}|stdztjd||tj dj ddd }Wntj yI}zt |jtd |jd}~wwd dd d |DD}|S)NDISTUTILS_USE_SDKcSsi|] \}}||qSr'lower).0rvaluer'r'r( ssz_get_vc_env..zUnable to find vcvarsall.batzcmd /u /c "{}" {} && set)stderrzutf-16lereplace)r1zError executing {}cSs$i|]\}}}|r|r||qSr'rM)rOrrIrPr'r'r(rQscss|]}|dVqdS)=N) partition)rOliner'r'r( sz_get_vc_env..)rgetenvr6itemsrKrr8r9formatSTDOUTdecoder<r erroroutputcmd splitlines)rHrJrIoutexcenvr'r'r( _get_vc_envqs2     rdcCsN|s tdtj}|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)rrXsplitpathseprr:abspathrG)exepathspfnr'r'r( _find_exes  rlrDrErF)win32z win-amd64z win-arm32z win-arm64cseZdZdZdZiZdgZgdZdgZdgZ eeee Z dZ dZ d Z d Zd ZZd Zd&ddZd'ddZ d(ddZ d)ddZ  d*ddZ         d+ddZfddZddZd d!Zd"d#Zd,d$d%ZZS)- MSVCCompilerzwConcrete class that implements an interface to Microsoft Visual C++, as defined by the CCompiler abstract class.msvcz.c)z.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(rqs zMSVCCompiler.__init__NcCs|jrJd|durt}|tvrtdttt|}t|}|s)td|dd|_|j t j }t d||_ t d||_t d||_t d ||_t d ||_t d ||_|d d t j D] }|rr||t jqe|d d t j D] }|r||t jq}d|_gd|_gd|_gd}gd}g|d|_g|d|_g|ddd|_g|ddd|_g||_g||_t j!df|jt j!df|jt j!df|jt j"df|jt j"df|jt j"df|jt j#df|jt j#df|jt j#df|ji |_$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.exeincludelib)/nologoz/Ox/W3z/GLz/DNDEBUGz/MD)r{z/Odz/MDdz/Zir|z/D_DEBUG)r{/INCREMENTAL:NO/LTCG)r{r}r~z /DEBUG:FULLz/MANIFEST:EMBED,ID=1z/DLLz/MANIFEST:EMBED,ID=2z/MANIFESTUAC:NOFT)%rsr PLAT_TO_VCVARSrrZtuplerdr7_pathsrerrfrlcclinkerrzrcmcmtadd_include_dirrstripsepadd_library_dirpreprocess_optionscompile_optionscompile_options_debug ldflags_exeldflags_exe_debugldflags_sharedldflags_shared_debugldflags_staticldflags_static_debugr EXECUTABLE SHARED_OBJECTSHARED_LIBRARY_ldflags)rtrrrHvc_envridirldflags ldflags_debugr'r'r( initializesb                     zMSVCCompiler.initializerxcsXifddjDfddjjDpdfdd}tt||S)Nci|]}|jqSr') obj_extensionrOextrtr'r(rQ"z1MSVCCompiler.object_filenames..crr') res_extensionrrr'r(rQ#rrxcstj|\}}rtj|}ntj|\}}|tjjtjjfr*|dd}z tj||WSt yDt d |w)NzDon't know how to compile {}) rrsplitextbasename splitdrive startswithraltsepr: LookupErrorrrZ)rjbaserrI)ext_map output_dir strip_dirr'r( make_out_path(s  z4MSVCCompiler.object_filenames..make_out_path)src_extensions_rc_extensions_mc_extensionslistmap)rtsource_filenamesrrrr')rrrtrr(object_filenamesszMSVCCompiler.object_filenamesc  CsL|js||||||||} | \}} }} } |pg} | d|r*| |jn| |jd}| D]}z| |\}}Wn tyGYq4w|rPtj |}||j vrZd|}n||j vrfd|}d}n||j vr|}d|}z||jg| ||gWnty}zt|d}~wwq4||jvrtj |}tj |}z.||jd|d||gtj tj |\}}tj ||d }||jd||gWnty}zt|d}~wwq4td |||jg| | }|r|d |||d |||z||Wq4ty#}zt|d}~ww| S) Nz/cFz/Tcz/TpTz/foz-hz-rrpz"Don't know how to compile {} to {}z/EHscz/Fo)rsr_setup_compileappendextendrrKeyErrorrrrg _c_extensions_cpp_extensionsrspawnrrrrdirnamerrrr:rZr)rtsourcesrmacros include_dirsr extra_preargsextra_postargsdepends compile_infoobjectspp_optsbuild compile_opts add_cpp_optsobjsrcr input_opt output_optmsgh_dirrc_dirrrIrc_fileargsr'r'r(compile>s              zMSVCCompiler.compilec Cs|js||||\}}|j||d}|||rN|d|g}|r& ztd|jd|| |jg|WdSt yM}zt |d}~wwtd|dS)N)r/OUT:Executing "%s" %s skipping %s (up-to-date)) rsr_fix_object_argslibrary_filename _need_linkr rrzr:rrr) rtroutput_libnamerr target_langoutput_filenamelib_argsrr'r'r(create_static_libs$ zMSVCCompiler.create_static_libc Cs|js||||\}}||||}|\}}}|r&|dt|t||||}|dur8tj ||}| ||r|j || f}dd|pKgD}||||d|g}tj |d} |durtj tj|\}}tj | ||}|d|| r| |dd<| r|| tj tj|}||ztd|jd |||jg|WdSty}zt|d}~wwtd |dS) Nz5I don't know what to do with 'runtime_library_dirs': cSsg|]}d|qS)z/EXPORT:r')rOsymr'r'r( rz%MSVCCompiler.link..rrz/IMPLIB:rrr)rsrr _fix_lib_argswarnstrrrrr:rrrrrrrrrgmkpathr rrrrr)rt target_descrrr libraries library_dirsruntime_library_dirsexport_symbolsrrr build_tempr fixed_argslib_optsr export_optsld_argsdll_namedll_ext implib_filerr'r'r(linksb       zMSVCCompiler.linkc s<td}z|jtjd<t|W|tjd<S|tjd<w)Nr)rrXrr6superr)rtr_old_path __class__r'r(rs   zMSVCCompiler.spawncCsd|S)Nz /LIBPATH:r'rtrr'r'r(library_dir_optionszMSVCCompiler.library_dir_optioncCstd)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 ||SN)r)rtrzr'r'r(library_option s zMSVCCompiler.library_optioncCs\|r |d|g}n|g}|D]}|D]}tj|||}tj|r*|SqqdS)N_d)rrr:rrG)rtdirsrzr try_namesrnamelibfiler'r'r(find_library_file s  zMSVCCompiler.find_library_file)rrrr)rrx)NNNrNNN)NrN) NNNNNrNNNN)r)__name__ __module__ __qualname____doc__ compiler_type executablesrrrrrrrstatic_lib_extensionshared_lib_extensionstatic_lib_formatshared_lib_format exe_extensionrqrrrrrrrrrr __classcell__r'r'rr(rns^  P " ]  E rnr)rrr8rdistutils.errorsrrrrrdistutils.ccompilerrr distutilsr distutils.utilr itertoolsr r)r?PLAT_SPEC_TO_RUNTIMErKrdrlrrnr'r'r'r(s2   !