U e5dI@sddlZddlZddlZddlTddlmZddlmZddlm Z ddl m Z m Z ddl mZmZddlmZGd d d Zd Zdd d ZddddddZddZdddZddZddZdS)N)*)spawn) move_file)mkpath)newer_pairwise newer_group) split_quotedexecute)logc @seZdZdZdZdZdZdZdZdZ dZ ddddddZ dddgZ dpddZ d d Zd d Zd dZddZdqddZddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Z drd/d0Z!d1d2Z"d3d4Z#d5d6Z$d7d8Z%dsd9d:Z&dtd;d<Z'd=d>Z(dud?d@Z)dAZ*dBZ+dCZ,dvdDdEZ-dwdFdGZ.dxdHdIZ/dydJdKZ0dLdMZ1dNdOZ2dPdQZ3dzdRdSZ4d{dTdUZ5d|dWdXZ6d}dYdZZ7d~d[d\Z8dd^d_Z9ddadbZ:dcddZ;dedfZdkdlZ?ddndoZ@dS) CCompilerNczc++Zobjc).cz.ccz.cppz.cxxz.mrcCsb||_||_||_d|_g|_g|_g|_g|_g|_g|_ |j D]}| ||j |qFdSN) dry_runforceverbose output_dirmacros include_dirs libraries library_dirsruntime_library_dirsobjects executableskeysset_executable)selfrrrkeyr+/usr/lib64/python3.8/distutils/ccompiler.py__init__UszCCompiler.__init__cKs<|D]2}||jkr&td||jjf||||qdS)Nz$unknown executable '%s' for class %s)r ValueError __class____name__r)rkwargsrrrrset_executablesys   zCCompiler.set_executablescCs,t|trt||t|n t|||dSr) isinstancestrsetattrr)rrvaluerrrrs zCCompiler.set_executablecCs0d}|jD] }|d|kr"|S|d7}q dS)Nr)r)rnameidefnrrr _find_macros    zCCompiler._find_macrocCs`|D]V}t|trFt|dkrFt|dts8|ddkrFt|dtstd|ddqdS)N)r*r*rzinvalid macro definition '%s': z.must be tuple (string,), (string, string), or z(string, None))r&tuplelenr' TypeError)rZ definitionsr-rrr_check_macro_definitionss     z"CCompiler._check_macro_definitionscCs.||}|dk r|j|=|j||fdSrr.rappend)rr+r)r,rrr define_macros zCCompiler.define_macrocCs0||}|dk r|j|=|f}|j|dSrr4)rr+r,Zundefnrrrundefine_macros zCCompiler.undefine_macrocCs|j|dSr)rr5rdirrrradd_include_dirszCCompiler.add_include_dircCs|dd|_dSrrrdirsrrrset_include_dirsszCCompiler.set_include_dirscCs|j|dSr)rr5)rlibnamerrr add_libraryszCCompiler.add_librarycCs|dd|_dSr)r)rZlibnamesrrr set_librariesszCCompiler.set_librariescCs|j|dSr)rr5r8rrradd_library_dirszCCompiler.add_library_dircCs|dd|_dSr)rr<rrrset_library_dirs szCCompiler.set_library_dirscCs|j|dSr)rr5r8rrradd_runtime_library_dirsz!CCompiler.add_runtime_library_dircCs|dd|_dSr)rr<rrrset_runtime_library_dirssz"CCompiler.set_runtime_library_dirscCs|j|dSr)rr5)robjectrrradd_link_object szCCompiler.add_link_objectcCs|dd|_dSr)r)rrrrrset_link_objects(szCCompiler.set_link_objectscCs|dkr|j}nt|ts"td|dkr2|j}n"t|trL||jpFg}ntd|dkrd|j}n*t|ttfrt||jpg}ntd|dkrg}|j|d|d}t ||}i} t t |D]B} || } || } t j | d} |t j | | | f| | <q||||| fS)N%'output_dir' must be a string or None/'macros' (if supplied) must be a list of tuples6'include_dirs' (if supplied) must be a list of stringsr) strip_dirrr*)rr&r'r2rlistrr0object_filenamesgen_preprocess_optionsranger1ospathsplitextrdirname)rZoutdirrZincdirssourcesdependsZextrarpp_optsbuildr,srcobjextrrr_setup_compile6s<   zCCompiler._setup_compilecCs0|dg}|rdg|dd<|r,||dd<|S)Nz-cz-grr)rrWdebugZbeforecc_argsrrr _get_cc_argsas   zCCompiler._get_cc_argscCs|dkr|j}nt|ts"td|dkr2|j}n"t|trL||jpFg}ntd|dkrd|j}n*t|ttfrt||jpg}ntd|||fS)NrIrJrK)rr&r'r2rrMrr0)rrrrrrr_fix_compile_argsjs"   zCCompiler._fix_compile_argscCs|j||d}|ifS)N)r)rN)rrUrrVrrrr _prep_compiles zCCompiler._prep_compilecCsHt|ttfstdt|}|dkr.|j}nt|ts@td||fS)Nz,'objects' must be a list or tuple of stringsrI)r&rMr0r2rr')rrrrrr_fix_object_argss zCCompiler._fix_object_argscCs|dkr|j}n*t|ttfr2t||jp,g}ntd|dkrJ|j}n*t|ttfrlt||jpfg}ntd|dkr|j}n*t|ttfrt||jpg}ntd|||fS)Nz3'libraries' (if supplied) must be a list of stringsz6'library_dirs' (if supplied) must be a list of stringsz>'runtime_library_dirs' (if supplied) must be a list of strings)rr&rMr0r2rr)rrrrrrr _fix_lib_argss,zCCompiler._fix_lib_argscCs2|jr dS|jr t||dd}n t||}|SdS)NTnewer)Zmissing)rrr)rr output_filerdrrr _need_links  zCCompiler._need_linkc Cs~t|ts|g}d}t|j}|D]V}tj|\}}|j|}z |j |}||kr`|}|}Wq"t k rvYq"Xq"|Sr) r&rMr1language_orderrQrRrS language_mapgetindexr!) rrUZlangrjsourcebaser[ZextlangZextindexrrrdetect_languages    zCCompiler.detect_languagecCsdSrr)rrkrerr extra_preargsextra_postargsrrr preprocesss zCCompiler.preprocessc  Csx|||||||\}} }} } || ||} | D]B} z| | \}}Wntk r\Yq0YnX|| ||| || q0| Sr)r\r_KeyError_compile)rrUrrrr]rnrorVrrWrXr^rZrYr[rrrcompiles6   zCCompiler.compilecCsdSrr)rrZrYr[r^rorWrrrrrCszCCompiler._compilecCsdSrr)rroutput_libnamerr] target_langrrrcreate_static_libIszCCompiler.create_static_libZ shared_objectZshared_library executablecCstdSrNotImplementedError)rZ target_descroutput_filenamerrrrexport_symbolsr]rnro build_temprurrrlinkis9zCCompiler.linkc Cs2|tj||j|dd||||||| | | | dS)Nshared)lib_type)r}r SHARED_LIBRARYlibrary_filename) rrrtrrrrr{r]rnror|rurrrlink_shared_libs  zCCompiler.link_shared_libc Cs(|tj||||||||| | | | dSr)r}r SHARED_OBJECT) rrrzrrrrr{r]rnror|rurrrlink_shared_objects zCCompiler.link_shared_objectc Cs.|tj|||||||d||| d| dSr)r}r EXECUTABLEexecutable_filename) rrZoutput_prognamerrrrr]rnrorurrrlink_executables zCCompiler.link_executablecCstdSrrxr8rrrlibrary_dir_optionszCCompiler.library_dir_optioncCstdSrrxr8rrrruntime_library_dir_optionsz$CCompiler.runtime_library_dir_optioncCstdSrrx)rlibrrrlibrary_optionszCCompiler.library_optionc Csddl}|dkrg}|dkr g}|dkr,g}|dkr8g}|jd|dd\}}t|d} z*|D]} | d| q^| d|W5| Xz|j|g|d} Wntk rYd SXz|j| d ||d Wnt t fk rYd SXdS) Nrr T)textwz#include "%s" z=int main (int argc, char **argv) { %s(); return 0; } r;Fza.out)rr) tempfileZmkstemprQfdopenclosewritersZ CompileErrorrZ LinkErrorr2) rfuncnameZincludesrrrrfdZfnamefZinclrrrr has_functions<     zCCompiler.has_functioncCstdSrrx)rr=rr]rrrfind_library_file$szCCompiler.find_library_filecCs|dkr d}g}|D]|}tj|\}}tj|d}|tj|d}||jkrftd||f|rvtj|}|tj |||j q|S)Nrr*z"unknown file type '%s' (from '%s')) rQrRrS splitdriveisabssrc_extensionsZUnknownFileErrorbasenamer5join obj_extension)rZsource_filenamesrLrZ obj_namesZsrc_namerlr[rrrrNOs"    zCCompiler.object_filenamescCs$|rtj|}tj|||jSr)rQrRrrshared_lib_extensionrrrLrrrrshared_object_filename`s z CCompiler.shared_object_filenamecCs(|rtj|}tj|||jp"dS)Nr)rQrRrr exe_extensionrrrrrfs zCCompiler.executable_filenamestaticc Cs`|dkrtdt||d}t||d}tj|\}}|||f} |rPd}tj||| S)N)rr~ZdylibZ xcode_stubz?'lib_type' must be "static", "shared", "dylib", or "xcode_stub"Z _lib_formatZ_lib_extensionr)r!getattrrQrRsplitr) rr?rrLrZfmtr[r9rlfilenamerrrrls zCCompiler.library_filenamer*cCst|dSr)r r])rmsglevelrrrannounceszCCompiler.announcecCsddlm}|rt|dS)Nr)DEBUG)Zdistutils.debugrprint)rrrrrr debug_prints zCCompiler.debug_printcCstjd|dS)Nz warning: %s )sysstderrr)rrrrrwarnszCCompiler.warncCst||||jdSr)r r)rfuncargsrrrrrr szCCompiler.executecCst||jddSN)r)rr)rcmdrrrrszCCompiler.spawncCst|||jdSr)rr)rrYZdstrrrrszCCompiler.move_filecCst|||jddSr)rr)rr+moderrrrszCCompiler.mkpath)rrr)N)N)NNNNN)NNNrNNN)NrN) NNNNNrNNNN) NNNNNrNNNN) NNNNNrNNNN)NNNNrNNN)NNNN)r)rr)rr)rr)rrr)r*)Nr*)r)Ar# __module__ __qualname__Z compiler_typerrZstatic_lib_extensionrZstatic_lib_formatZshared_lib_formatrrhrgr r%rr.r3r6r7r:r>r@rArBrCrDrErGrHr\r_r`rarbrcrfrmrprsrrrvrrrr}rrrrrrrrrNrrrrrrr rrrrrrrr s  $   +  "   D  A    , +      r ))zcygwin.*unix)posixr)ntmsvccCsV|dkrtj}|dkrtj}tD]0\}}t||dk sHt||dk r |Sq dS)Nr)rQr+rplatform_default_compilersrematch)Zosnamerpatterncompilerrrrget_default_compilers   r)Z unixccompilerZ UnixCCompilerzstandard UNIX-style compiler)Z _msvccompilerZ MSVCCompilerzMicrosoft Visual C++)cygwinccompilerZCygwinCCompilerz'Cygwin port of GNU C Compiler for Win32)rZMingw32CCompilerz(Mingw32 port of GNU C Compiler for Win32)Z bcppcompilerZ BCPPCompilerzBorland C++ Compiler)rrcygwinZmingw32ZbcppcCsXddlm}g}tD] }|d|dt|dfq|||}|ddS)Nr) FancyGetoptz compiler=r/zList of available compilers:)Zdistutils.fancy_getoptrcompiler_classrr5sortZ print_help)rZ compilersrZpretty_printerrrrshow_compilerss    rc Cs|dkrtj}z"|dkr t|}t|\}}}Wn8tk rhd|}|dk r\|d|}t|YnXz*d|}t|tj|} t | |} WnBt k rt d|Yn$tk rt d||fYnX| d||S)Nz5don't know how to compile C/C++ code on platform '%s'z with '%s' compilerz distutils.z4can't compile C/C++ code: unable to load module '%s'zBcan't compile C/C++ code: unable to find class '%s' in module '%s') rQr+rrrqZDistutilsPlatformError __import__rmodulesvars ImportErrorZDistutilsModuleError) ZplatrrrrZ module_name class_nameZlong_descriptionrmoduleklassrrr new_compilers:    rcCsg}|D]}t|tr0dt|kr.dkss6       --