U Re @ s d Z ddlZddlmZ ddlmZmZ ddlmZm Z m Z mZ ddlZddl Z ddlZddlZddlZddlZddlmZ ddlmZ dd lmZ e d krddlZddlmZ nG dd d Ze ZeejjfZ zddl!m"Z" W n e k r Y nX dd Z#d/ddZ$dd Z%dd Z&dddddZ'dd Z(dd Z)d d! Z*d"d# Z+d0d%d&Z,G d'd( d(Z-G d)d* d*Z.G d+d, d,Z/G d-d. d.Z0dS )1a Improved support for Microsoft Visual C++ compilers. Known supported compilers: -------------------------- Microsoft Visual C++ 9.0: Microsoft Visual C++ Compiler for Python 2.7 (x86, amd64) Microsoft Windows SDK 6.1 (x86, x64, ia64) Microsoft Windows SDK 7.0 (x86, x64, ia64) Microsoft Visual C++ 10.0: Microsoft Windows SDK 7.1 (x86, x64, ia64) Microsoft Visual C++ 14.X: Microsoft Visual C++ Build Tools 2015 (x86, x64, arm) Microsoft Visual Studio Build Tools 2017 (x86, x64, arm, arm64) Microsoft Visual Studio Build Tools 2019 (x86, x64, arm, arm64) This may also support compilers shipped with compatible Visual Studio versions. N)open)listdirpathsep)joinisfileisdirdirname) LegacyVersion)unique_everseen ) get_unpatchedWindows)environc @ s e Zd ZdZdZdZdZdS )winregN)__name__ __module____qualname__ HKEY_USERSHKEY_CURRENT_USERHKEY_LOCAL_MACHINEHKEY_CLASSES_ROOT r r /builddir/build/BUILDROOT/alt-python38-setuptools-58.3.0-2.el8.x86_64/opt/alt/python38/lib/python3.8/site-packages/setuptools/msvc.pyr + s r )Regc C s d}|d| f }zt |d}W nJ tk rj z|d| f }t |d}W n tk rd d}Y nX Y nX |rt|d}t|r|S tt| S )a Patched "distutils.msvc9compiler.find_vcvarsall" to use the standalone compiler build for Python (VCForPython / Microsoft Visual C++ Compiler for Python 2.7). Fall back to original behavior when the standalone compiler is not available. Redirect the path of "vcvarsall.bat". Parameters ---------- version: float Required Microsoft Visual C++ version. Return ------ str vcvarsall.bat path z-Software\%sMicrosoft\DevDiv\VCForPython\%0.1f installdirzWow6432Node\N vcvarsall.bat)r get_valueKeyErrorr r r msvc9_find_vcvarsall)versionZvc_basekey productdir vcvarsallr r r r B s r x86c O s zt t}|| |f||W S tjjk r4 Y n tk rF Y nX zt|| W S tjjk r } zt|| | W 5 d}~X Y nX dS )ao Patched "distutils.msvc9compiler.query_vcvarsall" for support extra Microsoft Visual C++ 9.0 and 10.0 compilers. Set environment without use of "vcvarsall.bat". Parameters ---------- ver: float Required Microsoft Visual C++ version. arch: str Target architecture. Return ------ dict environment N) r msvc9_query_vcvarsall distutilserrorsDistutilsPlatformError ValueErrorEnvironmentInfo return_env_augment_exception)verarchargskwargsorigexcr r r r% l s r% c C s zt t jddt jt jB } W n tk r4 Y dS X d}d}| t D ]}zt | |\}}}W n tk r Y qY nX |rL|t j krLt |rLztt|}W n t tfk r Y qLY nX |dkrL||krL|| }}qLW 5 Q R X ||fS )0Python 3.8 "distutils/_msvccompiler.py" backportz'Software\Microsoft\VisualStudio\SxS\VC7r NNN )r OpenKeyr KEY_READZKEY_WOW64_32KEYOSError itertoolscount EnumValueREG_SZr intfloatr) TypeError)r! best_versionbest_dirivZvc_dirvtr r r r _msvc14_find_vc2015 s2 rE c C s t dpt d} | sdS z>tt| dddddd d dd dd dddgjddd }W n tjtt fk rx Y dS X t|ddd}t |rd|fS dS )a Python 3.8 "distutils/_msvccompiler.py" backport Returns "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. ProgramFiles(x86)ProgramFilesr4 zMicrosoft Visual StudioZ Installerzvswhere.exez-latestz-prereleasez-requiresAnyz -requiresz1Microsoft.VisualStudio.Component.VC.Tools.x86.x64z)Microsoft.VisualStudio.Workload.WDExpressz -propertyinstallationPathz -products*mbcsstrict)encodingr' VCZ AuxiliaryZBuild )r get subprocesscheck_outputr decodestripCalledProcessErrorr8 UnicodeDecodeErrorr )rootpathr r r _msvc14_find_vc2017 s6 rX x64armarm64)r$ Z x86_amd64Zx86_armZ x86_arm64c C s t \}}d}| tkr t| }nd| kr,dnd}|rt|ddddd|d d }zddl}|j|dd d }W n tttfk r d}Y nX |st \}}|rt|d|dd }|sdS t|d}t|sdS |rt|sd}||fS )r3 Namd64rY r$ z..redistZMSVCz**zMicrosoft.VC14*.CRTzvcruntime140.dllr T) recursivezMicrosoft.VC140.CRTr4 r ) rX PLAT_SPEC_TO_RUNTIMEr globImportErrorr8 LookupErrorrE r ) plat_spec_rA vcruntimeZvcruntime_platZvcredistra r@ r# r r r _msvc14_find_vcvarsall s> rg c C s dt krdd t D S t| \}}|s6tjdz&tjd|| tj dj ddd }W n: tjk r } ztjd |j|W 5 d}~X Y nX dd d d | D D }|r||d<