B ŒÛ™\/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:x,tD]$}| ||¡}|r||kr||SqWt|ƒ‚dS)N)ÚHKEYSÚ read_valuesÚKeyError)ÚclsÚpathÚkeyÚbaseÚd©rú-/usr/lib/python3.7/distutils/msvc9compiler.pyÚ get_value@s     z Reg.get_valuecCsnyt||ƒ}Wntk r"dSXg}d}xt 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.batzUnable to find vcvarsall.bat)r7rrrr ÚdebugrVrÚisdirÚenvironÚgetr[ÚpardirÚabspathÚisfile)r;r8r>ZtoolskeyZtoolsdirÚ vcvarsallrrrÚfind_vcvarsallÚs2         rec Cs<t|ƒ}ddddh}i}|dkr(tdƒ‚t d||¡tjd||ftjtjd }z¨| ¡\}}| ¡d krzt|  d ¡ƒ‚|  d ¡}xr|  d ¡D]d}t   |¡}d |kr¨q|  ¡}|  d d¡\} } |  ¡} | |kr|  tj¡rè| dd…} t| ƒ|| <qWWd|j ¡|j ¡Xt|ƒt|ƒkr8ttt| ¡ƒƒƒ‚|S)zDLaunch vcvarsall.bat and read the settings from its environment ÚincludeÚlibZlibpathrNzUnable to find vcvarsall.batz'Calling 'vcvarsall.bat %s' (version=%s)z "%s" %s & set)ÚstdoutÚstderrrr+Ú ú=rrG)rerr r]Ú subprocessÚPopenÚPIPEZ communicateÚwaitr*rQrr&Ústripr%ÚendswithrVrZr\rhÚcloserirPÚ ValueErrorÚstrÚlistÚkeys) r;ZarchrdZ interestingÚresultÚpopenrhriÚlinerr(rrrÚquery_vcvarsallýs<          rzg @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.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:ÚverboseZdry_runZforcerrrr<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 ¡|_ y,x&tjd  d¡D]}|j |¡qJWWntk rxYnXt|jƒ|_d |j¡tjd <d|_|jdkrÎdddddg|_ddddddg|_n&ddddddg|_dddddddg|_dddg|_|jd krddd!d"g|_dg|_d#|_dS)$Nzdon't init multiple times)r z win-amd64z--plat-name must be one of %sZDISTUTILS_USE_SDKZMSSdkzcl.exezlink.exezlib.exezrc.exezmc.exer Ú_rrgrfrzxPython 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 rrVr_Úfind_exeÚccÚlinkerrgÚrcÚmcÚPLAT_TO_VCVARSrzr|rQrZr~rPZ_MSVCCompiler__productrrrYr[Zpreprocess_optionsr€Úcompile_optionsÚcompile_options_debugÚldflags_sharedr}Úldflags_shared_debugZldflags_static)r:rZok_platsZ plat_specZvc_envrArrrÚ initializeTsf                   zMSVCCompiler.initializeÚcCsâ|dkr d}g}xÌ|D]Ä}tj |¡\}}tj |¡d}|tj |¡d…}||jkrdtd|ƒ‚|rttj |¡}||jkrš|  tj  |||j ¡¡q||j krÀ|  tj  |||j ¡¡q|  tj  |||j ¡¡qW|S)Nr’rzDon't know how to compile %s)rVrÚsplitextÚ splitdriveÚisabsÚsrc_extensionsrÚbasenameÚ_rc_extensionsrr[Ú 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| ¡| ||||||¡} | \}} }} } |p6g} |  d¡|rT|  |j¡n |  |j¡x | D]}y| |\}}Wntk r”whYnX|r¦tj   |¡}||j kr¼d|}nT||j krÒd|}n>||j kr>|}d|}y"| |jg| |g|g¡Wqhtk r8}z t|ƒ‚Wdd}~XYqhXqhnÒ||jkrtj  |¡}tj  |¡}yl| |jgd|d|g|g¡tj  tj  |¡¡\}}tj  ||d¡}| |jgd|g|g¡Wqhtk rú}z t|ƒ‚Wdd}~XYqhXqhntd||fƒ‚d |}y&| |jg| | ||g|¡Wqhtk rj}z t|ƒ‚Wdd}~XYqhXqhW| S) Nz/cz/Tcz/Tpz/foz-hz-rz.rcz"Don't know how to compile %s to %sz/Fo)rr‘Z_setup_compilerÚextendrŽrrrVrrbÚ _c_extensionsÚ_cpp_extensionsr˜ÚspawnrŠrrršÚdirnamer‹r“r—r[rˆ)r:Zsourcesrœr6Z include_dirsr]Ú extra_preargsÚextra_postargsZdependsZ compile_infoÚobjectsZpp_optsZbuildZ compile_optsÚobjÚsrcrZ input_optZ output_optÚmsgZh_dirZrc_dirrrƒZrc_filerrrÚcompileÈsj              zMSVCCompiler.compilec Csž|js| ¡| ||¡\}}|j||d}| ||¡rŽ|d|g}|rJy| |jg|¡Wqštk rŠ}z t|ƒ‚Wdd}~XYqšXn t   d|¡dS)N)rœz/OUT:zskipping %s (up-to-date)) rr‘Ú_fix_object_argsÚlibrary_filenameÚ _need_linkr¢rgrrr r]) r:r¦Zoutput_libnamerœr]Ú target_langÚoutput_filenameZlib_argsr©rrrÚcreate_static_libs zMSVCCompiler.create_static_libc CsX|js| ¡| ||¡\}}| |||¡}|\}}}|rL| dt|ƒ¡t||||ƒ}|dk rptj  ||¡}|  ||¡rH|t j kr¬| rœ|j dd…}q¾|jdd…}n| r¸|j }n|j}g}x|pÊgD]}| d|¡qÌW||||d|g}tj |d¡} |dk rPtj tj |¡¡\}}tj  | | |¡¡}| d|¡| || |¡| rp| |dd…<| r€| | ¡| tj |¡¡y| |jg|¡Wn,tk rÔ}z t|ƒ‚Wdd}~XYnX| ||¡}|dk rT|\}}d||f}y| dd d ||g¡Wn,tk rD}z t|ƒ‚Wdd}~XYnXn t d |¡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))rr‘r«Z _fix_lib_argsÚwarnrtr rVrr[r­rÚ EXECUTABLErrrr£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Úlink6sl           zMSVCCompiler.linkcCs,tj |tj |¡d¡}| d|¡dS)Nz .manifestz/MANIFESTFILE:)rVrr[r—r)r:r¯r¶r·Ú temp_manifestrrrr³•sz"MSVCCompiler.manifest_setup_ldargscCs`x,|D] }| d¡r| dd¡d}PqWdS|tjkr>d}nd}| |¡}|dkrXdS||fS)Nz/MANIFESTFILE:ú:rrL)Ú startswithrQrr²Ú_remove_visual_c_ref)r:rµr·Úargrºr¸rrrr´¡s    z$MSVCCompiler.manifest_get_embed_infocCs²y˜t|ƒ}z | ¡}Wd| ¡Xt dtj¡}t |d|¡}d}t |d|¡}t dtj¡}t ||¡dkrrdSt|dƒ}z| |¡|S| ¡XWnt k r¬YnXdS)NzU|)r’z*\s*zI|)Úw) ÚopenÚreadrrÚrerªÚDOTALLrFÚ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)Nztjd d¡D]*}tj tj |¡|¡}tj |¡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~rVrr[rbrcr_rQ)r:ZexerAÚfnrrrr‡s   zMSVCCompiler.find_exe)rrr)N)rr’)NNNrNNN)NrN) NNNNNrNNNN)r) r/r0r1r2Z 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  W  V  R + r{)r )1r2rVrlrNrÂZdistutils.errorsrrrrrZdistutils.ccompilerrrr Z distutilsr Zdistutils.utilr ÚwinregZ OpenKeyExrZEnumKeyrZ EnumValuer$ÚerrorrZ HKEY_USERSÚHKEY_CURRENT_USERÚHKEY_LOCAL_MACHINEZHKEY_CLASSES_ROOTrÚplatformÚmaxsizeZ NATIVE_WIN64r7r@r?rŒrr5rUrYr\rerzr|r{rrrrÚsL  >. # )