Yf{@sdZddlZddlZddlZddlZddlmZddlTddlm Z m Z ddlm Z ddl m Z ddlmZdd lmZdd lmZdd lmZejd Zd dZGdddeZdS)zdistutils.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)*)customize_compilerget_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/python35/lib64/python3.5/distutils/command/build_ext.pyr sr c@seZdZdZdejZd`dad d d efd d ddfdddefdbdcdddddefdedfdgdhdidjdkdldmdngZd d%d(d1d8gZ d:d2d;e fgZ d<d=Z d>d?Z d@dAZdBdCZdDdEZdFdGZdHdIZdJdKZdLdMZejdNdOZdPdQZdRdSZdTdUZdVdWZdXdYZdZd[Zd\d]Zd^d_Zd2S)o build_extz8build C/C++ extensions (compile/link to build directory)z (separated by '%s') build-lib=b(directory for compiled extension modules build-temp=t1directory for temporary files (build by-products)z plat-name=pz>platform name to cross-compile for, if supported (default: %s)inplaceiz=ignore build-lib and put compiled extensions into the source z,directory alongside your pure Python modulesz include-dirs=Iz.list of directories to search for header filesdefine=DC preprocessor macros to defineundef=U!C preprocessor macros to undefine libraries=l!external C libraries to link withz library-dirs=Lz.directories to search for external C librariesrpath=R7directories to search for shared C libraries at runtime link-objects=O2extra explicit link objects to include in the linkdebugg'compile/link with debugging informationforcef2forcibly build everything (ignore file timestamps) compiler=cspecify the compiler type parallel=jnumber of parallel build jobsswig-cppN)make SWIG create C++ files (default is C) swig-opts=!list of SWIG command line optionsswig=path to the SWIG executableuser#add user include, library and rpathz help-compilerzlist available compilerscCsd|_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_temprpackage include_dirsdefineundef libraries library_dirsrpath link_objectsr+r.compilerswigswig_cpp swig_optsr=parallel)selfrrrinitialize_optionsjs*                    zbuild_ext.initialize_optionsc Csrddlm}|jdd'd(d)d*d+d,d-|jdkrP|jj|_|jj|_|j}|jd d }|j dkr|jj pg|_ t |j t r|j j t j|_ tjtjkr|j jt jjtjd |j j|||kr+|j j||jd|jd|jdkr]g|_|jdkrxg|_n*t |jt r|jj t j|_|jdkrg|_n*t |jt r|jj t j|_t jdkrC|jjt jjtjdtjtjkrL|jjt jjtjd|jrst jj|jd|_nt jj|jd|_|j jt jjtttdd}|r|jj||j dkrd}n|j dd}t jjtjd}|r3t jj||}|jj|tj!dddksutj!dddkrtj"j#t jjtjdr|jjt jjtjddt$dn|jjd|j%d r|j&s|jj|j%d!n|jjd|j'rP|j'j d"}d#d$|D|_'|j(rn|j(j d"|_(|j)dkrg|_)n|j)j d%|_)|j*r%t jjt+d }t jjt+d} t jj,|r|j j|t jj,| r%|jj| |jj| t |j-t rnyt.|j-|_-Wnt/k rmt0d&YnXdS).Nr) sysconfigZbuildr@rBrKr+r.rOrAZ plat_specificincluderGrJntZlibsZDebugZRelease_homewin32ZPCbuildcygwinatheosbinlibpythonconfig.Py_ENABLE_SHAREDLIBDIR,cSsg|]}|dfqS)1r).0Zsymbolrrr s z.build_ext.finalize_options.. zparallel should be an integer)r@r@)rBrB)rKrK)r+r+)r.r.)rOrO)rArA)1 distutilsrRZset_undefined_optionsrC distributionZ ext_packageZ ext_modulesr?Zget_python_incrD isinstancestrsplitospathsepsys exec_prefixbase_exec_prefixappendpathjoinZensure_string_listrGrHrInameprefixr+rBdirnamergetattrrAplatform executable startswithrget_config_varZ python_buildrErFrNr=r isdirrOint ValueErrorZDistutilsOptionError) rPrRZ py_includeZplat_py_include _sys_homesuffixZnew_libZdefinesZ user_includeZuser_librrrfinalize_optionss  "      ""  2$        zbuild_ext.finalize_optionsc Csddlm}|jsdS|jjrj|jd}|jj|jpSg|j j |j |d|j d|j d|jd|j|_ t|j tjdkr|jtkr|j j|j|jdk r|j j|j|jdk r9x*|jD]\}}|j j||qW|jdk rlx!|jD]}|j j|qRW|jdk r|j j|j|j dk r|j j|j |jdk r|j j|j|j dk r|j j!|j |j"dS) Nr) new_compiler build_clibrKverbosedry_runr.rU)#r rr?riZhas_c_librariesget_finalized_commandrGextendZget_library_namesrHrrrrKrrr.rrmrurAr Z initializerDZset_include_dirsrEZ define_macrorFZundefine_macroZ set_librariesZset_library_dirsrIZset_runtime_library_dirsrJZset_link_objectsbuild_extensions)rPrrruvaluemacrorrrruns>    !z build_ext.runc Cst|tstdxt|D]\}}t|trFq(t|t sht|dkrttd|\}}tjd|t|t ot j |stdt|t stdt||d}x9dD]1}|j |}|dk rt|||qW|j d|_d|krPtjd|j d}|rg|_g|_x|D]~} t| tot| dkstdt| dkr|jj| dq~t| dkr~|jj| q~W||||j|jg}x!|jD]}|j|jq W|S)N)rr?rr)rP filenamesrrrrget_source_filess zbuild_ext.get_source_filescCsG|j|jg}x*|jD]}|j|j|jq W|S)N)rr?rrget_ext_fullpathru)rPZoutputsrrrr get_outputss zbuild_ext.get_outputscCs4|j|j|jr&|jn |jdS)N)rr?rO_build_extensions_parallel_build_extensions_serial)rPrrrrs  zbuild_ext.build_extensionscsj}jdkr$tj}yddlm}Wntk rRd}YnX|dkrmjdS|d|jfddjD}xAtj|D]-\}}j ||j WdQRXqWWdQRXdS)NTr)ThreadPoolExecutorZ max_workerscs%g|]}jj|qSr)Zsubmitbuild_extension)rer)executorrPrrrfs z8build_ext._build_extensions_parallel..) rOrm cpu_countZconcurrent.futuresr ImportErrorrr?zip_filter_build_errorsresult)rPZworkersrZfuturesrZfutr)rrPrrs        z$build_ext._build_extensions_parallelc Cs<x5|jD]*}|j||j|WdQRXq WdS)N)r?rr)rPrrrrrsz"build_ext._build_extensions_serialccsdy dVWnTtttfk r_}z+|js3|jd|j|fWYdd}~XnXdS)Nz"building extension "%s" failed: %s)ZCCompilerErrorZDistutilsErrorZ CompileErrorZoptionalrru)rPrerrrrs   zbuild_ext._filter_build_errorsc Cs|j}|dks+t|ttf r>td|jt|}|j|j}||j}|jpt ||dst j d|jdSt j d|j|j ||}|jpg}|jdd}x!|jD]}|j|fqW|jj|d|jd|d|jd|j d |d |j}|dd|_|jrt|j|j|jpg}|jp|jj|} |jj||d |j|d |jd |jd |d|j |d|j d|jd| 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' extensionZ output_dirrrDr+Zextra_postargsdependsrGrHrexport_symbolsrBZ target_lang)!rrjrrrrurrr.rr r+info swig_sourcesrrrrrrKcompilerBrDZ_built_objectsrrrlanguageZdetect_languageZlink_shared_object get_librariesrHrget_export_symbols) rPrrext_pathrZ extra_argsrrFZobjectsrrrrrsN "              zbuild_ext.build_extensioncCsg}g}i}|jr(tjd|jsOd|jksOd|jkrXd}nd}xr|D]j}tjj|\}} | dkr|j|d||j||d ||            zbuild_ext.swig_sourcescCstjdkrdStjdkrixWd D]5}tjjd|d}tjj|r)|Sq)WdSntd tjd S) zReturn the name of the SWIG executable. On Unix, this is just "swig" -- it should be in the PATH. Tries a bit harder on Windows. posixrLrU1.31.21.1z c:\swig%szswig.exez>I don't know how to find (much less run) SWIG on platform '%s'N)rrr)rmrursrtisfileZDistutilsPlatformError)rPZversfnrrrrfs zbuild_ext.find_swigcCs|j|}|jd}|j|d}|jsstjj|dd|g}tjj|j|Sdj|dd}|jd}tjj |j |}tjj||S) zReturns the path of the filename for a given extension. The file is located in `build_lib` or directly in the package (inplace option). r`rSNrbuild_pyrrr) get_ext_fullnamerlget_ext_filenamerrmrsrtr@rabspathZget_package_dir)rPrfullnameZmodpathfilenamerCrZ package_dirrrrr~s #zbuild_ext.get_ext_fullpathcCs&|jdkr|S|jd|SdS)zSReturns the fullname of a given extension name. Adds the `package.` prefixNr`)rC)rPrrrrrszbuild_ext.get_ext_fullnamecCs?ddlm}|jd}|d}tjj||S)zConvert 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)r|r` EXT_SUFFIX)distutils.sysconfigr|rlrmrsrt)rPrr|rZ ext_suffixrrrrs zbuild_ext.get_ext_filenamecCs@d|jjdd}||jkr9|jj||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. ZPyInit_r`rSr)rurlrrr)rPrZ initfunc_namerrrrszbuild_ext.get_export_symbolscCs3tjdkrddlm}t|j|szd}|jrJ|d}|tjd?tjd?d@f}|j|gS|jSntjd d d krd }|tjd?tjd?d@f}|j|gStjd d d krddl m }d }|tjd?tjd?d@f}g}xS|j dj D]<}|j dro|j|dd q@|j|q@W|j|dg|Stjdkr|jStjd ddkr|jSddl m }|j dr(djtjd?tjd?d@|j d}|j|gS|jSd S)zReturn the list of libraries to link against when building a shared extension. On most platforms, this is just 'ext.libraries'; on Windows, we add the Python library (eg. python20.dll). rWr) MSVCCompilerz python%d%dZ_dNrYrZz python%d.%dr[)rRSHLIBSz-lrmdarwinaixraz python{}.{}{}ABIFLAGS)roryZdistutils._msvccompilerrrjrKr+ hexversionrGrhrRr|rlr{rrformat)rPrrtemplateZ pythonlibrRZextrar]rrrrsJ    zbuild_ext.get_libraries)rrr)rrr)rrr)rrr )r!r"r#)r%r&r')r(r)r*)r+r,r-)r.r/r0)r1r2r3)r4r5r6)r7Nr8)r9Nr:)r;Nr<)r=Nr>) __name__ __module__ __qualname__Z descriptionrmrnZsep_byr Z user_optionsZboolean_optionsr Z help_optionsrQrrrrrrrr contextlibcontextmanagerrrrrrrrrrrrrrr!s~        @ N     K 6   r)__doc__rrmreroZdistutils.corerZdistutils.errorsrrrrZdistutils.dep_utilrZdistutils.extensionrZdistutils.utilr rhr Zsiter rrr rrrrrs"