3 \w@sTdZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z m Z mZddlmZddlmZddlZejZejZejZejZejejejejfZ ej!dkoej"d&kZ#e#rd Z$d Z%d Z&n d Z$dZ%dZ&ddddZ'GdddZ(GdddZ)ddZ*ddZ+ddZ,ddZ-d'd d!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)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\.NETFrameworkx86amd64Zia64)r z win-amd64zwin-ia64c@sPeZdZdZddZeeZddZeeZddZeeZdd Ze eZd S) Regz2Helper class to read values from the registry cCs:x,tD]$}|j||}|r||kr||SqWt|dS)N)HKEYS read_valuesKeyError)clspathkeybasedr%/usr/lib64/python3.6/msvc9compiler.py get_valueAs     z Reg.get_valuecCsnyt||}Wntk r"dSXg}d}xz$(FrameworkVersion)) r@r;NET_BASErr WINSDK_BASErrrr rrr9)r=r>prhrrrrrr<s.    zMacroExpander.load_macroscCs(x"|jjD]\}}|j||}q W|S)N)r9itemsreplace)r=r1r%vrrrsubszMacroExpander.subN)r2r3r4r?r@r<rIrrrrr8{sr8cCsd}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$r1restZ majorVersionZ minorVersionrrrget_build_versions  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. )osrnormpathr!)pathsZ reduced_pathsrDZnprrrnormalize_and_reduce_pathss   r[cCs@|jtj}g}x|D]}||kr|j|qWtjj|}|S)z8Remove duplicate values of an environment variable. )rSrXpathsepr!join)ZvariableZoldListZnewListr$Z newVariablerrrremoveDuplicatess   r^c 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\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 debugrXrisdirenvirongetr]pardirabspathisfile)r>r;rAZtoolskeyZtoolsdir vcvarsallrrrfind_vcvarsalls2         rgc Cs8t|}td}i}|dkr$tdtjd||tjd||ftjtjd }z|j\}}|j d krvt|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|kr4ttt|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. =r)rhrirjrrN)rgsetrr r_ subprocessPopenPIPEZ communicatewaitr-rSrr)stripr(endswithrXr\r^rkcloserlrR ValueErrorstrlistkeys) r>ZarchrfZ interestingresultpopenrkrllinerr+rrrquery_vcvarsalls<         r~g @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=verboseZdry_runforcerrrr?JszMSVCCompiler.__init__NcCs|dkrt}d$}||kr(td|fdtjkrfdtjkrf|jdrfd|_d|_d |_d |_d |_ n|tksx|dkrt |}nt td t |}t t |}|d j tj|_|dtjd<|dtjd<t|jdkrtd|j|jd|_|jd|_|jd |_|jd |_|jd |_ y,x&tjd j dD]}|jj|q||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!extendrrrrXrrd _c_extensions_cpp_extensionsrspawnrrrrdirnamerrrr]r)r=Zsourcesrr9Z include_dirsr_ extra_preargsextra_postargsZdependsZ compile_infoobjectsZpp_optsZbuildZ 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_linkrrirrr r_) r=rZoutput_libnamerr_ 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_argswarnrxr rXrr]rr EXECUTABLErrr!rrrrmanifest_setup_ldargsrZmkpathrrrrmanifest_get_embed_infor r_)r= target_descrrrZ librariesZ library_dirsZruntime_library_dirsZexport_symbolsr_rr build_temprZ fixed_argsZlib_optsZldflagsZ export_optsZsymld_argsZdll_nameZdll_extZ implib_filerZmfinfoZ mffilenamemfidZout_argrrrlink8sl           zMSVCCompiler.linkcCs,tjj|tjj|d}|jd|dS)Nz .manifestz/MANIFESTFILE:)rXrr]rr!)r=rrr temp_manifestrrrrsz"MSVCCompiler.manifest_setup_ldargscCs`x,|D] }|jdr|jddd}PqWdS|tjkr>d}nd}|j|}|dkrXdS||fS)Nz/MANIFESTFILE::rr ) startswithrSrr_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) openreadrvrerDOTALLrIsearchwriteOSError)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'. ZPathr)rrXrr]rdrerarS)r=ZexerDfnrrrrs   zMSVCCompiler.find_exe)rrr)N)rr)NNNrNNN)NrN) NNNNNrNNNN)r) r2r3r4r5Z compiler_typeZ executablesrrrrrrrZstatic_lib_extensionZshared_lib_extensionZstatic_lib_formatZshared_lib_formatZ exe_extensionr?rrrrrrrrrrrrrrrrrr,sR  X  V  R + rl)r)1r5rXrprPrZdistutils.errorsrrrrrZdistutils.ccompilerrrr Z distutilsr Zdistutils.utilr winregZ OpenKeyExrZEnumKeyr Z EnumValuer'errorrZ HKEY_USERSHKEY_CURRENT_USERHKEY_LOCAL_MACHINEZHKEY_CLASSES_ROOTrplatformmaxsizeZ NATIVE_WIN64r:rCrBrrr8rWr[r^rgr~rrrrrrsN  >. # )