3 ev@sNdZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z m Z ddlmZddlmZddlZejZejZejZejZejejejejfZej dkoej!d%kZ"e"rd Z#d Z$d Z%n d Z#dZ$dZ%dddZ&GdddZ'GdddZ(ddZ)ddZ*ddZ+ddZ,d&dd Z-e)Z.e.d!kr:ed"e.Gd#d$d$e Z/dS)'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_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\.NETFrameworkx86amd64)r z win-amd64c@sPeZdZdZddZeeZddZeeZddZeeZdd Ze eZd S) Regz2Helper class to read values from the registry cCs:x,tD]$}|j||}|r||kr||SqWt|dS)N)HKEYS read_valuesKeyError)clspathkeybasedrI/tmp/pip-build-vlmub77e/setuptools/setuptools/_distutils/msvc9compiler.py get_value?s     z Reg.get_valuecCsnyt||}Wntk r"dSXg}d}xz$(FrameworkVersion)) rAr;NET_BASErr WINSDK_BASErrrrrrr9)r=r>prhrrrrrr<s.    zMacroExpander.load_macroscCs(x"|jjD]\}}|j||}q W|S)N)r9itemsreplace)r=r0r$vrrrsubszMacroExpander.subN)r2r3r4r?rAr<rJrrrrr8ysr8cCsd}tjj|}|d krdS|t|}tj|djdd\}}t|dd d}|dkrf|d7}t|ddd }|dkrd }|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  rXcCs4g}x*|D]"}tjj|}||kr |j|q W|S)znReturn a list of normalized paths with duplicates removed. The current order of paths is maintained. )osrnormpathr )pathsZ reduced_pathsrEnprrrnormalize_and_reduce_pathss   r]cCs@|jtj}g}x|D]}||kr|j|qWtjj|}|S)z8Remove duplicate values of an environment variable. )rTrYpathsepr join)variableZoldListZnewListr#Z newVariablerrrremoveDuplicatess   rac Cst|}ytjd|d}Wn"tk r>tjdd}YnX| sTtjj| rd|}tj j |d}|rtjj|rtjj |tj tj d}tjj |}tjj|stjd|dSntjd||stjd dStjj |d }tjj|r|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\VCrBz%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 debugrYrisdirenvirongetr_pardirabspathisfile)r>r;rBZtoolskeyZtoolsdir vcvarsallrrrfind_vcvarsalls2         rjc Cs<t|}ddddh}i}|dkr(tdtjd||tjd||ftjtjd }z|j\}}|jd krzt|j d |j d }xr|j d D]d}t j |}d |krq|j }|j d d\} } | j} | |kr| jtjr| dd} t| || <qWWd|jj|jjXt|t|kr8ttt|j|S)zDLaunch vcvarsall.bat and read the settings from its environment includeliblibpathrNzUnable to find vcvarsall.batz'Calling 'vcvarsall.bat %s' (version=%s)z "%s" %s & set)stdoutstderrrr- =rrO)rjrr rb subprocessPopenPIPE communicatewaitr,rTrr(stripr'endswithrYr^rarncloserorS ValueErrorstrlistkeys) r>archri interestingresultpopenrnrolinerr*rrrquery_vcvarsalls<          rg @z(VC %0.1f is not supported by this modulec @seZdZdZdZiZdgZdddgZdgZdgZ eeee Z d Z d Z d Z d Zd ZZdZd.ddZd/ddZd0ddZd1ddZd2ddZd3ddZddZd 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=verbosedry_runforcerrrr?HszMSVCCompiler.__init__NcCs0|j std|dkrt}d$}||kr8td|fdtjkrvdtjkrv|jdrvd|_d|_d |_ d |_ d |_ n|tks|dkrt |}nt td t |}t t|}|d jtj|_|dtjd<|dtjd<t|jdkrtd|j|jd|_|jd|_|jd |_ |jd |_ |jd |_ y,x&tjd jdD]}|jj|qNWWntk r|YnXt|j|_dj|jtjd <d|_|jdkrdddddg|_ddddddg|_n&ddddddg|_dddddddg|_dddg|_|jd krddd!d"g|_dg|_d#|_dS)%Nzdon't init multiple timesr win-amd64z--plat-name must be one of %sZDISTUTILS_USE_SDKZMSSdkzcl.exezlink.exezlib.exezrc.exezmc.exe_rrlrkrzxPython was built with %s, and extensions need to be built with the same version of the compiler, but it isn't installed.;rz/nologoz/O2z/MDz/W3z/DNDEBUGz/Odz/MDdz/Z7z/D_DEBUGz/GS-z/DLLz/INCREMENTAL:NOz/INCREMENTAL:noz/DEBUGT)r r) rAssertionErrorr rrYrdfind_execclinkerrlrcmcPLAT_TO_VCVARSrrrTr^rrSZ_MSVCCompiler__productr rr]r_Zpreprocess_optionsrcompile_optionscompile_options_debugldflags_sharedrldflags_shared_debugZldflags_static)r=rZok_platsZ plat_specZvc_envrErrr initializeSsf                   zMSVCCompiler.initializecCs|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)NrrzDon't know how to compile %s)rYrsplitext splitdriveisabssrc_extensionsrbasename_rc_extensionsr r_ res_extension_mc_extensions obj_extension)r=Zsource_filenamesZ strip_dir output_dirZ obj_namessrc_namerextrrrobject_filenamess(         zMSVCCompiler.object_filenamesc Cst|js|j|j||||||} | \}} }} } |p6g} | jd|rT| j|jn | j|jx | D]}y| |\}}Wntk rwhYnX|rtj j |}||j krd|}nT||j krd|}n>||j kr>|}d|}y"|j|jg| |g|gWqhtk r8}zt|WYdd}~XqhXqhn||jkrtj j|}tj j|}yl|j|jgd|d|g|gtj jtj j|\}}tj j||d}|j|jgd|g|gWqhtk r}zt|WYdd}~XqhXqhntd||fd |}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)rrZ_setup_compiler extendrrrrYrrg _c_extensions_cpp_extensionsrspawnrrrrdirnamerrrr_r)r=sourcesrr9 include_dirsrb extra_preargsextra_postargsdependsZ compile_infoobjectsZpp_optsbuildZ compile_optsobjsrcrZ input_optZ output_optmsgZh_dirZrc_dirrrZrc_filerrrcompilesj              zMSVCCompiler.compilec Cs|js|j|j||\}}|j||d}|j||r|d|g}|rJy|j|jg|Wqtk r}zt|WYdd}~XqXn t j d|dS)N)rz/OUT:zskipping %s (up-to-date)) rr_fix_object_argslibrary_filename _need_linkrrlrrr rb) r=rZoutput_libnamerrb target_langoutput_filenameZlib_argsrrrrcreate_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|pgD]}|jd|qW||||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 ||gWn,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))rrrZ _fix_lib_argswarnr{rrYrr_rr EXECUTABLErrr rrrrmanifest_setup_ldargsrmkpathrrrrmanifest_get_embed_infor rb)r= target_descrrr libraries library_dirsruntime_library_dirsexport_symbolsrbrr build_temprZ fixed_argsZlib_optsZldflagsZ export_optssymld_argsZdll_nameZdll_extZ implib_filerZmfinfoZ mffilenamemfidZout_argrrrlink5sl           zMSVCCompiler.linkcCs,tjj|tjj|d}|jd|dS)Nz .manifestz/MANIFESTFILE:)rYrr_rr )r=rrr temp_manifestrrrrsz"MSVCCompiler.manifest_setup_ldargscCs`x,|D] }|jdr|jddd}PqWdS|tjkr>d}nd}|j|}|dkrXdS||fS)Nz/MANIFESTFILE::rr ) startswithrTrr_remove_visual_c_ref)r=rrargrrrrrrs    z$MSVCCompiler.manifest_get_embed_infocCsyt|}z |j}Wd|jXtjdtj}tj|d|}d}tj|d|}tjdtj}tj||dkrrdSt|d}z|j||S|jXWnt k rYnXdS)NzU|)rz*\s*zI|)w) openreadryrerDOTALLrJsearchwriteOSError)r=Z manifest_fileZ manifest_fZ manifest_bufpatternrrrrs.     z!MSVCCompiler._remove_visual_c_refcCsd|S)Nz /LIBPATH:r)r=dirrrrlibrary_dir_optionszMSVCCompiler.library_dir_optioncCs tddS)NztjdjdD]*}tjjtjj||}tjj|rH|SqHW|S)aReturn 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'. Pathr)rrYrr_rgrhrdrT)r=ZexerEfnrrrrs   zMSVCCompiler.find_exe)rrr)N)rr)NNNrNNN)NrN) NNNNNrNNNN)r) r2r3r4r5 compiler_typeZ executablesrrrrrrrZstatic_lib_extensionshared_lib_extensionZstatic_lib_formatZshared_lib_formatZ exe_extensionr?rrrrrrrrrrrrrrrrrr*sR  W  V  R + rl)r)0r5rYrrrQrZdistutils.errorsrrrrrdistutils.ccompilerrr distutilsr distutils.utilr winreg OpenKeyExrEnumKeyrZ EnumValuer&errorrZ HKEY_USERSHKEY_CURRENT_USERHKEY_LOCAL_MACHINEHKEY_CLASSES_ROOTrplatformmaxsizeZ NATIVE_WIN64r:rDrCrrr8rXr]rarjrrrrrrrsL  >. # )