3 \w@sPddlZddlZddlZddlZddlmZmZmZmZm Z ddl m Z m Z m Z ddlmZddlmZddlZejZejZejZejZejejejejfZej dkoej!d%kZ"e"rd Z#d Z$d Z%n d Z#d Z$dZ%ddddZ&GdddZ'GdddZ(ddZ)ddZ*ddZ+ddZ,d&dd Z-e)Z.e.d!krr?r;rHrrrrr7{sr7cCsd}tjj|}|d krdS|t|}tj|djdd\}}t|dd d}|dkrf|d7}t|ddd}|dkrd }|dkr||SdS) NzMSC v.r r g$@r)sysr=findlensplitint)prefixr$r1restZ majorVersionZ minorVersionrrrget_build_versions  rVcCs4g}x*|D]"}tjj|}||kr |j|q W|S)N)osrnormpathr!)pathsZ reduced_pathsrCZnprrrnormalize_and_reduce_pathss   rZcCs@|jtj}g}x|D]}||kr|j|qWtjj|}|S)N)rRrWpathsepr!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||stjddStjj |d }tjj|r|Stjd dS) Nz %s\Setup\VCr@z%Unable to find productdir in registryzVS%0.f0COMNTOOLSZVCz%s is not a valid directoryz Env var %s is not set or invalidzNo productdir foundz vcvarsall.batzUnable to find vcvarsall.bat)r9rrrr debugrWrisdirenvirongetr\pardirabspathisfile)r=r:r@ZtoolskeyZtoolsdir vcvarsallrrrfind_vcvarsalls2         rfc 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)NincludeliblibpathrzUnable to find vcvarsall.batz'Calling 'vcvarsall.bat %s' (version=%s)z "%s" %s & set)stdoutstderrrr. =r)rgrhrirrM)rfsetrr r^ subprocessPopenPIPEZ communicatewaitr-rRrr)stripr(endswithrWr[r]rjcloserkrQ ValueErrorstrlistkeys) r=ZarchreZ interestingresultpopenrjrklinerr+rrrquery_vcvarsalls<         r}g @z(VC %0.1f is not supported by this modulec @seZdZdZiZdgZdddgZdgZdgZeeeeZ dZ d Z d Z d Z d ZZd Zd-ddZd.ddZd/ddZd0ddZd1ddZd2ddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd3d)d*Zd+d,ZdS)4 MSVCCompilerZmsvcz.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__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!extendrrrrWrrc _c_extensions_cpp_extensionsrspawnrrrrdirnamerrrr\r)r<Zsourcesrr8Z 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_linkrrhrrr 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_argswarnrwr rWrr\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:)rWrr\rr!)r<rrr temp_manifestrrrrsz"MSVCCompiler.manifest_setup_ldargscCs`x,|D] }|jdr|jddd}PqWdS|tjkr>d}nd}|j|}|dkrXdS||fS)Nz/MANIFESTFILE::rr ) startswithrRrr_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) openreadrurerDOTALLrHsearchwriteOSError)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)NZPathr)rrWrr\rcrdr`rR)r<ZexerCfnrrrrs   zMSVCCompiler.find_exe)rrr)N)rr)NNNrNNN)NrN) NNNNNrNNNN)r)r2r3r4Z compiler_typeZ executablesrrrrrrrZstatic_lib_extensionZshared_lib_extensionZstatic_lib_formatZshared_lib_formatZ exe_extensionr>rrrrrrrrrrrrrrrrrr~,sP  X  V  R + r~l)r)0rWrorOrZdistutils.errorsrrrrrZdistutils.ccompilerrrr Z distutilsr Zdistutils.utilr winregZ OpenKeyExrZEnumKeyr Z EnumValuer'errorrZ HKEY_USERSHKEY_CURRENT_USERHKEY_LOCAL_MACHINEZHKEY_CLASSES_ROOTrplatformmaxsizeZ NATIVE_WIN64r9rBrArrr7rVrZr]rfr}rr~rrrrsL  >. # )