[@w@sdZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z m Z mZddlmZddlmZddlZejZejZejZejZejejejejfZ ej!dkoej"d'kZ#e#r!d Z$d Z%d Z&nd Z$dZ%dZ&idd6dd6dd6Z'GdddZ(GdddZ)ddZ*ddZ+ddZ,dd Z-dd!d"Z.e*Z/e/d#kred$e/nGd%d&d&e Z0dS)(a distutils.msvc9compiler Contains MSVCCompiler, an implementation of the abstract CCompiler class for the Microsoft Visual Studio 2008. The module is compatible with VS 2005 and VS 2008. You can find legacy support for older versions of VS in distutils.msvccompiler. N)DistutilsExecErrorDistutilsPlatformError CompileErrorLibError LinkError) CCompilergen_preprocess_optionsgen_lib_options)log) get_platformwin32 z1Software\Wow6432Node\Microsoft\VisualStudio\%0.1fz5Software\Wow6432Node\Microsoft\Microsoft SDKs\Windowsz,Software\Wow6432Node\Microsoft\.NETFrameworkz%Software\Microsoft\VisualStudio\%0.1fz)Software\Microsoft\Microsoft SDKs\Windowsz Software\Microsoft\.NETFrameworkx86Zamd64z win-amd64Zia64zwin-ia64c@sveZdZdZddZeeZddZeeZddZeeZdd Ze eZd S) Regz2Helper class to read values from the registry cCsMx:tD]2}|j||}|r||kr||SqWt|dS)N)HKEYS read_valuesKeyError)clspathkeybasedr-/usr/lib/python3.4/distutils/msvc9compiler.py get_valueAs   z Reg.get_valuecCsyt||}Wntk r+dSYnXg}d}xDyt||}Wntk rcPYnX|j||d7}q;W|S)zReturn list of registry keys.Nr) RegOpenKeyExRegError RegEnumKeyappend)rrrhandleLikrrr read_keysIs    z Reg.read_keysc Csyt||}Wntk r+dSYnXi}d}xhyt||\}}}Wntk rlPYnX|j}|j|||j|<|d7}q;W|S)z`Return dict of registry keys and values. All names are converted to lowercase. Nrr)rr RegEnumValuelower convert_mbcs) rrrr!rr#namevaluetyperrrr[s    zReg.read_valuesc CsJt|dd}|dk rFy|d}WqFtk rBYqFXn|S)Ndecodembcs)getattr UnicodeError)sZdecrrrr(qs  zReg.convert_mbcsN) __name__ __module__ __qualname____doc__r classmethodr%rr( staticmethodrrrrr=s        rc@s@eZdZddZddZddZddZd S) MacroExpandercCs'i|_t||_|j|dS)N)macrosVS_BASEvsbase load_macros)selfversionrrr__init__}s  zMacroExpander.__init__cCs!tj|||jd|r?r;rHrrrrr7{s    r7cCsd}tjj|}|d kr(dS|t|}tj|djdd\}}t|dd d}t|ddd}|dkrd }n|dkr||SdS) zReturn the version of MSVC that was used to build Python. For Python 2.3 and up, the version number is included in sys.version. For earlier versions, assume the compiler is MSVC 6. zMSC v.rN r g$@r)sysr=findlensplitint)prefixr#r0restZ majorVersionZ minorVersionrrrget_build_versions %   rUcCsIg}x<|D]4}tjj|}||kr |j|q q W|S)znReturn a list of normalized paths with duplicates removed. The current order of paths is maintained. )osrnormpathr )ZpathsZ reduced_pathsrCZnprrrnormalize_and_reduce_pathss   rXcCs[|jtj}g}x*|D]"}||kr|j|qqWtjj|}|S)z8Remove duplicate values of an environment variable. )rQrVpathsepr join)ZvariableZoldListZnewListr#Z newVariablerrrremoveDuplicatess  r[c Csat|}ytjd|d}Wn%tk rKtjdd}YnX| sftjj| rd|}tj j |d}|rtjj|rtjj |tj tj d}tjj |}tjj|s tjd|dSqtjd|n|s%tjd dStjj |d }tjj|rP|Stjd dS) zFind the vcvarsall.bat file At first it tries to find the productdir of VS 2008 in the registry. If that fails it falls back to the VS90COMNTOOLS env var. z %s\Setup\VCr@z%Unable to find productdir in registryNzVS%0.f0COMNTOOLSZVCz%s is not a valid directoryz Env var %s is not set or invalidzNo productdir foundz vcvarsall.batzUnable to find vcvarsall.bat)r9rrrr debugrVrisdirenvirongetrZpardirabspathisfile)r=r:r@ZtoolskeyZtoolsdir vcvarsallrrrfind_vcvarsalls2       !  rdc Cst|}td}i}|dkr9tdntjd||tjd||fd tjd tj}z|j\}}|j d krt|j d n|j d }x|j d D]}t j |}d|krqn|j}|j dd\} } | j} | |kr| jtjr]| dd} nt| || VERSION_MSVCCompiler__versionZ_MSVCCompiler__root_MSVCCompiler__paths plat_name_MSVCCompiler__arch initialized)r<verboseZdry_runZforcerrrr>Gs     zMSVCCompiler.__init__NcCs|j std|dkr.t}nd&}||krVtd|fndtjkrdtjkr|jdrd|_d |_d |_ d |_ d |_ n|tks|dkrt |}nt td t |}t t|}|djtj|_|dtjd<|dtjd|)rz*\s*zI|)w) openreadrsrerDOTALLrHsearchwriteOSError)r<Z manifest_fileZ manifest_fZ manifest_bufpatternrrrrs.      z!MSVCCompiler._remove_visual_c_refcCsd|S)Nz /LIBPATH:r)r<dirrrrlibrary_dir_optionszMSVCCompiler.library_dir_optioncCstddS)Nzrrrrrrrrrrrrrrrrrr|)sR      X VR  +   r|l)1r4rVrmrNrZdistutils.errorsrrrrrZdistutils.ccompilerrrr Z distutilsr Zdistutils.utilr winregZ OpenKeyExrZEnumKeyrZ EnumValuer&errorrZ HKEY_USERSHKEY_CURRENT_USERHKEY_LOCAL_MACHINEZHKEY_CLASSES_ROOTrplatformmaxsizeZ NATIVE_WIN64r9rBrArrr7rUrXr[rdr{r}r|rrrrsP    (        >.   #)