U Æ:âe/wã@sRdZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z m Z mZddlmZddlmZddlZejZejZejZejZejejejejfZ ej!dko²ej"dkZ#e#rÆd Z$d Z%d Z&n d Z$d Z%dZ&dddœZ'Gdd„dƒZ(Gdd„dƒZ)dd„Z*dd„Z+dd„Z,dd„Z-d$dd„Z.e*ƒZ/e/d kr>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Úwin32lz1Software\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Úx86Zamd64©r z win-amd64c@sPeZdZdZdd„ZeeƒZdd„ZeeƒZdd„ZeeƒZdd „Ze eƒZd S) ÚRegz2Helper class to read values from the registry cCs:tD](}| ||¡}|r||kr||Sqt|ƒ‚dS©N)ÚHKEYSÚ read_valuesÚKeyError)ÚclsÚpathÚkeyÚbaseÚd©rúr?r;rIrrrrr7zsr7cCsšd}tj |¡}|dkrdS|t|ƒ}tj|d… dd¡\}}t|dd…ƒd}|dkrf|d7}t|d d …ƒ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.éÿÿÿÿéNú réþÿÿÿé éég$@r)Úsysr=ÚfindÚlenÚsplitÚint)Úprefixr#r0ÚrestZ majorVersionZ minorVersionrrrÚget_build_version¨s  rXcCs0g}|D]"}tj |¡}||kr| |¡q|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<| tj¡}g}|D]}||kr| |¡qtj |¡}|S)z8Remove duplicate values of an environment variable. )rTrYÚpathsepr Újoin)ÚvariableZoldListZnewListr#Z newVariablerrrÚremoveDuplicatesÏs   r`cCst|}zt d|d¡}Wn"tk r>t d¡d}YnX|rPtj |¡sÆd|}tj   |d¡}|r¸tj |¡r¸tj  |tj tj d¡}tj  |¡}tj |¡sÆt d|¡dSnt d|¡|sØt d ¡dStj  |d ¡}tj |¡rö|St d ¡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\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.batúUnable to find vcvarsall.bat)r9rrrr ÚdebugrYrÚisdirÚenvironÚgetr^ÚpardirÚabspathÚisfile)r=r:r@ZtoolskeyZtoolsdirÚ vcvarsallrrrÚfind_vcvarsallÚs4 ÿ       rjc Cs8t|ƒ}ddddh}i}|dkr(tdƒ‚t d||¡tjd||ftjtjd }z¤|  ¡\}}|  ¡d krzt|  d ¡ƒ‚|  d ¡}|  d ¡D]d}t |¡}d |kr¦qŽ| ¡}|  d d¡\} } |  ¡} | |krŽ|  tj¡ræ| dd…} t| ƒ|| <qŽW5|j ¡|j  ¡Xt|ƒt|ƒkr4ttt| ¡ƒƒƒ‚|S)zDLaunch vcvarsall.bat and read the settings from its environment ÚincludeÚlibZlibpathrNraz'Calling 'vcvarsall.bat %s' (version=%s)z "%s" %s & set)ÚstdoutÚstderrrr-Ú ú=rrJ)rjrr rbÚ subprocessÚPopenÚPIPErmÚclosernÚ communicateÚwaitr,rTrr(Ústripr'ÚendswithrYr]r`rSÚ ValueErrorÚstrÚlistÚkeys) r=ZarchriZ interestingÚresultÚpopenrmrnÚlinerr*rrrÚquery_vcvarsallýs> þ        r€rAz(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.cxxú.rcz.mcz.resz.objz.libz.dllz%s%sz.exercCs8t ||||¡t|_d|_g|_d|_d|_d|_dS)NzSoftware\Microsoft\VisualStudioF) rr>ÚVERSIONÚ_MSVCCompiler__versionZ_MSVCCompiler__rootÚ_MSVCCompiler__pathsÚ plat_nameÚ_MSVCCompiler__archÚ initialized)r<ÚverboseÚdry_runÚforcerrrr>IszMSVCCompiler.__init__NcCs(|jrtdƒ‚|dkrtƒ}d}||kr6td|fƒ‚dtjkrtdtjkrt| d¡rtd|_d|_d|_ d |_ d |_ nÂ|tƒks†|d krt |}nt tƒd t |}t t|ƒ}|d  tj¡|_|dtjd<|dtjd<t|jƒdkrútd|jƒ‚| d¡|_| d¡|_| d¡|_ | d ¡|_ | d ¡|_ z(tjd  d¡D]}|j |¡qHWntk rtYnXt|jƒ|_d |j¡tjd <d|_|jdkrÊdddddg|_ddddddg|_n&ddddddg|_dddddddg|_dddg|_|jd krddd!d"g|_dg|_d#|_dS)$Nzdon't init multiple timesrz--plat-name must be one of %sZDISTUTILS_USE_SDKZMSSdkzcl.exezlink.exezlib.exezrc.exezmc.exer Ú_rrlrkrzxPython was built with %s, and extensions need to be built with the same version of the compiler, but it isn't installed.ú;r z/nologoz/Oxz/MDz/W3z/DNDEBUGz/Odz/MDdz/Z7z/D_DEBUGz/GS-z/DLLz/INCREMENTAL:NOéz/INCREMENTAL:noz/DEBUGT) rˆÚAssertionErrorr rrYrdÚfind_exeÚccÚlinkerrlÚrcÚmcÚPLAT_TO_VCVARSr€rƒrTr]r…rSZ_MSVCCompiler__productr rr\r^Zpreprocess_optionsr‡Úcompile_optionsÚcompile_options_debugÚldflags_sharedr„Úldflags_shared_debugZldflags_static)r<r†Zok_platsZ plat_specZvc_envrDrrrÚ initializeTs€ÿ  ÿ ý       ÿÿ ÿ ÿ  ÿzMSVCCompiler.initializeÚcCsÞ|dkr d}g}|D]Ä}tj |¡\}}tj |¡d}|tj |¡d…}||jkrbtd|ƒ‚|rrtj |¡}||jkr˜|  tj  |||j ¡¡q||j kr¾|  tj  |||j ¡¡q|  tj  |||j ¡¡q|S)Nr›rzDon't know how to compile %s)rYrÚ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  Csp|js| ¡| ||||||¡} | \}} }} } |p6g} |  d¡|rT|  |j¡n |  |j¡| D]}z| |\}}Wntk r’YqdYnX|r¤tj   |¡}||j krºd|}nT||j krÐd|}n>||j kr<|}d|}z"| |jg| |g|g¡Wqdtk r6}z t|ƒ‚W5d}~XYqdXqdnÒ||jkrþtj  |¡}tj  |¡}zl| |jgd|d|g|g¡tj  tj  |¡¡\}}tj  ||d¡}| |jgd|g|g¡Wqdtk rø}z t|ƒ‚W5d}~XYqdXqdntd||fƒ‚d |}z&| |jg| | ||g|¡Wqdtk rh}z t|ƒ‚W5d}~XYqdXqd| S) Nz/cz/Tcz/Tpz/foz-hz-rr‚z"Don't know how to compile %s to %sz/Fo)rˆršZ_setup_compiler Úextendr—r–rrYrrgÚ _c_extensionsÚ_cpp_extensionsr¡Úspawnr“rrr£Údirnamer”rœr r^r‘)r<Zsourcesr¥r8Z include_dirsrbÚ extra_preargsÚextra_postargsZdependsZ compile_infoÚobjectsZpp_optsZbuildZ compile_optsÚobjÚsrcr¦Z input_optZ output_optÚmsgZh_dirZrc_dirrrŒZrc_filerrrÚcompileÈsˆ ÿ          ÿÿ     ÿÿ ÿÿ ÿÿþ zMSVCCompiler.compilec Csž|js| ¡| ||¡\}}|j||d}| ||¡rŽ|d|g}|rJz| |jg|¡Wqštk rŠ}z t|ƒ‚W5d}~XYqšXn t   d|¡dS)N)r¥ú/OUT:úskipping %s (up-to-date)) rˆršÚ_fix_object_argsÚlibrary_filenameÚ _need_linkr«rlrrr rb) r<r¯Zoutput_libnamer¥rbÚ target_langÚoutput_filenameZlib_argsr²rrrÚcreate_static_libsÿ zMSVCCompiler.create_static_libc CsT|js| ¡| ||¡\}}| |||¡}|\}}}|rL| dt|ƒ¡t||||ƒ}|dk rptj  ||¡}|  ||¡rD|t j kr¬| rœ|j dd…}q¾|jdd…}n| r¸|j }n|j}g}|pÈgD]}| d|¡qÊ||||d|g}tj |d¡} |dk rLtj tj |¡¡\}}tj  | | |¡¡}| d|¡| || |¡| rl| |dd…<| r|| | ¡| tj |¡¡z| |jg|¡Wn,tk rÐ}z t|ƒ‚W5d}~XYnX| ||¡}|dk rP|\}}d||f}z| dd d ||g¡Wn,tk r@}z t|ƒ‚W5d}~XYnXn t d |¡dS) Nz5I don't know what to do with 'runtime_library_dirs': rz/EXPORT:r´rz/IMPLIB:z-outputresource:%s;%szmt.exez-nologoz -manifestrµ)rˆršr¶Z _fix_lib_argsÚwarnrzr rYrr^r¸rÚ EXECUTABLEr™r˜r r¬rœr r·Úmanifest_setup_ldargsr¨Zmkpathr«r’rrÚmanifest_get_embed_infor rb)r<Ú target_descr¯rºr¥Z librariesZ library_dirsZruntime_library_dirsZexport_symbolsrbr­r®Ú build_tempr¹Z fixed_argsZlib_optsZldflagsZ export_optsZsymÚld_argsZdll_nameZdll_extZ implib_filer²ZmfinfoZ mffilenameÚmfidZout_argrrrÚlink6s„ÿ ÿþ   ÿÿ  ÿþ      ÿ zMSVCCompiler.linkcCs,tj |tj |¡d¡}| d|¡dS)Nz .manifestú/MANIFESTFILE:)rYrr^r r )r<rºrÁrÂÚ temp_manifestrrrr¾•s þz"MSVCCompiler.manifest_setup_ldargscCs^|D]"}| d¡r| dd¡d}q,qdS|tjkr|)r›z*\s*zI|)Úw) ÚopenrtÚreadÚrer³ÚDOTALLrIÚsearchÚwriteÚOSError)r<Z manifest_fileZ manifest_fZ manifest_bufÚpatternrrrrɹs2   ýþ   z!MSVCCompiler._remove_visual_c_refcCsd|S)Nz /LIBPATH:r©r<ÚdirrrrÚlibrary_dir_optionäszMSVCCompiler.library_dir_optioncCs tdƒ‚dS)Nzršr§r³r»rÄr¾r¿rÉrÖr×rØrÛrrrrrr+sl ÿÿ Wý þ Xû ó _ + r)r )1r4rYrqrQrÎZdistutils.errorsrrrrrZdistutils.ccompilerrrr Z distutilsr Zdistutils.utilr ÚwinregZ OpenKeyExrZEnumKeyrZ EnumValuer&ÚerrorrZ HKEY_USERSÚHKEY_CURRENT_USERÚHKEY_LOCAL_MACHINEZHKEY_CLASSES_ROOTrÚplatformÚmaxsizeZ NATIVE_WIN64r9rCrBr•rr7rXr\r`rjr€rƒrrrrrÚsP  ýþ>. # )