a „oe{ã@sÚdZddlZddlZddlZddlZddlmZddlmZm Z m Z m Z m Z m Z ddlmZmZddlmZddlmZdd lmZdd lmZdd lmZd d lmZddlmZe d¡Zdd„Z Gdd„deƒZ!dS)z¶distutils.command.build_ext Implements the Distutils 'build_ext' command, for building extension modules (currently limited to C extensions, should accommodate C++ extensions ASAP).éNé)ÚCommand)ÚDistutilsOptionErrorÚDistutilsSetupErrorÚCCompilerErrorÚDistutilsErrorÚ CompileErrorÚDistutilsPlatformError)Úcustomize_compilerÚget_python_version)Úget_config_h_filename)Ú newer_group)Ú Extension)Ú get_platform)Úlogé)Ú py37compat)Ú USER_BASEz3^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$cCsddlm}|ƒdS)Nr©Úshow_compilers)Ú ccompilerrr©rúHC:\Program Files\Certbot\pkgs\setuptools\_distutils\command\build_ext.pyr#s rc@seZdZdZdejZdddddeƒfdd d d efd d ddddefddddddddddgZgd¢Z ddde fgZ d d!„Z d"d#„Z d$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zejd2d3„ƒZd4d5„Zd6d7„Zd8d9„Zd:d;„Zdd?„Zd@dA„ZdBdC„ZdS)DÚ build_extz8build C/C++ extensions (compile/link to build directory)z (separated by '%s'))z build-lib=Úbz(directory for compiled extension modules)z build-temp=Útz1directory for temporary files (build by-products)z plat-name=Úpz>platform name to cross-compile for, if supported (default: %s))ÚinplaceÚiziignore build-lib and put compiled extensions into the source directory alongside your pure Python modulesz include-dirs=ÚIz.list of directories to search for header files)zdefine=ÚDzC preprocessor macros to define)zundef=ÚUz!C preprocessor macros to undefine)z libraries=Úlz!external C libraries to link withz library-dirs=ÚLz.directories to search for external C libraries)zrpath=ÚRz7directories to search for shared C libraries at runtime)z link-objects=ÚOz2extra explicit link objects to include in the link)ÚdebugÚgz'compile/link with debugging information)ÚforceÚfz2forcibly build everything (ignore file timestamps))z compiler=Úczspecify the compiler type)z parallel=Újznumber of parallel build jobs)úswig-cppNz)make SWIG create C++ files (default is C))z swig-opts=Nz!list of SWIG command line options)zswig=Nzpath to the SWIG executable)ÚuserNz#add user include, library and rpath)rr&r(r,r-z help-compilerNzlist available compilerscCs‚d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_d|_d|_d|_d|_dS)Nr)Ú extensionsÚ build_libÚ plat_nameÚ build_temprÚpackageÚ include_dirsÚdefineÚundefÚ librariesÚ library_dirsÚrpathÚ link_objectsr&r(ÚcompilerÚswigÚswig_cppÚ swig_optsr-Úparallel©ÚselfrrrÚinitialize_optionsms*zbuild_ext.initialize_optionsc CsØddlm}| ddddddd d ¡|jdur8|jj|_|jj|_| ¡}|jd d �}|j durn|jj pjg|_ t |j t ƒrŠ|j   t j¡|_ tjtjkr®|j  t j tjd ¡¡|j  |  t jj¡¡||krâ|j  |  t jj¡¡| d¡| d¡|jdu�rg|_|jdu�rg|_nt |jt ƒ�r:|j  t j¡|_|jdu�rNg|_nt |jt ƒ�rl|j  t j¡|_t jdk�rX|j t j tjd¡¡tjtjk�r¶|j t j tjd¡¡|j�rÒt j |jd¡|_nt j |jd¡|_|j  t j tƒ¡¡|j tj¡|j dk�rd}n|j dd…}t j tjd¡}|�rLt j ||¡}|j |¡tj!dd…dk�r¤|j"�s˜|j t j tjddt#ƒd¡¡n |j d¡| $d¡�rØ|j"�sÌ|j | $d¡¡n |j d¡|j%�rü|j%  d¡}d d!„|Dƒ|_%|j&�r|j&  d¡|_&|j'du�r&g|_'n|j'  d"¡|_'|j(�r˜t j t)d ¡}t j t)d¡}t j *|¡�rr|j  |¡t j *|¡�r˜|j |¡|j |¡t |j+t ƒ�rÔzt,|j+ƒ|_+Wnt-�yÒt.d#ƒ‚Yn0dS)$Nr)Ú sysconfigÚbuild)r/r/)r1r1)r:r:)r&r&)r(r()r>r>)r0r0r)Z plat_specificZincluder6r9ÚntZlibsZDebugZReleaseÚwin32éZPCbuildéÚcygwinÚlibÚpythonZconfigÚ.ÚPy_ENABLE_SHAREDZLIBDIRú,cSsg|] }|df‘qS)Ú1r)Ú.0ÚsymbolrrrÚ üóz.build_ext.finalize_options..ú zparallel should be an integer)/Z distutilsrBZset_undefined_optionsr2Ú distributionZ ext_packageZ ext_modulesr.Zget_python_incr3Ú isinstanceÚstrÚsplitÚosÚpathsepÚsysÚ exec_prefixÚbase_exec_prefixÚappendÚpathÚjoinÚextendZensure_string_listr6r7r8ÚnameÚprefixr&r1Údirnamer r0ÚplatformZ python_buildr Úget_config_varr4r5r=r-rÚisdirr>ÚintÚ ValueErrorr) r@rBZ py_includeZplat_py_includeÚsuffixZnew_libZdefinesZ user_includeZuser_librrrÚfinalize_options…s¬ ø               ÿÿ        zbuild_ext.finalize_optionscCsjddlm}|jsdS|j ¡rL| d¡}|j | ¡p:g¡|j   |j ¡||j |j |j|jd�|_ t|j ƒtjdkr”|jtƒkr”|j  |j¡|jdur¬|j  |j¡|jdurÔ|jD]\}}|j  ||¡q¼|jdurö|jD]}|j  |¡qä|jdu�r|j  |j¡|j du�r*|j  |j ¡|jdu�rD|j  |j¡|j du�r^|j  !|j ¡| "¡dS)Nr)Ú new_compilerÚ build_clib)r:ÚverboseÚdry_runr(rD)#rrkr.rTZhas_c_librariesÚget_finalized_commandr6r`Zget_library_namesr7r]rlr:rmrnr(r rXrar0rZ initializer3Zset_include_dirsr4Z define_macror5Zundefine_macroZ set_librariesZset_library_dirsr8Zset_runtime_library_dirsr9Zset_link_objectsÚbuild_extensions)r@rkrlraÚvalueÚmacrorrrÚrunsB   ü         z build_ext.runc Csvt|tƒstdƒ‚t|ƒD�]T\}}t|tƒr0qt|tƒrFt|ƒdkrNtdƒ‚|\}}t d|¡t|t ƒrvt   |¡s~tdƒ‚t|t ƒs�tdƒ‚t||dƒ}dD]"}|  |¡}|d ur¢t|||ƒq¢|  d ¡|_d |vrät d ¡|  d ¡}|�rhg|_g|_|D]b} t| tƒ�r"t| ƒdv�s*tdƒ‚t| ƒdk�rJ|j | d¡nt| ƒdk�r|j | ¡�q|||<qd S)a¬Ensure that the list of extensions (presumably provided as a command option 'extensions') is valid, i.e. it is a list of Extension objects. We also support the old-style list of 2-tuples, where the tuples are (ext_name, build_info), which are converted to Extension instances here. Raise DistutilsSetupError if the structure is invalid anywhere; just returns otherwise. z:'ext_modules' option must be a list of Extension instancesrzMeach element of 'ext_modules' option must be an Extension instance or 2-tuplezvold-style (ext_name, build_info) tuple found in ext_modules for extension '%s' -- please convert to Extension instancezRfirst element of each tuple in 'ext_modules' must be the extension name (a string)zOsecond element of each tuple in 'ext_modules' must be a dictionary (build info)Úsources)r3r7r6Ú extra_objectsÚextra_compile_argsÚextra_link_argsNr8Zdef_filez9'def_file' element of build info dict no longer supportedÚmacros)rrz9'macros' element of build info dict must be 1- or 2-tuplerr)rUÚlistrÚ enumeraterÚtupleÚlenrÚwarningrVÚextension_name_reÚmatchÚdictÚgetÚsetattrÚruntime_library_dirsÚ define_macrosÚ undef_macrosr]) r@r.rÚextÚext_nameZ build_infoÚkeyÚvalrxrrrrrÚcheck_extensions_list[s` ÿ ÿüÿ ÿ  ÿ ÿzbuild_ext.check_extensions_listcCs,| |j¡g}|jD]}| |j¡q|S©N)rŠr.r`rt)r@Ú filenamesr†rrrÚget_source_files¶s   zbuild_ext.get_source_filescCs2| |j¡g}|jD]}| | |j¡¡q|Sr‹)rŠr.r]Úget_ext_fullpathra)r@Zoutputsr†rrrÚ get_outputs¿s   zbuild_ext.get_outputscCs(| |j¡|jr| ¡n| ¡dSr‹)rŠr.r>Ú_build_extensions_parallelÚ_build_extensions_serialr?rrrrpÍs  zbuild_ext.build_extensionsc sàˆj}ˆjdurt ¡}zddlm}Wnty>d}Yn0|durTˆ ¡dS||d��n‰‡‡fdd„ˆjDƒ}tˆj|ƒD]:\}}ˆ  |¡�|  ¡Wdƒq‚1s²0Yq‚Wdƒn1sÒ0YdS)NTr)ÚThreadPoolExecutor)Ú max_workerscsg|]}ˆ ˆj|¡‘qSr)ZsubmitÚbuild_extension)rOr†©Úexecutorr@rrrQãsz8build_ext._build_extensions_parallel..) r>rXÚ cpu_countÚconcurrent.futuresr’Ú ImportErrorr‘r.ÚzipÚ_filter_build_errorsÚresult)r@Úworkersr’Zfuturesr†Zfutrr•rr�Õs"     ÿ z$build_ext._build_extensions_parallelc CsD|jD]8}| |¡�| |¡Wdƒq1s40YqdSr‹)r.r›r”)r@r†rrrr‘ês  z"build_ext._build_extensions_serialc csVz dVWnFtttfyP}z(|js(‚| d |j|¡¡WYd}~n d}~00dS)Nz"building extension "{}" failed: {})rrrZoptionalÚwarnÚformatra)r@r†Úerrrr›ïs  zbuild_ext._filter_build_errorsc CsP|j}|dust|ttfƒs*td|jƒ‚t|ƒ}| |j¡}||j}|j slt ||dƒslt   d|j¡dSt   d|j¡| ||¡}|jpŽg}|jdd…}|jD]}| |f¡q¤|jj||j||j|j ||jd�}|dd…|_|jrø| |j¡|j�pg}|j�p|j |¡} |jj||| |¡|j|j || !|¡|j |j| d� dS)Nzjin 'ext_modules' option (extension '%s'), 'sources' must be present and must be a list of source filenamesZnewerz$skipping '%s' extension (up-to-date)zbuilding '%s' extension)Z output_dirrxr3r&Úextra_postargsÚdepends)r6r7rƒr¡Úexport_symbolsr&r1Z target_lang)"rtrUryr{rraÚsortedrŽr¢r(r rr&ÚinfoÚ swig_sourcesrvr„r…r]r:Úcompiler1r3Z_built_objectsrur`rwÚlanguageZdetect_languageZlink_shared_objectÚ get_librariesr7rƒÚget_export_symbols) r@r†rtÚext_pathr¢Ú extra_argsrxr5Zobjectsr¨rrrr”øsZþÿ     ù   özbuild_ext.build_extensioncCs$g}g}i}|jrt d¡|js6d|jvs6d|jvrI don't know how to find (much less run) SWIG on platform '%s'N)rXrar^r_Úisfiler )r@ZversÚfnrrrr°‚s    ÿÿzbuild_ext.find_swigcCsŽ| |¡}| d¡}| |d¡}|jsRtjj|dd…|gŽ}tj |j|¡Sd |dd…¡}| d¡}tj  |  |¡¡}tj ||¡S)z¡Returns the path of the filename for a given extension. The file is located in `build_lib` or directly in the package (inplace option). rKr®NrÚbuild_py) Úget_ext_fullnamerWÚget_ext_filenamerrXr^r_r/roÚabspathZget_package_dir)r@r‡ÚfullnameÚmodpathÚfilenamer2r¹Z package_dirrrrrŽ›s   zbuild_ext.get_ext_fullpathcCs |jdur|S|jd|SdS)zSReturns the fullname of a given extension name. Adds the `package.` prefixNrK)r2)r@r‡rrrrº¶s zbuild_ext.get_ext_fullnamecCs.ddlm}| d¡}|dƒ}tjj|Ž|S)z¦Convert the name of an extension (eg. "foo.bar") into the name of the file from which it will be loaded (eg. "foo/bar.so", or "foo\bar.pyd"). r©rerKZ EXT_SUFFIX)rBrerWrXr^r_)r@r‡rer«Z ext_suffixrrrr»¿s  zbuild_ext.get_ext_filenamecCsz|j d¡d}z| d¡Wn.tyLd| d¡ dd¡ d¡}Yn 0d|}d |}||jvrt|j |¡|jS) aReturn the list of symbols that a shared extension has to export. This either uses 'ext.export_symbols' or, if it's not provided, "PyInit_" + module_name. Only relevant on Windows, where the .pyd file (DLL) must export the module "PyInit_" function. rKr®ÚasciiZU_Zpunycodeó-ó_Ú_ZPyInit)rarWÚencodeÚUnicodeEncodeErrorÚreplaceÚdecoder£r])r@r†rariZ initfunc_namerrrrªÊs "  zbuild_ext.get_export_symbolscCsìtjdkr^ddlm}t|j|ƒsÞd}|jr4|d}|tjd?tjd?d@f}|j|gSn€dd l m }d }|d ƒrÂt td ƒr†d }ns"