3 \”wã@sTdZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z m Z mZddlmZddlmZddlZejZejZejZejZejejejejfZ ej!dko²ej"d&kZ#e#rÆd Z$d Z%d Z&n d Z$dZ%dZ&ddddœZ'Gdd„dƒZ(Gdd„dƒZ)dd„Z*dd„Z+dd„Z,dd„Z-d'd d!„Z.e*ƒZ/e/d"k�r@ed#e/ƒ‚Gd$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)ÚDistutilsExecErrorÚDistutilsPlatformErrorÚ CompileErrorÚLibErrorÚ LinkError)Ú CCompilerÚgen_preprocess_optionsÚgen_lib_options)Úlog)Ú get_platformÚwin32éé 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\.NETFrameworkÚx86Úamd64Zia64)r z win-amd64zwin-ia64c@sPeZdZdZdd„ZeeƒZdd„ZeeƒZdd„ZeeƒZdd „Ze eƒZd S) ÚRegz2Helper class to read values from the registry cCs:x,tD]$}|j||ƒ}|r||kr||SqWt|ƒ‚dS)N)ÚHKEYSÚ read_valuesÚKeyError)ÚclsÚpathÚkeyÚbaseÚd©rú//usr/lib64/python3.6/distutils/msvc9compiler.pyÚ get_valueAs     z Reg.get_valuecCsnyt||ƒ}Wntk r"dSXg}d}xz$(FrameworkVersion)) r@r;ÚNET_BASErrÚ WINSDK_BASErrrr rrr9)r=r>ÚprÚhrrrrrr<…s.    zMacroExpander.load_macroscCs(x"|jjƒD]\}}|j||ƒ}q W|S)N)r9ÚitemsÚreplace)r=r1r%ÚvrrrÚsub¤szMacroExpander.subN)r2r3r4r?r@r<rIrrrrr8{sr8cCsšd}tjj|ƒ}|d krdS|t|ƒ}tj|d…jddƒ\}}t|dd …ƒd}|dkrf|d7}t|dd…ƒd }|dkr†d }|dkr–||SdS) zÃReturn 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.réNú r é ég$@réÿÿÿÿéþÿÿÿ)Úsysr>ÚfindÚlenÚsplitÚint)Úprefixr$r1ÚrestZ majorVersionZ minorVersionrrrÚget_build_version©s  rWcCs4g}x*|D]"}tjj|ƒ}||kr |j|ƒq W|S)znReturn a list of normalized paths with duplicates removed. The current order of paths is maintained. )ÚosrÚnormpathr!)ÚpathsZ reduced_pathsrDZnprrrÚnormalize_and_reduce_pathsÂs   r[cCs@|jtjƒ}g}x|D]}||kr|j|ƒqWtjj|ƒ}|S)z8Remove duplicate values of an environment variable. )rSrXÚpathsepr!Újoin)ZvariableZoldListZnewListr$Z newVariablerrrÚremoveDuplicatesÐs   r^c Cst|}ytjd|dƒ}Wn"tk r>tjdƒd}YnX| sTtjj|ƒ rÊd|}tj j |dƒ}|r¼tjj|ƒr¼tjj |tj tj dƒ}tjj |ƒ}tjj|ƒsÊtjd|ƒdSntjd|ƒ|sÜtjd ƒdStjj |d ƒ}tjj|ƒrú|Stjd ƒdS) z¨Find 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\VCrAz%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)r:rrrr ÚdebugrXrÚisdirÚenvironÚgetr]ÚpardirÚabspathÚisfile)r>r;rAZtoolskeyZtoolsdirÚ vcvarsallrrrÚfind_vcvarsallÛs2         rgc Cs8t|ƒ}tdƒ}i}|dkr$tdƒ‚tjd||ƒtjd||ftjtjd �}z¨|jƒ\}}|j ƒd krvt|j d ƒƒ‚|j d ƒ}xr|j d ƒD]d}t j |ƒ}d |kr¤qŒ|jƒ}|j d dƒ\} } | jƒ} | |krŒ| jtjƒrä| dd…} t| ƒ|| <qŒWWd|jjƒ|jjƒXt|ƒt|ƒk�r4ttt|jƒƒƒƒ‚|S)zDLaunch vcvarsall.bat and read the settings from its environment ÚincludeÚlibÚlibpathrNzUnable to find vcvarsall.batz'Calling 'vcvarsall.bat %s' (version=%s)z "%s" %s & set)ÚstdoutÚstderrrr.Ú ú=r)rhrirjrrN)rgÚsetrr r_Ú subprocessÚPopenÚPIPEZ communicateÚwaitr-rSrr)Ústripr(ÚendswithrXr\r^rkÚcloserlrRÚ ValueErrorÚstrÚlistÚkeys) r>ZarchrfZ interestingÚresultÚpopenrkrlÚlinerr+rrrÚquery_vcvarsallþs<         r~g @z(VC %0.1f is not supported by this modulec @sÞeZdZdZdZiZdgZdddgZdgZdgZ eeee Z d Z d Z d Z d Zd ZZdZd.dd„Zd/dd„Zd0dd„Zd1dd„Zd2dd„Zd3dd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd4d*d+„Zd,d-„ZdS)5Ú 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.exercCs8tj||||ƒt|_d|_g|_d|_d|_d|_dS)NzSoftware\Microsoft\VisualStudioF) rr?ÚVERSIONÚ_MSVCCompiler__versionZ_MSVCCompiler__rootÚ_MSVCCompiler__pathsÚ plat_nameÚ_MSVCCompiler__archÚ initialized)r=ÚverboseZdry_runZforcerrrr?JszMSVCCompiler.__init__NcCs0|j stdƒ‚|dkrtƒ}d%}||kr8td|fƒ‚dtjkrvdtjkrv|jdƒrvd|_d |_d |_ d |_ d |_ nÄ|tƒksˆ|dkr’t |}nt tƒd t |}t t|ƒ}|djtjƒ|_|dtjd<|dtjd<t|jƒdk�rþtd|jƒ‚|jdƒ|_|jd ƒ|_|jd ƒ|_ |jd ƒ|_ |jd ƒ|_ y,x&tjdjdƒD]}|jj|ƒ�qNWWntk �r|YnXt|jƒ|_dj|jƒtjd<d|_|jdk�rÒdddddg|_ddddddg|_n&ddddddg|_dddddddg|_ddd g|_|jd!k�rddd"d#g|_dg|_d$|_dS)&Nzdon't init multiple timesr ú win-amd64úwin-ia64z--plat-name must be one of %sZDISTUTILS_USE_SDKZMSSdkzcl.exezlink.exezlib.exezrc.exezmc.exeÚ_rrirhrzxPython was built with %s, and extensions need to be built with the same version of the compiler, but it isn't installed.ú;rz/nologoz/Oxz/MDz/W3z/DNDEBUGz/Odz/MDdz/Z7z/D_DEBUGz/GS-z/DLLz/INCREMENTAL:NOéz/INCREMENTAL:noz/DEBUGT)r r‡rˆ) r…ÚAssertionErrorr rrXraÚfind_exeÚccÚlinkerriÚrcÚmcÚPLAT_TO_VCVARSr~r€rSr\r‚rRZ_MSVCCompiler__productr!rr[r]Zpreprocess_optionsr„Úcompile_optionsÚcompile_options_debugÚldflags_sharedr�Úldflags_shared_debugZldflags_static)r=rƒZok_platsZ plat_specZvc_envrDrrrÚ initializeUsf                   zMSVCCompiler.initializeÚcCsâ|dkr d}g}xÌ|D]Ä}tjj|ƒ\}}tjj|ƒd}|tjj|ƒd…}||jkrdtd|ƒ‚|rttjj|ƒ}||jkrš|j tjj |||j ƒƒq||j krÀ|j tjj |||j ƒƒq|j tjj |||j ƒƒqW|S)Nr˜rzDon't know how to compile %s)rXrÚsplitextÚ splitdriveÚisabsÚsrc_extensionsrÚbasenameÚ_rc_extensionsr!r]Ú res_extensionÚ_mc_extensionsÚ obj_extension)r=Zsource_filenamesZ strip_dirÚ output_dirZ obj_namesZsrc_namerÚextrrrÚobject_filenames«s(         zMSVCCompiler.object_filenamesc Cst|js|jƒ|j||||||ƒ} | \}} }} } |p6g} | jdƒ|rT| j|jƒn | j|jƒ�x | D�]}y| |\}}Wntk r”whYnX|r¦tj j |ƒ}||j kr¼d|}�nT||j krÒd|}�n>||j k�r>|}d|}y"|j|jg| |g|gƒWqhtk �r8}zt|ƒ‚WYdd}~XqhXqhnÒ||jk�rtj j|ƒ}tj j|ƒ}yl|j|jgd|d|g|gƒtj jtj j|ƒƒ\}}tj j||dƒ}|j|jgd|g|gƒWqhtk �rú}zt|ƒ‚WYdd}~XqhXqhntd||fƒ‚d |}y&|j|jg| | ||g|ƒWqhtk �rj}zt|ƒ‚WYdd}~XqhXqhW| S) Nz/cz/Tcz/Tpz/foz-hz-rz.rcz"Don't know how to compile %s to %sz/Fo)r…r—Z_setup_compiler!Úextendr”r“rrXrrdÚ _c_extensionsÚ_cpp_extensionsržÚspawnr�rrr Údirnamer‘r™r�r]rŽ)r=Zsourcesr¢r9Z include_dirsr_Ú extra_preargsÚextra_postargsZdependsZ compile_infoÚobjectsZpp_optsZbuildZ compile_optsÚobjÚsrcr£Z input_optZ output_optÚmsgZh_dirZrc_dirrr‰Zrc_filerrrÚcompileÊsj              zMSVCCompiler.compilec Csž|js|jƒ|j||ƒ\}}|j||d�}|j||ƒrŽ|d|g}|rJy|j|jg|ƒWqštk rŠ}zt|ƒ‚WYdd}~XqšXn t j d|ƒdS)N)r¢z/OUT:zskipping %s (up-to-date)) r…r—Ú_fix_object_argsÚlibrary_filenameÚ _need_linkr¨rirrr r_) r=r¬Zoutput_libnamer¢r_Ú target_langÚoutput_filenameZlib_argsr¯rrrÚcreate_static_libs zMSVCCompiler.create_static_libcCsX|js|jƒ|j||ƒ\}}|j|||ƒ}|\}}}|rL|jdt|ƒƒt||||ƒ}|dk rptjj ||ƒ}|j ||ƒ�rH|t j kr¬| rœ|j dd…}q¾|jdd…}n| r¸|j }n|j}g}x|pÊgD]}|jd|ƒqÌW||||d|g}tjj|dƒ} |dk �rPtjjtjj|ƒƒ\}}tjj | |j|ƒƒ}|jd|ƒ|j|| |ƒ| �rp| |dd…<| �r€|j| ƒ|jtjj|ƒƒy|j|jg|ƒWn,tk �rÔ}zt|ƒ‚WYdd}~XnX|j||ƒ}|dk �rT|\}}d||f}y|jdd d ||gƒWn,tk �rD}zt|ƒ‚WYdd}~XnXn tjd |ƒdS) Nz5I don't know what to do with 'runtime_library_dirs': rz/EXPORT:z/OUT:rz/IMPLIB:z-outputresource:%s;%szmt.exez-nologoz -manifestzskipping %s (up-to-date))r…r—r±Z _fix_lib_argsÚwarnrxr rXrr]r³rÚ EXECUTABLEr–r•r!r©r™r�r²Úmanifest_setup_ldargsr¥Zmkpathr¨r�rrÚmanifest_get_embed_infor r_)r=Ú target_descr¬rµr¢Z librariesZ library_dirsZruntime_library_dirsZexport_symbolsr_rªr«Ú build_tempr´Z fixed_argsZlib_optsZldflagsZ export_optsZsymÚld_argsZdll_nameZdll_extZ implib_filer¯ZmfinfoZ mffilenameÚmfidZout_argrrrÚlink8sl           zMSVCCompiler.linkcCs,tjj|tjj|ƒdƒ}|jd|ƒdS)Nz .manifestz/MANIFESTFILE:)rXrr]r�r!)r=rµr¼r½Ú temp_manifestrrrr¹—sz"MSVCCompiler.manifest_setup_ldargscCs`x,|D] }|jdƒr|jddƒd}PqWdS|tjkr>d}nd}|j|ƒ}|dkrXdS||fS)Nz/MANIFESTFILE:ú:rr )Ú startswithrSrr¸Ú_remove_visual_c_ref)r=r»r½ÚargrÀr¾rrrrº£s    z$MSVCCompiler.manifest_get_embed_infocCs²y˜t|ƒ}z |jƒ}Wd|jƒXtjdtjƒ}tj|d|ƒ}d}tj|d|ƒ}tjdtjƒ}tj||ƒdkrrdSt|dƒ}z|j|ƒ|S|jƒXWnt k r¬YnXdS)NzU|)r˜z*\s*zI|)Úw) ÚopenÚreadrvÚrer°ÚDOTALLrIÚsearchÚwriteÚOSError)r=Z manifest_fileZ manifest_fZ manifest_bufÚpatternrrrrûs.     z!MSVCCompiler._remove_visual_c_refcCsd|S)Nz /LIBPATH:r)r=ÚdirrrrÚlibrary_dir_optionæszMSVCCompiler.library_dir_optioncCs tdƒ‚dS)NztjdjdƒD]*}tjjtjj|ƒ|ƒ}tjj|ƒrH|SqHW|S)aŒReturn 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'. ZPathrŠ)r‚rXrr]rdrerarS)r=ZexerDÚfnrrrr�s   zMSVCCompiler.find_exe)rrr)N)rr˜)NNNrNNN)NrN) NNNNNrNNNN)r) r2r3r4r5Z compiler_typeZ executablesr¦r§ržr rœrŸr¡Zstatic_lib_extensionZshared_lib_extensionZstatic_lib_formatZshared_lib_formatZ exe_extensionr?r—r¤r°r¶r¿r¹rºrÃrÏrÐrÑrÔr�rrrrr,sR  X  V  R + rl)r)1r5rXrprPrÈZdistutils.errorsrrrrrZdistutils.ccompilerrrr Z distutilsr Zdistutils.utilr ÚwinregZ OpenKeyExrZEnumKeyr Z EnumValuer'ÚerrorrZ HKEY_USERSÚHKEY_CURRENT_USERÚHKEY_LOCAL_MACHINEZHKEY_CLASSES_ROOTrÚplatformÚmaxsizeZ NATIVE_WIN64r:rCrBr’rr8rWr[r^rgr~r€rrrrrÚsN  >. # )