efdZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z ddl m Z ddlmZddlmZdd lmZmZdd lmZGd d Zd ZddZddddddZdZddZdZdZdS)zdistutils.ccompiler Contains CCompiler, an abstract base class that defines the interface for the Distutils compiler abstraction model.N) CompileError LinkErrorUnknownFileErrorDistutilsPlatformErrorDistutilsModuleError)spawn) move_file)mkpath) newer_group) split_quotedexecute)logcPeZdZdZdZdZdZdZdZdZ dZ dZ ddddddZ gdZ gZ gZ dDd Zd Zd Zd Zd ZdEdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dEdZ$dZ%dZ&d Z'd!Z( dFd"Z) dGd#Z*d$Z+ dHd%Z,d&Z-d'Z.d(Z/ dId)Z0 dId*Z1 dId+Z2 dJd,Z3d-Z4d.Z5d/Z6 dKd0Z7dLd1Z8dMd3Z9e:d4Z;d5ZdMd7Z?dMd8Z@ dNd:ZAdOd<ZBd=ZCd>ZDdPd?ZEd@ZFdAZGdQdCZHdS)R CCompileraAbstract base class to define the interface that must be implemented by real compiler classes. Also has some utility methods used by several compiler classes. The basic idea behind a compiler abstraction class is that each instance can be used for all the compile/link steps in building a single project. Thus, attributes common to all of those compile and link steps -- include directories, macros to define, libraries to link against, etc. -- are attributes of the compiler instance. To allow for variability in how individual files are treated, most of those attributes may be varied on a per-compilation or per-link basis. Ncc++objc).cz.ccz.cppz.cxxz.m)rrrrc ||_||_||_d|_g|_g|_g|_g|_g|_g|_ |j D]#}| ||j |$dSN) dry_runforceverbose output_dirmacros include_dirs libraries library_dirsruntime_library_dirsobjects executableskeysset_executable)selfrrrkeys /builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/setuptools/_distutils/ccompiler.py__init__zCCompiler.__init__js     %'! #((** < K  DAw$ FAAtr)c|D]~}t|trOt|dvr>t|dts|dt|dtst d|zdzdzdS)zEnsures that every element of 'definitions' is a valid macro definition, ie. either (name,value) 2-tuple or a (name,) tuple. Do nothing if all definitions are OK, raise TypeError otherwise. )rrNrzinvalid macro definition '%s': z.must be tuple (string,), (string, string), or z(string, None))r1tuplelenr2 TypeError)r% definitionsr8s r'_check_macro_definitionsz"CCompiler._check_macro_definitionss   D4'' II''#DGS11(59!W_tAw,,6E 6=FG&' 6E  r)c|||}||j|=|j||fdS)a_Define a preprocessor macro for all compilations driven by this compiler object. The optional parameter 'value' should be a string; if it is not supplied, then the macro will be defined without an explicit value and the exact outcome depends on the compiler used (XXX true? does ANSI say anything about this?) Nr9rappend)r%r6r4r7s r' define_macrozCCompiler.define_macrosE   T " " = A D%=)))))r)c~||}||j|=|f}|j|dS)aUndefine a preprocessor macro for all compilations driven by this compiler object. If the same macro is defined by 'define_macro()' and undefined by 'undefine_macro()' the last call takes precedence (including multiple redefinitions or undefinitions). If the macro is redefined/undefined on a per-compilation basis (ie. in the call to 'compile()'), then that takes precedence. NrB)r%r6r7undefns r'undefine_macrozCCompiler.undefine_macrosH   T " " = A 6"""""r)c:|j|dS)zAdd 'dir' to the list of directories that will be searched for header files. The compiler is instructed to search directories in the order in which they are supplied by successive calls to 'add_include_dir()'. N)rrCr%dirs r'add_include_dirzCCompiler.add_include_dir!   %%%%%r)c$|dd|_dS)aySet the list of directories that will be searched to 'dirs' (a list of strings). Overrides any preceding calls to 'add_include_dir()'; subsequence calls to 'add_include_dir()' add to the list passed to 'set_include_dirs()'. This does not affect any list of standard include directories that the compiler may search by default. Nrr%dirss r'set_include_dirszCCompiler.set_include_dirss!Gr)c:|j|dS)aAdd 'libname' to the list of libraries that will be included in all links driven by this compiler object. Note that 'libname' should *not* be the name of a file containing a library, but the name of the library itself: the actual filename will be inferred by the linker, the compiler, or the compiler class (depending on the platform). The linker will be instructed to link against libraries in the order they were supplied to 'add_library()' and/or 'set_libraries()'. It is perfectly valid to duplicate library names; the linker will be instructed to link against libraries as many times as they are mentioned. N)rrC)r%libnames r' add_libraryzCCompiler.add_librarys  g&&&&&r)c$|dd|_dS)zSet the list of libraries to be included in all links driven by this compiler object to 'libnames' (a list of strings). This does not affect any standard system libraries that the linker may include by default. N)r)r%libnamess r' set_librarieszCCompiler.set_librariess "!!!r)c:|j|dS)a'Add 'dir' to the list of directories that will be searched for libraries specified to 'add_library()' and 'set_libraries()'. The linker will be instructed to search for libraries in the order they are supplied to 'add_library_dir()' and/or 'set_library_dirs()'. N)rrCrIs r'add_library_dirzCCompiler.add_library_dirrLr)c$|dd|_dS)zSet the list of library search directories to 'dirs' (a list of strings). This does not affect any standard library search path that the linker may search by default. N)rrOs r'set_library_dirszCCompiler.set_library_dirs's !Gr)c:|j|dS)zlAdd 'dir' to the list of directories that will be searched for shared libraries at runtime. N)r rCrIs r'add_runtime_library_dirz!CCompiler.add_runtime_library_dir.s! !((-----r)c$|dd|_dS)zSet the list of directories to search for shared libraries at runtime to 'dirs' (a list of strings). This does not affect any standard search path that the runtime linker may search by default. N)r rOs r'set_runtime_library_dirsz"CCompiler.set_runtime_library_dirs4s %)G!!!r)c:|j|dS)zAdd 'object' to the list of object files (or analogues, such as explicitly named library files or the output of "resource compilers") to be included in every link driven by this compiler object. N)r!rC)r%objects r'add_link_objectzCCompiler.add_link_object<s F#####r)c$|dd|_dS)zSet the list of object files (or analogues) to be included in every link to 'objects'. This does not affect any standard object files that the linker may include by default (such as system libraries). N)r!)r%r!s r'set_link_objectszCCompiler.set_link_objectsDs qqqz r)c||||\}}}|g}||d|}t|t|ksJt||}i} t t|D]p} || } || } t j| d} |t j | | | f| | <q||||| fS)z;Process arguments and decide which source files to compile.Nr) strip_dirrr) _fix_compile_argsobject_filenamesr=gen_preprocess_optionsrangeospathsplitextr dirname)r%outdirrincdirssourcesdependsextrar!pp_optsbuildr7srcobjexts r'_setup_compilezCCompiler._setup_compileQs"&"8"8"Q"Q =E''1'PP7||s7||++++(99s7||$$ $ $A!*C!*C'""3''*C KK,, - - -sE#JJww55r)c8|dgz}|rdg|dd<|r||dd<|S)Nz-cz-gr)r%rtdebugbeforecc_argss r' _get_cc_argszCCompiler._get_cc_argshs?TF"  !&GBQBK  ! GBQBKr)c||j}n$t|tstd||j}n1t|t r ||jpgz}ntd|t |j}nEt|t tfrt ||jpgz}ntd||jjz }|||fS)a'Typecheck and fix-up some of the arguments to the 'compile()' method, and return fixed-up values. Specifically: if 'output_dir' is None, replaces it with 'self.output_dir'; ensures that 'macros' is a list, and augments it with 'self.macros'; ensures that 'include_dirs' is a list, and augments it with 'self.include_dirs'. Guarantees that the returned values are of the correct type, i.e. for 'output_dir' either string or None, and for 'macros' and 'include_dirs' either list or None. N%'output_dir' must be a string or Nonez/'macros' (if supplied) must be a list of tuplesz6'include_dirs' (if supplied) must be a list of strings) rr1r2r>rlistrr<r,)r%rrrs r'rgzCCompiler._fix_compile_argsqs  JJJ,, ECDD D >[FF  % % Ot{0b1FFMNN N   122LL  tUm 4 4 V --1B1HbILLTUU U 33 6<//r)c||||}t|t|ksJ|ifS)a,Decide which source files must be recompiled. Determine the list of object files corresponding to 'sources', and figure out which ones really need to be recompiled. Return a list of all object files and a dictionary telling which source files can be skipped. r)rhr=)r%rqrrrr!s r' _prep_compilezCCompiler._prep_compilesE''J'GG7||s7||++++{r)ct|ttfstdt|}||j}n$t|t std||fS)zTypecheck and fix up some arguments supplied to various methods. Specifically: ensure that 'objects' is a list; if output_dir is None, replace with self.output_dir. Return fixed versions of 'objects' and 'output_dir'. z,'objects' must be a list or tuple of stringsNr)r1rr<r>rr2)r%r!rs r'_fix_object_argszCCompiler._fix_object_argssq 'D%=11 LJKK Kw--  JJJ,, ECDD D$$r)c||j}nEt|ttfrt||jpgz}nt d||j}nEt|ttfrt||jpgz}nt d||jjz }||j}nEt|ttfrt||jpgz}nt d|||fS)a;Typecheck and fix up some of the arguments supplied to the 'link_*' methods. Specifically: ensure that all arguments are lists, and augment them with their permanent versions (eg. 'self.libraries' augments 'libraries'). Return a tuple with fixed versions of all arguments. 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)rr1rr<r>rr,r )r%rrr s r' _fix_lib_argszCCompiler._fix_lib_argss'  II  D%= 1 1 SY4>+?R@IIQRR R  ,LL  tUm 4 4 V --1B1HbILLTUU U 33  '#'#< ,tUm < < #'(<#=#=)/R$ S <)=>>r)cl|jrdS|jrt||d}nt||}|S)zjReturn true if we need to relink the files listed in 'objects' to recreate 'output_file'. Tnewer)missing)rrr )r%r! output_filers r' _need_linkzCCompiler._need_linksG : 4| :#G['JJJ#G[99Lr)cNt|ts|g}d}t|j}|D]s}tj|\}}|j|} |j |}||kr|}|}d#t$rYpwxYw|S)z|Detect the language of a given file, or list of files. Uses language_map, and language_order to do the job. N) r1rr=language_orderrkrlrm language_mapgetindexr+) r%rqlangrsourcebaserxextlangextindexs r'detect_languagezCCompiler.detect_languages'4(( iGD'((  F((00ID#'++C00G .44W==e##"D$E     s0$B B"!B"cdS)aPreprocess a single C/C++ source file, named in 'source'. Output will be written to file named 'output_file', or stdout if 'output_file' not supplied. 'macros' is a list of macro definitions as for 'compile()', which will augment the macros set with 'define_macro()' and 'undefine_macro()'. 'include_dirs' is a list of directory names that will be added to the default list. Raises PreprocessError on failure. Nr{)r%rrrr extra_preargsextra_postargss r' preprocesszCCompiler.preprocesss $ r)c |||||||\}} }} } || ||} | D]9} | | \}}n#t$rYwxYw|| ||| || :| S)aK Compile one or more source files. 'sources' must be a list of filenames, most likely C/C++ files, but in reality anything that can be handled by a particular compiler and compiler class (eg. MSVCCompiler can handle resource files in 'sources'). Return a list of object filenames, one per source filename in 'sources'. Depending on the implementation, not all source files will necessarily be compiled, but all corresponding object filenames will be returned. If 'output_dir' is given, object files will be put under it, while retaining their original path component. That is, "foo/bar.c" normally compiles to "foo/bar.o" (for a Unix implementation); if 'output_dir' is "build", then it would compile to "build/foo/bar.o". 'macros', if given, must be a list of macro definitions. A macro definition is either a (name, value) 2-tuple or a (name,) 1-tuple. The former defines a macro; if the value is None, the macro is defined without an explicit value. The 1-tuple case undefines a macro. Later definitions/redefinitions/ undefinitions take precedence. 'include_dirs', if given, must be a list of strings, the directories to add to the default include file search path for this compilation only. 'debug' is a boolean; if true, the compiler will be instructed to output debug symbols in (or alongside) the object file(s). 'extra_preargs' and 'extra_postargs' are implementation- dependent. On platforms that have the notion of a command-line (e.g. Unix, DOS/Windows), they are most likely lists of strings: extra command-line arguments to prepend/append to the compiler command line. On other platforms, consult the implementation class documentation. In any event, they are intended as an escape hatch for those occasions when the abstract compiler framework doesn't cut the mustard. 'depends', if given, is a list of filenames that all targets depend on. If a source file is older than any file in depends, then the source file will be recompiled. This supports dependency tracking, but only at a coarse granularity. Raises CompileError on failure. )ryrKeyError_compile)r%rqrrrr|rrrrr!rtrur~rwrvrxs r'compilezCCompiler.compilesz;?:M:M  gw; ; 7%##GUMBB K KC  :SS     MM#sC.' J J J Js A  AAcdS)zCompile 'src' to product 'obj'.Nr{)r%rwrvrxr~rrts r'rzCCompiler._compile]s  r)cdS)a&Link a bunch of stuff together to create a static library file. The "bunch of stuff" consists of the list of object files supplied as 'objects', the extra object files supplied to 'add_link_object()' and/or 'set_link_objects()', the libraries supplied to 'add_library()' and/or 'set_libraries()', and the libraries supplied as 'libraries' (if any). 'output_libname' should be a library name, not a filename; the filename will be inferred from the library name. 'output_dir' is the directory where the library file will be put. 'debug' is a boolean; if true, debugging information will be included in the library (note that on most platforms, it is the compile step where this matters: the 'debug' flag is included here just for consistency). 'target_lang' is the target language for which the given objects are being compiled. This allows specific linkage time treatment of certain languages. Raises LibError on failure. Nr{)r%r!output_libnamerr| target_langs r'create_static_libzCCompiler.create_static_libcs 2 r) shared_objectshared_library executablect)auLink a bunch of stuff together to create an executable or shared library file. The "bunch of stuff" consists of the list of object files supplied as 'objects'. 'output_filename' should be a filename. If 'output_dir' is supplied, 'output_filename' is relative to it (i.e. 'output_filename' can provide directory components if needed). 'libraries' is a list of libraries to link against. These are library names, not filenames, since they're translated into filenames in a platform-specific way (eg. "foo" becomes "libfoo.a" on Unix and "foo.lib" on DOS/Windows). However, they can include a directory component, which means the linker will look in that specific directory rather than searching all the normal locations. 'library_dirs', if supplied, should be a list of directories to search for libraries that were specified as bare library names (ie. no directory component). These are on top of the system default and those supplied to 'add_library_dir()' and/or 'set_library_dirs()'. 'runtime_library_dirs' is a list of directories that will be embedded into the shared library and used to search for other shared libraries that *it* depends on at run-time. (This may only be relevant on Unix.) 'export_symbols' is a list of symbols that the shared library will export. (This appears to be relevant only on Windows.) 'debug' is as for 'compile()' and 'create_static_lib()', with the slight distinction that it actually matters on most platforms (as opposed to 'create_static_lib()', which includes a 'debug' flag mostly for form's sake). 'extra_preargs' and 'extra_postargs' are as for 'compile()' (except of course that they supply command-line arguments for the particular linker being used). 'target_lang' is the target language for which the given objects are being compiled. This allows specific linkage time treatment of certain languages. Raises LinkError on failure. NotImplementedError)r% target_descr!output_filenamerrrr export_symbolsr|rr build_temprs r'linkzCCompiler.links v"!r)c |tj|||d||||||| | | | dS)Nshared)lib_type)rrSHARED_LIBRARYlibrary_filename) r%r!rrrrr rr|rrrrs r'link_shared_libzCCompiler.link_shared_libsa  $   ! !.8 ! D D              r)c \|tj||||||||| | | | dSr)rr SHARED_OBJECT) r%r!rrrrr rr|rrrrs r'link_shared_objectzCCompiler.link_shared_objectsN  #                r)c |tj|||||||d||| d| dSr)rr EXECUTABLEexecutable_filename) r%r!output_prognamerrrr r|rrrs r'link_executablezCCompiler.link_executables\    $ $_ 5 5              r)ct)zkReturn the compiler option to add 'dir' to the list of directories searched for libraries. rrIs r'library_dir_optionzCCompiler.library_dir_option" "!r)ct)zsReturn the compiler option to add 'dir' to the list of directories searched for runtime libraries. rrIs r'runtime_library_dir_optionz$CCompiler.runtime_library_dir_option(rr)ct)zReturn the compiler option to add 'lib' to the list of libraries linked into the shared library or executable. r)r%libs r'library_optionzCCompiler.library_option.rr)c<ddl}|g}ntjdt|g}ntjdt|g}|g}|d|d\}}t j|d} |D]} | d | z|s| d |z| d |z| n#| wxYw | |g| } n%#t$rYt j |d SwxYw t j |n#t j |wxYw | | d||t j | d|jpdn1#tt f$rY| D]} t j | d SwxYw | D]} t j | n#| D]} t j | wxYwdS)aRReturn a boolean indicating whether funcname is provided as a symbol on the current platform. The optional arguments can be used to augment the compilation environment. The libraries argument is a list of flags to be passed to the linker to make additional symbol definitions available for linking. The includes and include_dirs arguments are deprecated. Usually, supplying include files with function declarations will cause function detection to fail even in cases where the symbol is available for linking. rNzincludes is deprecatedzinclude_dirs is deprecatedrT)textwz#include "%s" z4#ifdef __cplusplus extern "C" #endif char %s(void); z=int main (int argc, char **argv) { %s(); return 0; } rNFza.out)rrr)tempfilewarningswarnDeprecationWarningmkstemprkfdopenwritecloserrremoverrrrr>) r%funcnameincludesrrrrfdfnamefinclr!fns r' has_functionzCCompiler.has_function4s2   HH M24F G G G  LL M68J K K K  I  L$$T8$$?? E Ib#     6 6-45555    GG      GGIIIIAGGIIII llE7lFFGG    Ie        Ie    BIe       IL !    I((T_=RPR(SS    9%       "        "  g   "  tsa2G G>G  G>>Hct)aHSearch the specified list of directories for a static or shared library file 'lib' and return the full path to that file. If 'debug' true, look for a debugging version (if that makes sense on the current platform). Return None if 'lib' wasn't found in any of the specified directories. r)r%rPrr|s r'find_library_filezCCompiler.find_library_files "!r)rcJdtfd|DS)Nrc3FK|]}|VdSr)_make_out_path).0src_namerr%rfs r' z-CCompiler.object_filenames..sI      Ix @ @      r))r)r%source_filenamesrfrs` ``r'rhzCCompiler.object_filenamessR  J      ,      r)cLt|j|jSr)dictfromkeyssrc_extensions obj_extension)r%s r'out_extensionszCCompiler.out_extensionss}}T0$2DEEEr)cxtj|\}}||} |j|}n1#t $r$t d||wxYw|rtj|}tj |||zS)Nz"unknown file type '{}' (from '{}')) rkrlrm_make_relativer LookupErrorrformatbasenamejoin)r%rrfrrrxnew_exts r'rzCCompiler._make_out_pathsG$$X.. c""4(( )#.GG   "4;;CJJ    *7##D))Dw||Jw777s A.A5ctj|d}|tj|dS)z In order to ensure that a filename always honors the indicated output_dir, make sure it's relative. Ref python/cpython#37775. rN)rkrl splitdriveisabs)rno_drives r'rzCCompiler._make_relatives=7%%d++A. h//1122r)c|J|rtj|}tj|||jzSr)rkrlrrshared_lib_extensionr%rrfrs r'shared_object_filenamez CCompiler.shared_object_filenamesI%%%  2w''11Hw||J43L(LMMMr)c|J|rtj|}tj|||jpdzS)Nr)rkrlrr exe_extensionrs r'rzCCompiler.executable_filenamesN%%%  2w''11Hw||JD4F4L"(MNNNr)staticc<|Jd}|t|vrtd|t||dz}t||dz}tj|\}} || |fz} |rd}tj||| S)Nz)"static", "shared", "dylib", "xcode_stub"z'lib_type' must be _lib_format_lib_extensionr)evalr+getattrrkrlsplitr) r%rSrrfrexpectedfmtrxrJrfilenames r'rzCCompiler.library_filenames%%%> 4>> ) )=8==>> >dH}455dH'7788GMM'** T$$  Cw||JX666r)rc.tj|dSr)rr|)r%msglevels r'announcezCCompiler.announces #r)c8ddlm}|rt|dSdS)Nr)DEBUG)distutils.debugr print)r%rr s r' debug_printzCCompiler.debug_prints5))))))   #JJJJJ  r)cJtjd|zdS)Nz warning: %s )sysstderrr)r%rs r'rzCCompiler.warn s# 3./////r)c4t||||jdSr)rr)r%funcargsrr s r'rzCCompiler.execute sdC.....r)c .t|fd|ji|dS)Nr)r r)r%cmdr.s r'r zCCompiler.spawns% c224<2622222r)c0t|||jSN)r)r r)r%rvdsts r'r zCCompiler.move_filesc4<8888r)c4t|||jdSr)r r)r%r6modes r'r zCCompiler.mkpathstT4<000000r))rrrr)NNNNN)NNNrNNN)NrN) NNNNNrNNNN)NNNNrNNN)NNNN)r)rr)rrr)r)Nr)r)Ir- __module__ __qualname____doc__ compiler_typerrstatic_lib_extensionrstatic_lib_formatshared_lib_formatrrrrrr(r/r$r9r@rDrGrKrQrTrWrYr[r]r_rbrdryrrgrrrrrrrrrrrrrrrrrrrrrrhpropertyrr staticmethodrrrrr rrrr r r r{r)r'rrs  *M2NMM L*))NLL"<"<"<"rC)rrrtmacrorJs r'riris*G225%(( Q#e**-A-A-A-A-A-A-A-AHJOP  u::?? NN6E!H, - - - - ZZ1__Qxva01111 y50111%%v|$$$$ Nr)c*g}|D]*}|||+|D]G}||}t|tr||z}2||H|D]}t j|\}} |rH||g| } | r|| U| d|zn|| ||S)acGenerate linker options for searching library directories and linking with specific libraries. 'libraries' and 'library_dirs' are, respectively, lists of library names (not filenames!) and search directories. Returns a list of command-line options suitable for use with some compiler (depending on the two format strings passed in). z6no library file corresponding to '%s' found (skipping)) rCrrr1rrkrlrrrr) r2rr rlib_optsrJoptrlib_dirlib_namelib_files r'gen_lib_optionsr^sBH::33C889999#!!11#66 c4  !#~HH OOC  : : gmmC00(  :117)XFFH )))) ORUU OOH33C88 9 9 9 9 Or))NN)NNrrr)r rrkr.rerrorsrrrrrr file_utilr dir_utilr _modifiedr utilr r_logrrr-r3rCrHrUrir^r{r)r'res11   """"""''''''''}1}1}1}1}1}1}1}1H 8 O E  E">>>"+'+'+'+'\***Z%%%%%r)