B ʀpzxS @sdZddlZddlZddlZddlZddlZeeddl Z WdQRXddl 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 CsytjtjdtjtjBd}Wntk r<tddSXd}d}|xtD]}yt ||\}}}Wntk rPYnX|rT|tj krTt j |rTytt|}Wnttfk rwTYnX|dkrT||krT||}}qTWWdQRX||fS)Nz'Software\Microsoft\VisualStudio\SxS\VC7)accesszVisual C++ is not registered)NNr)winreg OpenKeyExHKEY_LOCAL_MACHINEZKEY_READZKEY_WOW64_32KEYOSErrorr debugr Z EnumValueREG_SZospathisdirintfloat ValueError TypeError)key best_versionbest_dirivZvc_dirZvtversionr!/builddir/build/BUILDROOT/alt-python37-setuptools-58.3.0-4.el9.x86_64/opt/alt/python37/lib/python3.7/site-packages/setuptools/_distutils/_msvccompiler.py _find_vc2015 s0  r#c Cstjdptjd}|s dSy8tjtj|dddddd d d d d dg ddd}Wntjt t fk rtdSXtj|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 ProgramFiles)NNzMicrosoft 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<s$  r3x86Zx64ZarmZarm64)r4 x86_amd64x86_arm x86_arm64cCs\t\}}|st\}}|s*tddStj|d}tj|sTtd|dS|dfS)Nz$No suitable Visual C++ version found)NNz vcvarsall.batz%s cannot be found)r3r#r rrrr.isfile) plat_spec_rr vcvarsallr!r!r"_find_vcvarsallcs     r<c CstdrddtjDSt|\}}|s6tdy&tjd||tj dj ddd }Wn@tj k r}z t |jtd |jWdd}~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"r@scss|]}|dVqdS)=N) partition)r>liner!r!r" sz_get_vc_env..)rgetenvr*itemsr<rr,r-formatSTDOUTdecoder0r erroroutputcmd splitlines)r9r;r:outexcenvr!r!r" _get_vc_envus$     rScCsN|stdtj}x2|D]*}tjtj||}tj|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)rrGsplitpathseprr.abspathr8)Zexepathspfnr!r!r" _find_exes   rZr5r6r7)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.cxxz.rcz.mcz.resz.objz.libz.dllz%s%sz.exercCs t||||d|_d|_dS)NF)r__init__ plat_name initialized)selfverbosedry_runforcer!r!r"r]szMSVCCompiler.__init__NcCs|jrtd|dkrt}|tkr6tdttt|}t|}|sRtd|dd|_ |j t j }t d||_t d||_t d||_t d ||_t d ||_t d ||_x2|d d t j D]}|r||t jqWx6|d d t j D]}|r||t jqWd|_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)rg)rg)rhrirj)rhrirj)&r_AssertionErrorr PLAT_TO_VCVARSrrItuplerSr+_pathsrTrrUrZcclinkerrfrcmcmtZadd_include_dirrstripsepZadd_library_dirZpreprocess_optionscompile_optionscompile_options_debugZ ldflags_exeZldflags_exe_debugZldflags_sharedZldflags_shared_debugZldflags_staticZldflags_static_debugrZ EXECUTABLEZ SHARED_OBJECTZSHARED_LIBRARY_ldflags)r`r^r9Zvc_envrWdirldflagsZ ldflags_debugr!r!r" initializesZ                     zMSVCCompiler.initializerdcsTfddjDfddjjDp4dfdd}tt||S)Ncsi|] }j|qSr!) obj_extension)r>ext)r`r!r"r@&sz1MSVCCompiler.object_filenames..csi|] }j|qSr!) res_extension)r>r})r`r!r"r@'srdcstj|\}}r"tj|}n2tj|\}}|tjjtjjfrT|dd}ytj||St k rt d |YnXdS)NzDon't know how to compile {}) rrsplitextbasename splitdrive startswithrualtsepr. LookupErrorrrI)rXbaser}r:)ext_map output_dir strip_dirr!r" make_out_path,s z4MSVCCompiler.object_filenames..make_out_path)src_extensions_rc_extensions_mc_extensionslistmap)r`Zsource_filenamesrrrr!)rrr`rr"object_filenames!s zMSVCCompiler.object_filenamesc  Cs|js||||||||} | \}} }} } |p6g} | d|rT| |jn | |jd}x| D]}y| |\}}Wntk rwlYnX|rtj |}||j krd|}nD||j krd|}d}n*||j krB|}d|}y||jg| ||gWqltk r<}z t|Wdd}~XYqlXqln||jkrtj |}tj |}y\||jd|d||gtj tj |\}}tj ||d }||jd||gWqltk r}z t|Wdd}~XYqlXqlntd |||jg| | }|r$|d |||d |||y||Wqltk r}z t|Wdd}~XYqlXqlW| S) Nz/cFz/Tcz/TpTz/foz-hz-rz.rcz"Don't know how to compile {} to {}z/EHscz/Fo)r_r{Z_setup_compileappendextendrwrvKeyErrorrrrV _c_extensions_cpp_extensionsrspawnrqrrrdirnamerrrrr.rIro)r`sourcesrZmacros include_dirsr extra_preargsextra_postargsdependsZ compile_infoobjectsZpp_optsbuildZ compile_optsZ add_cpp_optsobjsrcr}Z input_optZ output_optmsgZh_dirZrc_dirrr:Zrc_fileargsr!r!r"compileBsn               zMSVCCompiler.compilec Cs|js||||\}}|j||d}|||r|d|g}|rJy,td|jd|| |jg|Wqt k r}z t |Wdd}~XYqXn td|dS)N)rz/OUT:zExecuting "%s" %s zskipping %s (up-to-date)) r_r{_fix_object_argslibrary_filename _need_linkr rrfr.rrr) r`rZoutput_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|}||y,td|jd |||jg|Wn,tk r}z t|Wdd}~XYnXn td |dS) Nz5I don't know what to do with 'runtime_library_dirs': cSsg|] }d|qS)z/EXPORT:r!)r>symr!r!r" sz%MSVCCompiler.link..z/OUT:rz/IMPLIB:zExecuting "%s" %srzskipping %s (up-to-date))r_r{rZ _fix_lib_argswarnstrrrrr.rrxrrrrrrrVmkpathr rrprrr)r`Z target_descrrr libraries library_dirsruntime_library_dirsexport_symbolsrrr build_temprZ fixed_argsZlib_optsrzZ export_optsZld_argsZdll_nameZdll_extZ implib_filerr!r!r"linksL       zMSVCCompiler.linkc s:ttj|jd}|||}tj||dSQRX|jS)N)PATH)rR)dictrr*rn_fallback_spawnsuperrr?)r`rNrRfallback) __class__r!r"rszMSVCCompiler.spawnc #stddi}y |VWn0tk rH}zdt|kr8Wdd}~XYnXdStdtjd|t ||_ WdQRXdS)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) typerrwarningsrunittestZmockpatchrrr?)r`rNrRZbagrQ)rr!r"rs  zMSVCCompiler._fallback_spawncCsd|S)Nz /LIBPATH:r!)r`ryr!r!r"library_dir_optionszMSVCCompiler.library_dir_optioncCs tddS)Nz:don't know how to set runtime library search path for MSVC)r)r`ryr!r!r"runtime_library_dir_optionsz'MSVCCompiler.runtime_library_dir_optioncCs ||S)N)r)r`rfr!r!r"library_option szMSVCCompiler.library_optioncCs`|r|d|g}n|g}xB|D]6}x0|D](}tj|||}tj|r(|Sq(WqWdSdS)NZ_d)rrr.rr8)r`dirsrfrZ try_namesrynameZlibfiler!r!r"find_library_file#s    zMSVCCompiler.find_library_file)rrr)N)rrd)NNNrNNN)NrN) NNNNNrNNNN)r)!__name__ __module__ __qualname____doc__ compiler_typeZ executablesrrrrrr~r|Zstatic_lib_extensionshared_lib_extensionZstatic_lib_formatZshared_lib_formatZ exe_extensionr]r{rrrrr contextlibcontextmanagerrrrrr __classcell__r!r!)rr"r\sN   P  [  8 r\)N)!rrr,rrZ unittest.mockrsuppress ImportErrorrdistutils.errorsrrrrrdistutils.ccompilerrr distutilsr distutils.utilr itertoolsr r#r3ZPLAT_SPEC_TO_RUNTIMEr<rSrZrlr\r!r!r!r"s4    !