\d{dZddlZddlZddlZddlZddlmZddlTddlm Z m Z ddlm Z ddl m Z ddlmZdd lmZdd lmZdd lmZejd Zd ZGddeZdS)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]*)*$c&ddlm}|dS)Nrshow_compilers)distutils.ccompilerrrs ,..\python\lib\distutils\command\build_ext.pyrrs(222222Nc eZdZdZdejzZdddddezfdd d d ezfd d ddddezfddddddddddgZgdZ ddde fgZ d Z d!Z d"Zd#Zd$Zd%Zd&Zd'Zd(Zejd)Zd*Zd+Zd,Zd-Zd.Zd/Zd0Zd1ZdS)2 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))inplaceiziignore 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)debuggz'compile/link with debugging information)forcefz2forcibly 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 compilersc,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_temprpackage include_dirsdefineundef libraries library_dirsrpath link_objectsr!r#compilerswigswig_cpp swig_optsr(parallelselfs rinitialize_optionszbuild_ext.initialize_optionsjs               rc ddlm}|ddddddd d |j|jj|_|jj|_|}|d }|j |jj pg|_ t|j tr)|j tj|_ tjtjkrB|j tjtjd |j | tjj||kr<|j | tjj|d|d|jg|_|jg|_nCt|jtr)|j tj|_|jg|_nCt|jtr)|j tj|_tjdkr|jtjtjdtjtjkrB|jtjtjd|jr+tj|jd|_n*tj|jd|_|j tjt?tAtdd}|r|j||j!dkrd}n|j!dd}tjtjd}|r tj||}|j|tj"dddkrtj#$tjtjdrT|jtjtjddtKzdn|jd|&drO|j's.|j|&d n|jd|j(r+|j( d!}d"|D|_(|j)r|j) d!|_)|j*g|_*n|j* d#|_*|j+rtjtXd }tjtXd} tj-|r|j |tj-| r4|j| |j| t|j.tr9 t_|j.|_.dS#t`$rtcd$wxYwdS)%Nr) sysconfigbuild)r+r+)r-r-)r6r6)r!r!)r#r#)r:r:)r,r,) plat_specificincluder2r5ntlibsDebugRelease_homewin32PCbuildcygwinbinlibpythonconfig.Py_ENABLE_SHAREDLIBDIR,cg|]}|dfS)1).0symbols r z.build_ext.finalize_options..s???VFC=???r zparallel should be an integer)2 distutilsr?set_undefined_optionsr. distribution ext_package ext_modulesr*get_python_incr/ isinstancestrsplitospathsepsys exec_prefixbase_exec_prefixappendpathjoinextendensure_string_listr2r3r4nameprefixr!r-dirnamergetattrr,platform executable startswithrget_config_var python_buildr0r1r9r(r isdirr:int ValueErrorDistutilsOptionError) r<r? py_includeplat_py_include _sys_homesuffixnew_libdefines user_includeuser_libs rfinalize_optionszbuild_ext.finalize_optionss`'''''' ""7#=#?#;#5#5#;#= % % % < ,8DL+7--// #222CC   $ $ 1 > D"D  d' - - D $ 1 7 7 C CD  ?c2 2 2   $ $RW\\#/9%M%M N N N   !1!1"'/!B!BCCC j ( (   $ $%%bgo66 8 8 8  ,,, /// > !DN   $ "D   )3 / / D $ 1 7 7 C CD  : DJJ  C ( ( 6))"*55DJ 7d??   $ $RW\\#/6%J%J K K K#sz11!((c6JF)S)STTTz K"$',,t"H"H"$',,t "J"J   $ $RW__5J5L5L%M%M N N NWd33I 4!((333~(( +gll3?I>>G 8',,w77   $ $W - - - < x ' '~((cou)M)MNN .!((cj%6>ASAUAU6U6>*@*@AAAA !((---  $ $%7 8 8 .) .!(()A)A()K)KLLLL!((--- ; @k'',,G??w???DK : /))#..DJ > !DNN!^11#66DN 9 ,7<< 9==Lw||Iu55Hw}}\** 7!((666w}}X&& ,!((222 !!(+++ dmS ) ) L L #DM 2 2  L L L*+JKKK L L Ls ;]]0cvddlm}|jsdS|jrb|d}|j|pg|j |j ||j |j |j|j|_ t!|j t"jdkr6|jt)kr|j |j|j|j |j|j(|jD] \}}|j ||!|j$|jD]}|j ||j|j |j|j |j |j |j|j |j|j |j !|j |"dS)Nr) new_compiler build_clib)r6verbosedry_runr#rD)#rrr*r_has_c_librariesget_finalized_commandr2rnget_library_namesr3rkrr6rrr#rrfrpr,r initializer/set_include_dirsr0 define_macror1undefine_macro set_librariesset_library_dirsr4set_runtime_library_dirsr5set_link_objectsbuild_extensions)r<rrrpvaluemacros rrunz build_ext.runs2444444  F   , , . . <33LAAJ N ! !*">">"@"@"FB G G G   $ $Z%: ; ; ;% dm-1\-1\+/:777  4=))) 7d??t~?? M $ $T^ 4 4 4   ( M * *4+< = = = ; "!% 8 8 u **47777 : ! 4 4 ,,U3333 > % M ' ' 7 7 7   ( M * *4+< = = = : ! M 2 24: > > >   ( M * *4+< = = = rct|tstdt|D] \}}t|trt|t rt |dkrtd|\}}tjd|t|trt |stdt|tstdt ||d}dD]*}| |}|t|||+| d |_d |vrtjd | d }|rg|_g|_|D]} t| t rt | dvstdt | dkr!|j| dkt | dkr|j| |||< d S)aEnsure 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 instanceszMeach 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/r3r2 extra_objectsextra_compile_argsextra_link_argsNr4def_filez9'def_file' element of build info dict no longer supportedmacros)rArz9'macros' element of build info dict must be 1- or 2-tuplerAr)rclistDistutilsSetupError enumerater tuplelenr warnrdextension_name_rematchdictgetsetattrruntime_library_dirs define_macros undef_macrosrk) r<r*rextext_name build_infokeyvalrrs rcheck_extensions_listzbuild_ext.check_extensions_listVs*d++ P%NPP P ++> > FAs#y)) c5)) 8SXX]])7888$' Hj H?@H J J Jx-- @%++H55 @)?@@@j$// <);<<< Hj&;<'>C $Z''/000  ^^H--F 8$&!#% #88E&ue447Uv9M9M167775zzQ(//a9999Uq)00777JqMM}> > rc||jg}|jD]}||j|SN)rr*rnr)r< filenamesrs rget_source_fileszbuild_ext.get_source_filessO ""4?333 ? * *C   S[ ) ) ) )rc||jg}|jD]/}|||j0|Sr)rr*rkget_ext_fullpathrp)r<outputsrs r get_outputszbuild_ext.get_outputss\ ""4?333 ? < .s:333 t';SAA333r) r:rf cpu_countconcurrent.futuresr ImportErrorrr*zip_filter_build_errorsresult)r<workersrfuturesrfutrs` @rrz$build_ext._build_extensions_parallels- =D lnnG  = = = = = = =   GGG  ?  ) ) + + + F  G 4 4 4 !33333"&/333G99 ! !S..s33!!JJLLL!!!!!!!!!!!!!!! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !sC. ==$AC#(C = C# C C#C C##C'*C'c|jD]D}||5||dddn #1swxYwYEdSr)r*rr)r<rs rrz"build_ext._build_extensions_serials? * *C**3// * *$$S))) * * * * * * * * * * * * * * * * *sAA A c#K dVdS#tttf$r3}|js|d|jd|Yd}~dSd}~wwxYw)Nzbuilding extension "z " failed: )CCompilerErrorDistutilsError CompileErroroptionalrrp)r<res rrzbuild_ext._filter_build_errorss % EEEEE = % % %<  IIIxxx$ % % % % % % % % % %s A(AAc |j}|t|ttfst d|jzt |}||j}||jz}|j s-t||dstj d|jdStj d|j|||}|jpg}|jdd}|jD]}||f|j||j||j|j ||j}|dd|_|jr||j|jpg}|jp|j|} |j|||||j|j ||!||j |j|  dS)Nzjin 'ext_modules' option (extension '%s'), 'sources' must be present and must be a list of source filenamesnewerz$skipping '%s' extension (up-to-date)zbuilding '%s' extension) output_dirrr/r!extra_postargsdepends)r2r3rrexport_symbolsr!r- target_lang)"rrcrrrrpsortedrrr#rr r!info swig_sourcesrrrrkr6compiler-r/_built_objectsrrnrlanguagedetect_languagelink_shared_object get_librariesr3rget_export_symbols) r<rrext_pathr extra_argsrr1objectsrs rrzbuild_ext.build_extensions+ ?*WtUm"D"D?%/14:;; ; //((22CK'  :k'8WEE : I>&aaaj   . NN3, - - -(.B <I4=#@#@#I#I (( X((--)!$!9%22377*  ) " " " " "rcg}g}i}|jrtjd|jsd|jvs d|jvrd}nd}|D]{}tj|\}} | dkr<||dz|z|||d||<f||||s|S|jp| } | dg} | |j|jr| d|js|jD]} | | |D];}||} tj d || | | d | |gz<|S) zWalk the list of source files in 'sources', looking for SWIG interface (.i) files. Run SWIG on all that are found, and return a modified 'sources' list with SWIG source files replaced by the generated C (or C++) files. z/--swig-cpp is deprecated - use --swig-opts=-c++z-c++z.cppz.cz.i_wrapz-pythonzswigging %s to %sz-o) r8r rr9rfrlsplitextrkr7 find_swigrnrspawn)r<r extension new_sourcesr swig_targets target_extsourcebaserr7swig_cmdotargets rrzbuild_ext.swig_sources2s     = H HF G G G = Vt~55 i) ) )JJJ + +F'**622KT3d{{""4'>J#>???##F+++'22 V$$""6****  y,DNN,,)$''' = $ OOF # # #~ #( # #""""" : :F!&)F H(&& 9 9 9 JJx4"88 9 9 9 9rctjdkrdStjdkrMdD]H}tjd|zd}tj|r|cSIdSt dtjz)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. posixr7rD)z1.3z1.2z1.1z c:\swig%szswig.exez>I don't know how to find (much less run) SWIG on platform '%s')rfrprlrmisfileDistutilsPlatformError)r<versfns rrzbuild_ext.find_swighs 7g  6 W__. " "W\\,"5zBB7>>"%%III"z(%')w/00 0rc*||}|d}||d}|jsDt jj|dd|gz}tj|j|Sd|dd}|d}tj | |}tj||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). rRrNrbuild_py) get_ext_fullnamereget_ext_filenamerrfrlrmr+rabspathget_package_dir)r<rfullnamemodpathfilenamer.r package_dirs rrzbuild_ext.get_ext_fullpaths ((22..%%((55| :w|WSbS\8*%<=H7<<99 9((71R4=))--j99gooh&>&>w&G&GHH w||K222rc.|j|S|jdz|zS)zSReturns the fullname of a given extension name. Adds the `package.` prefixNrR)r.)r<rs rrzbuild_ext.get_ext_fullnames# < O<#%0 0rczddlm}|d}|d}tjj||zS)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"). rrwrR EXT_SUFFIX)distutils.sysconfigrwrerfrlrm)r<rrwr ext_suffixs rrzbuild_ext.get_ext_filenamesJ 766666>>#&&#^L11 w|X&33rcrd|jddz} |dnO#t$rBd|ddddz}YnwxYwd |z}||jvr|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. _rRrasciirpunycode-_PyInit)rpreencodeUnicodeEncodeErrorreplacedecoderrk)r<rr initfunc_names rrzbuild_ext.get_export_symbolss sx~~c**2.. Y MM' " " " "! Y Y Y6==44<>)- >*N;77 }9(<'===}r) __name__ __module__ __qualname__ descriptionrfrgsep_byr user_optionsboolean_optionsr help_optionsr=rrrrrrrr contextlibcontextmanagerrrrrrrrrrrXrrrr!sLK($bj 0F 5 > s '<>> * + 9 # 9F B D , . . # 9F B D D ? 4 ? & * 6 . ( 0O) LVHGGO $ #^ 5 L 0RLRLRLh> > > @L L L \   ,,,!!!(*** %%%J"J"J"X444l00003336111444"""&11111rr)__doc__r8rfrerhdistutils.corerdistutils.errorsrrrrdistutils.dep_utilrdistutils.extensionr distutils.utilr r]r siter rrrrrXrrrBs@  """"""FFFFFFFF555555******))))))''''''BJ;== Q Q Q Q Q Q Q Q Q Q r