a Z^'Nc@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 CsztjtjdtjtjBd}Wnty<tdYdS0d}d}|tD]}zt ||\}}}WntyYqYn0|rR|tj krRt j |rRztt|}WnttfyYqRYn0|dkrR||krR||}}qRWdn1s0Y||fS)Nz'Software\Microsoft\VisualStudio\SxS\VC7)ZaccesszVisual C++ is not registeredNNri)winregZ OpenKeyExZHKEY_LOCAL_MACHINEZKEY_READZKEY_WOW64_32KEYOSErrorrdebugr Z EnumValueZREG_SZospathisdirZintZfloatZ ValueErrorZ TypeError)key best_versionbest_dirZiZvZvc_dirZvtZversionr//usr/lib64/python3.9/distutils/_msvccompiler.py _find_vc2015s2       ,rc Cstjdptjd}|s dSz8tjtj|dddddd d d d d dg ddd}Wntjt t fytYdS0tj|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 -productsZ*ZmbcsZstrict)ZencodingerrorsZVCZ AuxiliaryZBuildi) renvironget subprocess check_outputrjoinZstripCalledProcessErrorr ZUnicodeDecodeErrorr)Zrootrrrr _find_vc20178s(  rx86Zx64ZarmZarm64)r 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)rrrrrrrisfile) plat_spec_rr vcvarsallrrr_find_vcvarsall_s     r(c CstdrddtjDSt|\}}|s6tdz&tjd||tj dj ddd }WnBtj y}z(t |jtd |jWYd}~n d}~00d dd d |DD}|S)NZDISTUTILS_USE_SDKcSsi|]\}}||qSrZlower).0rvaluerrr ssz_get_vc_env..zUnable to find vcvarsall.batzcmd /u /c "{}" {} && set)Zstderrzutf-16leZreplace)rzError executing {}cSs$i|]\}}}|r|r||qSrr))r*rr&r+rrrr,scss|]}|dVqdS)z=N)Z partition)r*ZlinerrrZ z_get_vc_env..)rgetenvrZitemsr(rrrformatZSTDOUTZdecoderrZerrorZoutputcmdZ splitlines)r%r'r&ZoutZexcZenvrrr _get_vc_envqs.     r1cCsN|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)rr.splitpathseprrabspathr$)ZexepathspZfnrrr _find_exes   r7r!r"r#)Zwin32z win-amd64z win-arm32z win-arm64c seZdZdZdZiZdgZgdZdgZdgZ eeee Z dZ dZ d Z d Zd ZZd Zd&ddZd'ddZd(ddZd)ddZd*ddZd+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.Zmsvcz.c)z.ccz.cppz.cxx.rcz.mcz.resz.objz.libz.dllz%s%sz.exercCs t||||d|_d|_dS)NF)r__init__ plat_name initialized)selfZverboseZdry_runZforcerrrr:szMSVCCompiler.__init__NcCs |durt}|tvr(tdttt|}t|}|sDtd|dd|_|jt j }t d||_ t d||_ t d||_t d||_t d ||_t d ||_|d dt j D]}|r||t jq|d dt j D]}|r||t jqd|_gd |_gd|_gd}gd}g|d|_g|d|_g|ddd|_g|ddd|_g||_g||_tj df|jtj df|jtj df|jtj!df|jtj!df|jtj!df|jtj"df|jtj"df|jtj"df|ji |_#d|_$dS)Nz--plat-name must be one of {}z7Unable to find a compatible Visual Studio installation.rzcl.exezlink.exezlib.exezrc.exezmc.exezmt.exeZincludelib)/nologoz/Ox/W3z/GLz/DNDEBUGz/MD)r@z/Odz/MDdz/ZirAz/D_DEBUG)r@/INCREMENTAL:NO/LTCG)r@rBrCz /DEBUG:FULLz/MANIFEST:EMBED,ID=1z/DLLz/MANIFEST:EMBED,ID=2z/MANIFESTUAC:NOFT)%r PLAT_TO_VCVARSrr/Ztupler1r_pathsr2rr3r7cclinkerr?rcmcZmtZadd_include_dirZrstripsepZadd_library_dirZpreprocess_optionscompile_optionscompile_options_debugZ ldflags_exeZldflags_exe_debugZldflags_sharedZldflags_shared_debugZldflags_staticZldflags_static_debugrZ EXECUTABLEZ SHARED_OBJECTZSHARED_LIBRARY_ldflagsr<)r=r;r%Zvc_envr5dirldflagsZ ldflags_debugrrr initializes\                    zMSVCCompiler.initializer>csXifddjDfddjjDp8dfdd}tt||S)Nci|] }|jqSr) obj_extensionr*extr=rrr,"r-z1MSVCCompiler.object_filenames..crQr) res_extensionrSrUrrr,#r-r>cstj|\}}r"tj|}n2tj|\}}|tjjtjjfrT|dd}ztj||WSt yt d |Yn0dS)NizDon't know how to compile {}) rrsplitextbasenameZ splitdriveZ startswithrJZaltseprZ LookupErrorrr/)r6baserTr&)ext_map output_dir strip_dirrr make_out_path(s  z4MSVCCompiler.object_filenames..make_out_path)src_extensions_rc_extensions_mc_extensionsZlistZmap)r=Zsource_filenamesr\r[r]r)rZr[r=r\robject_filenamesszMSVCCompiler.object_filenamesc  Cs|js||||||||} | \}} }} } |p6g} | d|rT| |jn | |jd}| D]}z| |\}}WntyYqhYn0|rtj |}||j vrd|}nH||j vrd|}d}n.||j vr@|}d|}z||jg| ||gWqhty:}zt|WYd}~qhd}~00qhn||jvrtj |}tj |}z\||jd|d||gtj tj |\}}tj ||d }||jd||gWqhty}zt|WYd}~qhd}~00qhntd |||jg| | }|r$|d |||d |||z||Wqhty}zt|WYd}~qhd}~00qh| S) Nz/cFz/Tcz/TpTz/foz-hz-rr9z"Don't know how to compile {} to {}z/EHscz/Fo)r<rPZ_setup_compileappendextendrLrKZKeyErrorrrr4 _c_extensions_cpp_extensionsr_spawnrHrrr`dirnamerIrWrXrr/rF)r=Zsourcesr[ZmacrosZ include_dirsr extra_preargsextra_postargsZdependsZ compile_infoobjectsZpp_optsZbuildZ compile_optsZ add_cpp_optsZobjZsrcrTZ input_optZ output_optmsgZh_dirZrc_dirrYr&Zrc_fileZargsrrrcompile>sr                 zMSVCCompiler.compilec Cs|js||||\}}|j||d}|||r|d|g}|rJz,td|jd|| |jg|Wqt y}zt |WYd}~qd}~00n td|dS)N)r[/OUT:Executing "%s" %s skipping %s (up-to-date)) r<rP_fix_object_argslibrary_filename _need_linkrrr?rrfrr) r=rjZoutput_libnamer[r target_langoutput_filenameZlib_argsrkrrrcreate_static_libs  zMSVCCompiler.create_static_libc Cs|js||||\}}||||}|\}}}|rL|dt|t||||}|durptj ||}| ||r|j || f}dd|pgD}||||d|g}tj |d} |dur tj tj|\}}tj | ||}|d|| r| |dd<| r.|| tj tj|}||z,td|jd |||jg|Wn.ty}zt|WYd}~n d}~00n td |dS) Nz5I don't know what to do with 'runtime_library_dirs': cSsg|] }d|qS)z/EXPORT:r)r*ZsymrrrZ r-z%MSVCCompiler.link..rmrz/IMPLIB:rnrorp)r<rPrqZ _fix_lib_argsZwarnZstrrrrrrsrMrgrWrXrrrbrcr4ZmkpathrrrGrfrr)r=Z target_descrjrur[Z librariesZ library_dirsZruntime_library_dirsZexport_symbolsrrhriZ build_temprtZ fixed_argsZlib_optsrOZ export_optsZld_argsZdll_nameZdll_extZ implib_filerkrrrlinks^        zMSVCCompiler.linkc s@td}z$|jtjd<t|W|tjd<S|tjd<0dS)Nr)rr.rErZsuperrf)r=r0Zold_pathZ __class__rrrfs    zMSVCCompiler.spawncCsd|S)Nz /LIBPATH:rr=rNrrrlibrary_dir_optionzMSVCCompiler.library_dir_optioncCs tddS)Nz:don't know how to set runtime library search path for MSVC)rryrrrruntime_library_dir_optionsz'MSVCCompiler.runtime_library_dir_optioncCs ||SN)rr)r=r?rrrlibrary_option r{zMSVCCompiler.library_optioncCs\|r|d|g}n|g}|D]:}|D]0}tj|||}tj|r$|Sq$qdS)NZ_d)rrrrrr$)r=Zdirsr?rZ try_namesrNZnameZlibfilerrrfind_library_file s zMSVCCompiler.find_library_file)rrrr})rr>)NNNrNNN)NrN) NNNNNrNNNN)r)Z__name__Z __module__Z __qualname____doc__Z compiler_typeZ executablesrdrer_r`r^rVrRZstatic_lib_extensionZshared_lib_extensionZstatic_lib_formatZshared_lib_formatZ exe_extensionr:rPrarlrvrwrfrzr|r~rZ __classcell__rrrxrr8s\  P " ]  E r8r})rrrr Zdistutils.errorsrrrrrZdistutils.ccompilerrrZ distutilsrZdistutils.utilr Z itertoolsr rrZPLAT_SPEC_TO_RUNTIMEr(r1r7rDr8rrrrZs0   !