class documentation

Abstract 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.

Method __init__ Undocumented
Method add_include_dir Add '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()'.
Method add_library Add '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).
Method add_library_dir 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()'.
Method add_link_object Add '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.
Method add_runtime_library_dir Add 'dir' to the list of directories that will be searched for shared libraries at runtime.
Method announce Undocumented
Method compile Compile one or more source files.
Method create_static_lib 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).
Method debug_print Undocumented
Method define_macro 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...
Method detect_language Detect the language of a given file, or list of files. Uses language_map, and language_order to do the job.
Method executable_filename Undocumented
Method execute Undocumented
Method find_library_file Search 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)...
Method has_function Return 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.
Method library_dir_option Return the compiler option to add 'dir' to the list of directories searched for libraries.
Method library_filename Undocumented
Method library_option Return the compiler option to add 'lib' to the list of libraries linked into the shared library or executable.
Method link Link a bunch of stuff together to create an executable or shared library file.
Method link_executable Undocumented
Method link_shared_lib Undocumented
Method link_shared_object Undocumented
Method mkpath Undocumented
Method move_file Undocumented
Method object_filenames Undocumented
Method preprocess Preprocess 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()'...
Method runtime_library_dir_option Return the compiler option to add 'dir' to the list of directories searched for runtime libraries.
Method set_executable Undocumented
Method set_executables Define the executables (and options for them) that will be run to perform the various stages of compilation. The exact set of executables that may be specified here depends on the compiler class (via the 'executables' class attribute), but most will have: compiler the C/C++ compiler linker_so linker used to create shared objects and libraries linker_exe linker used to create binary executables archiver static library creator...
Method set_include_dirs Set 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()'...
Method set_libraries Set 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.
Method set_library_dirs Set 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.
Method set_link_objects Set 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).
Method set_runtime_library_dirs Set 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.
Method shared_object_filename Undocumented
Method spawn Undocumented
Method undefine_macro Undefine 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)...
Method warn Undocumented
Constant EXECUTABLE Undocumented
Constant SHARED_LIBRARY Undocumented
Constant SHARED_OBJECT Undocumented
Class Variable compiler_type Undocumented
Class Variable exe_extension Undocumented
Class Variable language_map Undocumented
Class Variable language_order Undocumented
Class Variable obj_extension Undocumented
Class Variable shared_lib_extension Undocumented
Class Variable shared_lib_format Undocumented
Class Variable src_extensions Undocumented
Class Variable static_lib_extension Undocumented
Class Variable static_lib_format Undocumented
Instance Variable dry_run Undocumented
Instance Variable force Undocumented
Instance Variable include_dirs include dirs specific to this compiler class
Instance Variable libraries Undocumented
Instance Variable library_dirs library dirs specific to this compiler class
Instance Variable macros Undocumented
Instance Variable objects Undocumented
Instance Variable output_dir Undocumented
Instance Variable runtime_library_dirs Undocumented
Instance Variable verbose Undocumented
Property out_extensions Undocumented
Static Method _make_relative In order to ensure that a filename always honors the indicated output_dir, make sure it's relative. Ref python/cpython#37775.
Method _check_macro_definitions Ensures 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.
Method _compile Compile 'src' to product 'obj'.
Method _find_macro Undocumented
Method _fix_compile_args 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...
Method _fix_lib_args 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')...
Method _fix_object_args Typecheck 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'.
Method _get_cc_args Undocumented
Method _make_out_path Undocumented
Method _need_link Return true if we need to relink the files listed in 'objects' to recreate 'output_file'.
Method _prep_compile Decide which source files must be recompiled.
Method _setup_compile Process arguments and decide which source files to compile.
def add_include_dir(self, dir): (source)

Add '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()'.

def add_library(self, libname): (source)

Add '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.

def add_library_dir(self, dir): (source)

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()'.

def add_link_object(self, object): (source)

Add '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.

def add_runtime_library_dir(self, dir): (source)

Add 'dir' to the list of directories that will be searched for shared libraries at runtime.

def announce(self, msg, level=1): (source)

Undocumented

def compile(self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None, depends=None): (source)

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.

def create_static_lib(self, objects, output_libname, output_dir=None, debug=0, target_lang=None): (source)

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.

def debug_print(self, msg): (source)

Undocumented

def define_macro(self, name, value=None): (source)

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?)

def detect_language(self, sources): (source)

Detect the language of a given file, or list of files. Uses language_map, and language_order to do the job.

def executable_filename(self, basename, strip_dir=0, output_dir=''): (source)

Undocumented

def execute(self, func, args, msg=None, level=1): (source)

Undocumented

def find_library_file(self, dirs, lib, debug=0): (source)

Search 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.

def has_function(self, funcname, includes=None, include_dirs=None, libraries=None, library_dirs=None): (source)

Return 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.

def library_dir_option(self, dir): (source)
def library_filename(self, libname, lib_type='static', strip_dir=0, output_dir=''): (source)

Undocumented

def library_option(self, lib): (source)

Return the compiler option to add 'lib' to the list of libraries linked into the shared library or executable.

def link(self, target_desc, objects, output_filename, output_dir=None, libraries=None, library_dirs=None, runtime_library_dirs=None, export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None, build_temp=None, target_lang=None): (source)

Link 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.

def link_executable(self, objects, output_progname, output_dir=None, libraries=None, library_dirs=None, runtime_library_dirs=None, debug=0, extra_preargs=None, extra_postargs=None, target_lang=None): (source)

Undocumented

def link_shared_lib(self, objects, output_libname, output_dir=None, libraries=None, library_dirs=None, runtime_library_dirs=None, export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None, build_temp=None, target_lang=None): (source)

Undocumented

def link_shared_object(self, objects, output_filename, output_dir=None, libraries=None, library_dirs=None, runtime_library_dirs=None, export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None, build_temp=None, target_lang=None): (source)

Undocumented

def mkpath(self, name, mode=511): (source)

Undocumented

def move_file(self, src, dst): (source)

Undocumented

def preprocess(self, source, output_file=None, macros=None, include_dirs=None, extra_preargs=None, extra_postargs=None): (source)

Preprocess 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.

def runtime_library_dir_option(self, dir): (source)
def set_executable(self, key, value): (source)

Undocumented

def set_executables(self, **kwargs): (source)

Define the executables (and options for them) that will be run to perform the various stages of compilation. The exact set of executables that may be specified here depends on the compiler class (via the 'executables' class attribute), but most will have: compiler the C/C++ compiler linker_so linker used to create shared objects and libraries linker_exe linker used to create binary executables archiver static library creator On platforms with a command-line (Unix, DOS/Windows), each of these is a string that will be split into executable name and (optional) list of arguments. (Splitting the string is done similarly to how Unix shells operate: words are delimited by spaces, but quotes and backslashes can override this. See 'distutils.util.split_quoted()'.)

def set_include_dirs(self, dirs): (source)

Set 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.

def set_libraries(self, libnames): (source)

Set 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.

def set_library_dirs(self, dirs): (source)

Set 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.

def set_link_objects(self, objects): (source)

Set 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).

def set_runtime_library_dirs(self, dirs): (source)

Set 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.

def shared_object_filename(self, basename, strip_dir=0, output_dir=''): (source)

Undocumented

def spawn(self, cmd, **kwargs): (source)
def undefine_macro(self, name): (source)

Undefine 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.

def warn(self, msg): (source)

Undocumented

EXECUTABLE: str = (source)

Undocumented

Value
'executable'
SHARED_LIBRARY: str = (source)

Undocumented

Value
'shared_library'
SHARED_OBJECT: str = (source)

Undocumented

Value
'shared_object'
language_map: dict[str, str] = (source)

Undocumented

language_order: list[str] = (source)

Undocumented

Undocumented

Undocumented

include_dirs = (source)

include dirs specific to this compiler class

libraries = (source)

Undocumented

library_dirs = (source)

library dirs specific to this compiler class

Undocumented

Undocumented

output_dir = (source)

Undocumented

runtime_library_dirs = (source)

Undocumented

Undocumented

@staticmethod
def _make_relative(base): (source)

In order to ensure that a filename always honors the indicated output_dir, make sure it's relative. Ref python/cpython#37775.

def _check_macro_definitions(self, definitions): (source)

Ensures 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.

def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): (source)

Compile 'src' to product 'obj'.

def _find_macro(self, name): (source)

Undocumented

def _fix_compile_args(self, output_dir, macros, include_dirs): (source)

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.

def _fix_lib_args(self, libraries, library_dirs, runtime_library_dirs): (source)

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.

def _fix_object_args(self, objects, output_dir): (source)

Typecheck 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'.

def _get_cc_args(self, pp_opts, debug, before): (source)

Undocumented

def _make_out_path(self, output_dir, strip_dir, src_name): (source)
def _need_link(self, objects, output_file): (source)

Return true if we need to relink the files listed in 'objects' to recreate 'output_file'.

def _prep_compile(self, sources, output_dir, depends=None): (source)

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.

def _setup_compile(self, outdir, macros, incdirs, sources, depends, extra): (source)

Process arguments and decide which source files to compile.