_ddZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z ddl m Z ddlmZddlmZdd lmZmZdd lmZGd d Zd ZddZddddddZdZddZdZdZy)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)logcBeZdZdZdZdZdZdZdZdZ dZ dZ ddddddZ gdZ gZ gZ d?dZd Zd Zd Zd Zd@d ZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#d@dZ$dZ%dZ&dZ'd Z( dAd!Z) dBd"Z*d#Z+ dCd$Z,d%Z-d&Z.d'Z/ dDd(Z0 dDd)Z1 dDd*Z2 dEd+Z3d,Z4d-Z5d.Z6 dFd/Z7dGd0Z8dHd1Z9e:d2Z;d3ZdHd5Z?dHd6Z@ dId7ZAdJd8ZBd9ZCd:ZDdKd;ZEd<ZFd=ZGdLd>ZHy)M 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)rrrc ||_||_||_d|_g|_g|_g|_g|_g|_g|_ |jjD]!}|j||j|#yN) dry_runforceverbose output_dirmacros include_dirs libraries library_dirsruntime_library_dirsobjects executableskeysset_executable)selfrrrkeys A/usr/lib/python3/dist-packages/setuptools/_distutils/ccompiler.py__init__zCCompiler.__init__js     %'! ##((* t|t tfrt ||j xsgz}n td||jj z }|||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. %'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  JJ,CD D >[[F  %t{{0b1FMN N   1 12L  tUm 4 -1B1B1HbILTU U 333 6<//r)cb|j||}t|t|k(sJ|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_compiles;''J'G7|s7|+++{r)ct|ttfs tdt|}||j}||fSt|t s td||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 stringsr)r1rr<r>rr2)r%r!rs r'_fix_object_argszCCompiler._fix_object_argssf 'D%=1JK Kw-  J$$J,CD D$$r)c | |j}n>t|ttfrt||jxsgz}n t d| |j }n>t|ttfrt||j xsgz}n t d||j j z }| |j}n>t|ttfrt||jxsgz}n t 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. z3'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  I  D%= 1Y4>>+?R@IQR R  ,,L  tUm 4 -1B1B1HbILTU U 333  '#'#<#< ,tUm <#'(<#=))/R$ S <)=>>r)cp|jry|jrt||d}|St||}|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_links= ::||#G['JL$G[9Lr)cJt|ts|g}d}t|j}|D]d}tj j |\}}|jj|} |jj|}||kr|}|}f|S#t$rYtwxYw)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((0ID#''++C0G ..44W=e#"D$E    s.$B B"!B"cy)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 |j||||||\}} }} } |j| ||} | D]!} | | \}}|j| ||| || #| S#t$rY1wxYw)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%##GUMB KC  :S MM#sC.' J  K   sA A$#A$cy)zCompile 'src' to product 'obj'.Nr{)r%rwrvrxr~rrts r'rzCCompiler._compile]s r)cy)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_libcs2 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 ||jtj||j|d||||||| | | | y)Nshared)lib_type)rrSHARED_LIBRARYlibrary_filename) r%r!rrrrr rr|rrrrs r'link_shared_libzCCompiler.link_shared_libsM  $ $   ! !.8 ! D          r)c Z|jtj||||||||| | | | yr)rr SHARED_OBJECT) r%r!rrrrr rr|rrrrs r'link_shared_objectzCCompiler.link_shared_objects=  # #            r)c x|jtj||j|||||d||| d| yr)rr EXECUTABLEexecutable_filename) r%r!output_prognamerrrr r|rrrs r'link_executablezCCompiler.link_executablesH    $ $_ 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}|j d|d\}}t j |d} |D]} | jd | z|s| jd |z| jd |z| j |j|g| } t j| |j| d||t j|jd|jxsd | D]} t j| y#| jwxYw#t$rYt j|y wxYw#t j|wxYw#tt f$rY| D]} t j| y wxYw#| D]} t j| wxYw)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_function4s 2   H MM24F G  L MM68J K  I  L$$T8$$? E IIb#    6-45 6   GG    GGI llE7lFG IIe    IL !  II((T__=RPR(S   "  + GGI  IIe   IIe  9%    "     "  s[9AE!E6:F44G%!E36 F?FFFF14G"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)c<dtfd|DS)Nrc3DK|]}j|ywr)_make_out_path).0src_namerr%rfs r' z-CCompiler.object_filenames..s(     Ix @ s )r)r%source_filenamesrfrs` ``r'rhzCCompiler.object_filenamess(  J ,   r)cVtj|j|jSr)dictfromkeyssrc_extensions obj_extension)r%s r'out_extensionszCCompiler.out_extensionss}}T00$2D2DEEr)c`tjj|\}}|j|} |j|}|rtjj|}tjj|||zS#t $rt dj||wxYw)Nz"unknown file type '{}' (from '{}')) rkrlrm_make_relativer LookupErrorrformatbasenamejoin)r%rrfrrrxnew_exts r'rzCCompiler._make_out_pathsGG$$X. c""4( ))#.G 77##D)Dww||Jw77  "4;;CJ  s B%B-ctjj|d}|tjj|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_relatives877%%d+A. h/122r)c|J|rtjj|}tjj|||jzSr)rkrlrrshared_lib_extensionr%rrfrs r'shared_object_filenamez CCompiler.shared_object_filenamesE%%% ww''1Hww||J43L3L(LMMr)c|J|rtjj|}tjj|||jxsdzS)Nr)rkrlrr exe_extensionrs r'rzCCompiler.executable_filenamesJ%%% ww''1Hww||JD4F4F4L"(MNNr)c|Jd}|t|vrtd|t||dz}t||dz}tjj |\}} || |fz} |rd}tjj ||| 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> )28*=> >dH}45dH'778GGMM'* T$$ Cww||JX66r)c.tj|yr)rr|)r%msglevels r'announcezCCompiler.announces  #r)c,ddlm}|r t|yy)Nr)DEBUG)distutils.debugr print)r%rr s r' debug_printzCCompiler.debug_prints)  #J r)cHtjjd|zy)Nz warning: %s )sysstderrr)r%rs r'rzCCompiler.warn s 3./r)c4t||||jyr)rr)r%funcargsrrs r'rzCCompiler.execute sdC.r)c 4t|fd|ji|y)Nr)r r)r%cmdr.s r'r zCCompiler.spawns c24<<262r)c2t|||jSN)r)r r)r%rvdsts r'r zCCompiler.move_filesc4<<88r)c4t|||jyr)r r)r%r6modes r'r zCCompiler.mkpathstT4<<0r))rrrr)NNNNN)NNNrNNN)NrN) NNNNNrNNNN)NNNNrNNN)NNNN)r)rr)staticrr)r)Nr)i)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'rrsn *M2NMM L*NLL"rC)rrrtmacrorJs r'riris*G25%(Q#e*-A-AHJOP  u:? NN6E!H, - Z1_Qxva01 y501!2$%v|$% Nr)cg}|D]"}|j|j|$|D]:}|j|}t|tr||z}*|j|<|D]}t j j|\}} |r<|j|g| } | r|j| N|jd|zc|j|j||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) r1rr rlib_optsrJoptrlib_dirlib_namelib_files r'gen_lib_optionsr]sH:33C89:$!11#6 c4 #~H OOC ! : ggmmC0( 117)XFH) ORUU OOH33C8 9 : Or))NN)NNrrr)rrrkr-rerrorsrrrrrr file_utilr dir_utilr dep_utilr utilr r_logrrr,r2rBrGrTrir]r{r)r'rds1   !'}1}1H 8 O E  E">"+'\*Z%r)