B Xé˜iWµsØã@s²ddlZddlZddlZddlZddlmZddlTddlmZm Z ddlm Z ddl m Z ddl mZddlmZdd lmZdd lmZe d ¡Zd d „ZGdd„deƒZdS)éN)ÚCommand)Ú*)Úcustomize_compilerÚget_python_version)Úget_config_h_filename)Ú newer_group)Ú Extension)Ú get_platform)Úlog)Ú USER_BASEz3^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$cCsddlm}|ƒdS)Nr)Úshow_compilers)Údistutils.ccompilerr )r ©rú>/opt/alt/python37/lib/python3.7/distutils/command/build_ext.pyr s r c@seZdZdZdejZdddddeƒfdd d d efd d ddddefddddddddddgZddddd gZ d!d"d#e fgZ d$d%„Z d&d'„Z d(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4d5„Zejd6d7„ƒZd8d9„Zd:d;„Zdd?„Zd@dA„ZdBdC„ZdDdE„ZdFdG„Zd"S)HÚ 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)zswig-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 rpathrrrzswig-cppr#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_objectsrrÚcompilerÚswigÚswig_cppÚ swig_optsr#Úparallel)ÚselfrrrÚinitialize_optionsjs*zbuild_ext.initialize_optionsc Csüddlm}| ddddddd d ¡|jdkr8|jj|_|jj|_| ¡}|jd d }|j dkrn|jj pjg|_ t |j t ƒrŠ|j   t j¡|_ tjtjkr®|j  t j tjd ¡¡|j  |  t jj¡¡||krâ|j  |  t jj¡¡| d¡| d¡|jdkrg|_|jdkrg|_nt |jt ƒr:|j  t j¡|_|jdkrNg|_nt |jt ƒrl|j  t j¡|_t jdkrh|j t j tjd¡¡tjtjkr¶|j t j tjd¡¡|jrÒt j |jd¡|_nt j |jd¡|_|j  t j tƒ¡¡t tddƒ}|r|j |¡|j!dkr*d}n|j!dd…}t j tjd¡}|r\t j ||¡}|j |¡tj"dd…dkrÆtj# $t j tjd¡¡rº|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)r4|j)  d!¡|_)|j*dkrHg|_*n|j*  d$¡|_*|j+rºt j t,d ¡}t j t,d¡} t j -|¡r”|j  |¡t j -| ¡rº|j | ¡|j | ¡t |j.t ƒrøyt/|j.ƒ|_.Wnt0k röt1d%ƒ‚YnXdS)&Nr)Ú sysconfigZbuild)r%r%)r'r')r0r0)rr)rr)r4r4)r&r&é)Z plat_specificZincluder,r/ÚntZlibsZDebugZReleaseÚ_homeÚwin32éZPCbuildéÚcygwinÚbinÚlibZpythonZconfigÚ.ÚPy_ENABLE_SHAREDZLIBDIRú,cSsg|] }|df‘qS)Ú1r)Ú.0Úsymbolrrrú ùsz.build_ext.finalize_options..ú zparallel should be an integer)2Ú distutilsr7Zset_undefined_optionsr(Ú distributionZ ext_packageZ ext_modulesr$Zget_python_incr)Ú isinstanceÚstrÚsplitÚosÚpathsepÚsysÚ exec_prefixÚbase_exec_prefixÚappendÚpathÚjoinÚextendZensure_string_listr,r-r.ÚnameÚprefixrr'ÚdirnamerÚgetattrr&ÚplatformÚ executableÚ startswithrÚget_config_varZ python_buildr*r+r3r#r Úisdirr4ÚintÚ ValueErrorZDistutilsOptionError) r5r7Z py_includeZplat_py_includeZ _sys_homeÚsuffixZnew_libZdefinesZ user_includeZuser_librrrÚfinalize_options‚sª                           zbuild_ext.finalize_optionscCsrddlm}|jsdS|j ¡rL| d¡}|j | ¡p:g¡|j   |j ¡||j |j |j|jd|_ t|j ƒtjdkr”|jtƒkr”|j  |j¡|jdk r¬|j  |j¡|jdk rØx |jD]\}}|j  ||¡q¾W|jdk rþx|jD]}|j  |¡qêW|jdk r|j  |j¡|j dk r2|j  |j ¡|jdk rL|j  |j¡|j dk rf|j  !|j ¡| "¡dS)Nr)Ú new_compilerÚ build_clib)r0ÚverboseÚdry_runrr9)#r rdr$rJZhas_c_librariesÚget_finalized_commandr,rVZget_library_namesr-rSrer0rfrgrrrNrWr&r Z initializer)Zset_include_dirsr*Z define_macror+Zundefine_macroZ set_librariesZset_library_dirsr.Zset_runtime_library_dirsr/Zset_link_objectsÚbuild_extensions)r5rdrerWÚvalueÚmacrorrrÚruns>             z build_ext.runc Cs„t|tƒstdƒ‚xjt|ƒD]\\}}t|tƒr4qt|tƒrJt|ƒdkrRtdƒ‚|\}}t d|¡t|t ƒrzt   |¡s‚tdƒ‚t|t ƒs”tdƒ‚t||dƒ}x*dD]"}|  |¡}|dk r¨t|||ƒq¨W|  d ¡|_d |krìt d ¡|  d ¡}|rtg|_g|_xj|D]b} t| tƒr,t| ƒd ks4tdƒ‚t| ƒdkrT|j | d¡nt| ƒdkr|j | ¡qW|||<qWdS)Nz:'ext_modules' option must be a list of Extension instancesézMeach 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)r)r-r,Ú extra_objectsÚextra_compile_argsÚextra_link_argsr.Zdef_filez9'def_file' element of build info dict no longer supportedÚmacros)r8rmz9'macros' element of build info dict must be 1- or 2-tupler8r)rKÚlistÚDistutilsSetupErrorÚ enumeraterÚtupleÚlenr ÚwarnrLÚextension_name_reÚmatchÚdictÚgetÚsetattrÚruntime_library_dirsÚ define_macrosÚ undef_macrosrS) r5r$rÚextÚext_nameZ build_infoÚkeyÚvalrrrkrrrÚcheck_extensions_listVsP           zbuild_ext.check_extensions_listcCs0| |j¡g}x|jD]}| |j¡qW|S)N)r…r$rVrn)r5Ú filenamesrrrrÚget_source_files¤s   zbuild_ext.get_source_filescCs6| |j¡g}x |jD]}| | |j¡¡qW|S)N)r…r$rSÚget_ext_fullpathrW)r5ZoutputsrrrrÚ get_outputs­s   zbuild_ext.get_outputscCs(| |j¡|jr| ¡n| ¡dS)N)r…r$r4Ú_build_extensions_parallelÚ_build_extensions_serial)r5rrrri»s  zbuild_ext.build_extensionsc s¾ˆj}ˆjdkrt ¡}yddlm}Wntk r@d}YnX|dkrVˆ ¡dS||dT‰‡‡fdd„ˆjDƒ}x6tˆj|ƒD]&\}}ˆ  |¡|  ¡WdQRXq†WWdQRXdS)NTr)ÚThreadPoolExecutor)Ú max_workerscsg|]}ˆ ˆj|¡‘qSr)ZsubmitÚbuild_extension)rEr)Úexecutorr5rrrGÑsz8build_ext._build_extensions_parallel..) r4rNÚ cpu_countÚconcurrent.futuresrŒÚ ImportErrorr‹r$ÚzipÚ_filter_build_errorsÚresult)r5ÚworkersrŒZfuturesrZfutr)rr5rrŠÃs       z$build_ext._build_extensions_parallelc Cs4x.|jD]$}| |¡| |¡WdQRXqWdS)N)r$r”rŽ)r5rrrrr‹×s  z"build_ext._build_extensions_serialc csTy dVWnDtttfk rN}z |js*‚| d|j|f¡Wdd}~XYnXdS)Nz"building extension "%s" failed: %s)ZCCompilerErrorZDistutilsErrorZ CompileErrorZoptionalrxrW)r5rÚerrrr”Üs zbuild_ext._filter_build_errorsc CsT|j}|dkst|ttfƒs*td|jƒ‚t|ƒ}| |j¡}||j}|jslt ||dƒslt   d|j¡dSt   d|j¡|  ||¡}|jpŽg}|jdd…}x|jD]}| |f¡q¦W|jj||j||j|j ||jd}|dd…|_|jrü| |j¡|jpg}|jp|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_dirrrr)rÚextra_postargsÚdepends)r,r-r~r˜Úexport_symbolsrr'Z target_lang)!rnrKrsrvrtrWrˆr™rrr rÚinfoÚ swig_sourcesrprr€rSr0Úcompiler'r)Z_built_objectsrorVrqÚlanguageZdetect_languageZlink_shared_objectÚ get_librariesr-r~Úget_export_symbols) r5rrnÚext_pathr™Z extra_argsrrr+ZobjectsržrrrrŽæsN         zbuild_ext.build_extensioncCs0g}g}i}|jrt d¡|js6d|jks6d|jkr        zbuild_ext.swig_sourcescCs`tjdkrdStjdkrNxBdD]&}tj d|d¡}tj |¡r|SqWdSntdtjƒ‚dS)NÚposixr1r9)z1.3z1.2z1.1z c:\swig%szswig.exez>I don't know how to find (much less run) SWIG on platform '%s')rNrWrTrUÚisfileZDistutilsPlatformError)r5ZversÚfnrrrr¥gs    zbuild_ext.find_swigcCsŽ| |¡}| d¡}| |d¡}|jsRtjj|dd…|gŽ}tj |j|¡Sd |dd…¡}| d¡}tj  |  |¡¡}tj ||¡S)NrAr£rÚbuild_py) Úget_ext_fullnamerMÚget_ext_filenamerrNrTrUr%rhÚabspathZget_package_dir)r5r‚ÚfullnameZmodpathÚfilenamer(r®Z package_dirrrrrˆs   zbuild_ext.get_ext_fullpathcCs |jdkr|S|jd|SdS)NrA)r()r5r‚rrrr¯šs zbuild_ext.get_ext_fullnamecCs.ddlm}| d¡}|dƒ}tjj|Ž|S)Nr)r^rAZ EXT_SUFFIX)Údistutils.sysconfigr^rMrNrTrU)r5r‚r^r¡Z ext_suffixrrrr°£s  zbuild_ext.get_ext_filenamecCs0d|j d¡d}||jkr*|j |¡|jS)NZPyInit_rAr£)rWrMršrS)r5rZ initfunc_namerrrr ­s  zbuild_ext.get_export_symbolscCsÜtjdkrdddlm}t|j|ƒs\d}|jr4|d}|tjd?tjd?d@f}|j|gS|jSnttjd krt|jStjdd …d krŒ|jSdd l m }|  d ¡rÒd  tjd?tjd?d@|  d¡¡}|j|gS|jSdS)Nr;r)Ú MSVCCompilerz python%d%dZ_déééÿÚdarwinéZaix)r7rBz python{}.{}{}ZABIFLAGS) rPr[Zdistutils._msvccompilerrµrKr0rÚ hexversionr,rIr7r^Úformat)r5rrµÚtemplateZ pythonlibr7rrrrŸ¸s*         zbuild_ext.get_libraries) Ú__name__Ú __module__Ú __qualname__Ú descriptionrNrOZsep_byr Z user_optionsZboolean_optionsr Z help_optionsr6rcrlr…r‡r‰rirŠr‹Ú contextlibÚcontextmanagerr”rŽrœr¥rˆr¯r°r rŸrrrrr!s^  @N  K6   r)rÂrNÚrerPZdistutils.corerZdistutils.errorsr´rrrZdistutils.dep_utilrZdistutils.extensionrZdistutils.utilr rIr Zsiter rryr rrrrrÚs