ccroot¶
Classes and methods shared by tools providing support for C-like language such as C/C++/D/Assembly/Go (this support module is almost never used alone).
-
waflib.Tools.ccroot.
USELIB_VARS
= {'asm': {'ASFLAGS'}, 'c': {'CPPFLAGS', 'FRAMEWORKPATH', 'ARCH', 'DEFINES', 'CFLAGS', 'INCLUDES', 'FLEXFLAGS', 'CCDEPS'}, 'cprogram': {'LIBPATH', 'LDFLAGS', 'FRAMEWORK', 'LINKFLAGS', 'LIB', 'FRAMEWORKPATH', 'STLIBPATH', 'LINKDEPS', 'ARCH', 'RPATH', 'STLIB'}, 'cs': {'RESOURCES', 'CSFLAGS', 'ASSEMBLIES'}, 'cshlib': {'LIBPATH', 'LDFLAGS', 'FRAMEWORK', 'LINKFLAGS', 'LIB', 'FRAMEWORKPATH', 'STLIBPATH', 'LINKDEPS', 'ARCH', 'RPATH', 'STLIB'}, 'cstlib': {'LINKDEPS', 'ARFLAGS'}, 'cxx': {'CPPFLAGS', 'FRAMEWORKPATH', 'CXXFLAGS', 'ARCH', 'DEFINES', 'INCLUDES', 'CXXDEPS', 'FLEXFLAGS'}, 'cxxprogram': {'LIBPATH', 'LDFLAGS', 'FRAMEWORK', 'LINKFLAGS', 'LIB', 'FRAMEWORKPATH', 'STLIBPATH', 'LINKDEPS', 'ARCH', 'RPATH', 'STLIB'}, 'cxxshlib': {'LIBPATH', 'LDFLAGS', 'FRAMEWORK', 'LINKFLAGS', 'LIB', 'FRAMEWORKPATH', 'STLIBPATH', 'LINKDEPS', 'ARCH', 'RPATH', 'STLIB'}, 'cxxstlib': {'LINKDEPS', 'ARFLAGS'}, 'd': {'INCLUDES', 'DFLAGS'}, 'dprogram': {'LIBPATH', 'LINKFLAGS', 'LIB', 'STLIBPATH', 'LINKDEPS', 'RPATH', 'STLIB'}, 'dshlib': {'LIBPATH', 'LINKFLAGS', 'LIB', 'STLIBPATH', 'LINKDEPS', 'RPATH', 'STLIB'}, 'dstlib': {'LINKDEPS', 'ARFLAGS'}, 'fc': {'INCLUDES', 'FCPPFLAGS', 'FCFLAGS', 'DEFINES'}, 'fcprogram': {'LIBPATH', 'LDFLAGS', 'LINKFLAGS', 'LIB', 'STLIBPATH', 'LINKDEPS', 'RPATH', 'STLIB'}, 'fcprogram_test': {'LIBPATH', 'LDFLAGS', 'LINKFLAGS', 'LIB', 'STLIBPATH', 'LINKDEPS', 'RPATH', 'STLIB'}, 'fcshlib': {'LIBPATH', 'LDFLAGS', 'LINKFLAGS', 'LIB', 'STLIBPATH', 'LINKDEPS', 'RPATH', 'STLIB'}, 'fcstlib': {'LINKDEPS', 'ARFLAGS'}, 'includes': {'INCLUDES', 'ARCH', 'FRAMEWORKPATH'}, 'javac': {'CLASSPATH', 'JAVACFLAGS'}}¶ Mapping for features to
waflib.ConfigSet.ConfigSet
variables. Seewaflib.Tools.ccroot.propagate_uselib_vars()
.
-
waflib.Tools.ccroot.
create_compiled_task
(self, name, node)[source]¶ Task generator method
Create the compilation task: c, cxx, asm, etc. The output node is created automatically (object file with a typical .o extension). The task is appended to the list compiled_tasks which is then used by
waflib.Tools.ccroot.apply_link()
Parameters: - name (string) – name of the task class
- node (
waflib.Node.Node
) – the file to compile
Returns: The task created
Return type:
-
waflib.Tools.ccroot.
to_incnodes
(self, inlst)[source]¶ Task generator method
Task generator method provided to convert a list of string/nodes into a list of includes folders.
The paths are assumed to be relative to the task generator path, except if they begin by # in which case they are searched from the top-level directory (
bld.srcnode
). The folders are simply assumed to be existing.The node objects in the list are returned in the output list. The strings are converted into node objects if possible. The node is searched from the source directory, and if a match is found, the equivalent build directory is created and added to the returned list too. When a folder cannot be found, it is ignored.
Parameters: inlst (space-delimited string or a list of string/nodes) – list of folders Return type: list of waflib.Node.Node
Returns: list of include folders as nodes
-
waflib.Tools.ccroot.
apply_incpaths
(self)[source]¶ Task generator method
Task generator method that processes the attribute includes:
tg = bld(features='includes', includes='.')
The folders only need to be relative to the current directory, the equivalent build directory is added automatically (for headers created in the build directory). This enables using a build directory or not (
top == out
).This method will add a list of nodes read by
waflib.Tools.ccroot.to_incnodes()
intg.env.INCPATHS
, and the list of include paths intg.env.INCLUDES
.Feature: c, cxx, d, asm, fc, includes
-
class
waflib.Tools.ccroot.
link_task
(*k, **kw)[source]¶ Bases:
waflib.Task.Task
Base class for all link tasks. A task generator is supposed to have at most one link task bound in the attribute link_task. See
waflib.Tools.ccroot.apply_link()
.-
color
= 'YELLOW'¶
-
weight
= 3¶ Try to process link tasks as early as possible
-
inst_to
= None¶ Default installation path for the link task outputs, or None to disable
-
chmod
= 493¶ Default installation mode for the link task outputs
-
add_target
(target)[source]¶ Process the target attribute to add the platform-specific prefix/suffix such as .so or .exe. The settings are retrieved from
env.clsname_PATTERN
-
exec_command
(*k, **kw)[source]¶ Wrapper for
waflib.Context.Context.exec_command()
. This version set the current working directory (build.variant_dir
), applies PATH settings (if self.env.PATH is provided), and can run long commands through a temporary@argfile
.Parameters: cmd (list of string (best) or string (process will use a shell)) – process command to execute Returns: the return code Return type: int Optional parameters:
- cwd: current working directory (Node or string)
- stdout: set to None to prevent waf from capturing the process standard output
- stderr: set to None to prevent waf from capturing the process standard error
- timeout: timeout value (Python 3)
-
-
class
waflib.Tools.ccroot.
stlink_task
(*k, **kw)[source]¶ Bases:
waflib.Tools.ccroot.link_task
Base for static link tasks, which use ar most of the time. The target is always removed before being written.
-
chmod
= 420¶ Default installation mode for the static libraries
-
hcode
= b'${AR} ${ARFLAGS} ${AR_TGT_F}${TGT} ${AR_SRC_F}${SRC}'¶
-
orig_run_str
= '${AR} ${ARFLAGS} ${AR_TGT_F}${TGT} ${AR_SRC_F}${SRC}'¶
-
vars
= ['AR', 'ARFLAGS', 'AR_SRC_F', 'AR_TGT_F']¶
-
-
waflib.Tools.ccroot.
apply_skip_stlib_link_deps
(self)[source]¶ Task generator method
This enables an optimization in the :py:func:wafilb.Tools.ccroot.processes_use: method that skips dependency and link flag optimizations for targets that generate static libraries (via the :py:class:Tools.ccroot.stlink_task task). The actual behavior is implemented in :py:func:wafilb.Tools.ccroot.processes_use: method so this feature only tells waf to enable the new behavior.
Feature: skip_stlib_link_deps
-
waflib.Tools.ccroot.
apply_link
(self)[source]¶ Task generator method
Collect the tasks stored in
compiled_tasks
(created bywaflib.Tools.ccroot.create_compiled_task()
), and use the outputs for a new instance ofwaflib.Tools.ccroot.link_task
. The class to use is the first link task matching a name from the attribute features, for example:def build(bld): tg = bld(features='cxx cxxprogram cprogram', source='main.c', target='app')
will create the task
tg.link_task
as a new instance ofwaflib.Tools.cxx.cxxprogram
Feature: c, cxx, d, fc, asm
-
waflib.Tools.ccroot.
use_rec
(self, name, **kw)[source]¶ Task generator method
Processes the
use
keyword recursively. This method is kind of private and only meant to be used fromprocess_use
-
waflib.Tools.ccroot.
process_use
(self)[source]¶ Task generator method
Process the
use
attribute which contains a list of task generator names:def build(bld): bld.shlib(source='a.c', target='lib1') bld.program(source='main.c', target='app', use='lib1')
See
waflib.Tools.ccroot.use_rec()
.Feature: c, cxx, d, use, fc
-
waflib.Tools.ccroot.
accept_node_to_link
(self, node)[source]¶ Task generator method
PRIVATE INTERNAL USE ONLY
-
waflib.Tools.ccroot.
add_objects_from_tgen
(self, tg)[source]¶ Task generator method
Add the objects from the depending compiled tasks as link task inputs.
Some objects are filtered: for instance, .pdb files are added to the compiled tasks but not to the link tasks (to avoid errors) PRIVATE INTERNAL USE ONLY
-
waflib.Tools.ccroot.
get_uselib_vars
(self)[source]¶ Task generator method
Returns: the uselib variables associated to the features attribute (see waflib.Tools.ccroot.USELIB_VARS
)Return type: list of string
-
waflib.Tools.ccroot.
propagate_uselib_vars
(self)[source]¶ Task generator method
Process uselib variables for adding flags. For example, the following target:
def build(bld): bld.env.AFLAGS_aaa = ['bar'] from waflib.Tools.ccroot import USELIB_VARS USELIB_VARS['aaa'] = ['AFLAGS'] tg = bld(features='aaa', aflags='test')
The aflags attribute will be processed and this method will set:
tg.env.AFLAGS = ['bar', 'test']
Feature: c, cxx, d, fc, javac, cs, uselib, asm
-
waflib.Tools.ccroot.
apply_implib
(self)[source]¶ Task generator method
Handle dlls and their import libs on Windows-like systems.
A
.dll.a
file called import library is generated. It must be installed as it is required for linking the library.Feature: cshlib, cxxshlib, fcshlib
-
waflib.Tools.ccroot.
apply_vnum
(self)[source]¶ Task generator method
Enforce version numbering on shared libraries. The valid version numbers must have either zero or two dots:
def build(bld): bld.shlib(source='a.c', target='foo', vnum='14.15.16')
In this example on Linux platform,
libfoo.so
is installed aslibfoo.so.14.15.16
, and the following symbolic links are created:libfoo.so → libfoo.so.14.15.16
libfoo.so.14 → libfoo.so.14.15.16
By default, the library will be assigned SONAME
libfoo.so.14
, effectively declaring ABI compatibility between all minor and patch releases for the major version of the library. When necessary, the compatibility can be explicitly defined using cnum parameter:- def build(bld):
- bld.shlib(source=’a.c’, target=’foo’, vnum=‘14.15.16’, cnum=‘14.15’)
In this case, the assigned SONAME will be
libfoo.so.14.15
with ABI compatibility only between path releases for a specific major and minor version of the library.On OS X platform, install-name parameter will follow the above logic for SONAME with exception that it also specifies an absolute path (based on install_path) of the library.
Feature: cshlib, cxxshlib, dshlib, fcshlib, vnum
-
class
waflib.Tools.ccroot.
vnum
(*k, **kw)[source]¶ Bases:
waflib.Task.Task
Create the symbolic links for a versioned shared library. Instances are created by
waflib.Tools.ccroot.apply_vnum()
-
color
= 'CYAN'¶
-
ext_in
= ['.bin']¶
-
hcode
= b'\tdef run(self):\n\t\tfor x in self.outputs:\n\t\t\tpath = x.abspath()\n\t\t\ttry:\n\t\t\t\tos.remove(path)\n\t\t\texcept OSError:\n\t\t\t\tpass\n\n\t\t\ttry:\n\t\t\t\tos.symlink(self.inputs[0].name, path)\n\t\t\texcept OSError:\n\t\t\t\treturn 1\n'¶
-
-
class
waflib.Tools.ccroot.
fake_shlib
(*k, **kw)[source]¶ Bases:
waflib.Tools.ccroot.link_task
Task used for reading a system library and adding the dependency on it
-
runnable_status
()[source]¶ Returns the Task status
Returns: a task state in waflib.Task.RUN_ME
,waflib.Task.SKIP_ME
,waflib.Task.CANCEL_ME
orwaflib.Task.ASK_LATER
.Return type: int
-
-
class
waflib.Tools.ccroot.
fake_stlib
(*k, **kw)[source]¶ Bases:
waflib.Tools.ccroot.stlink_task
Task used for reading a system library and adding the dependency on it
-
runnable_status
()[source]¶ Returns the Task status
Returns: a task state in waflib.Task.RUN_ME
,waflib.Task.SKIP_ME
,waflib.Task.CANCEL_ME
orwaflib.Task.ASK_LATER
.Return type: int
-
hcode
= b'\tdef wrap(self):\n\t\ttry:\n\t\t\tos.remove(self.outputs[0].abspath())\n\t\texcept OSError:\n\t\t\tpass\n\t\treturn old(self)\n'¶
-
-
waflib.Tools.ccroot.
read_shlib
(self, name, paths=[], export_includes=[], export_defines=[])[source]¶ Configuration Method bound to
waflib.Configure.ConfigurationContext
Read a system shared library, enabling its use as a local library. Will trigger a rebuild if the file changes:
def build(bld): bld.read_shlib('m') bld.program(source='main.c', use='m')
-
waflib.Tools.ccroot.
read_stlib
(self, name, paths=[], export_includes=[], export_defines=[])[source]¶ Configuration Method bound to
waflib.Configure.ConfigurationContext
Read a system static library, enabling a use as a local library. Will trigger a rebuild if the file changes.
-
waflib.Tools.ccroot.
process_lib
(self)[source]¶ Task generator method
Find the location of a foreign library. Used by
waflib.Tools.ccroot.read_shlib
andwaflib.Tools.ccroot.read_stlib
.Feature: fake_lib
-
class
waflib.Tools.ccroot.
fake_o
(*k, **kw)[source]¶ Bases:
waflib.Task.Task
-
runnable_status
()[source]¶ Returns the Task status
Returns: a task state in waflib.Task.RUN_ME
,waflib.Task.SKIP_ME
,waflib.Task.CANCEL_ME
orwaflib.Task.ASK_LATER
.Return type: int
-
-
waflib.Tools.ccroot.
after_method
(*k)[source]¶ Decorator that registers a task generator method which will be executed after the functions of given name(s):
from waflib.TaskGen import feature, after @feature('myfeature') @after_method('fun2') def fun1(self): print('feature 1!') @feature('myfeature') def fun2(self): print('feature 2!') def build(bld): bld(features='myfeature')
Parameters: k (list of string) – method names
-
waflib.Tools.ccroot.
before_method
(*k)[source]¶ Decorator that registera task generator method which will be executed before the functions of given name(s):
from waflib.TaskGen import feature, before @feature('myfeature') @before_method('fun2') def fun1(self): print('feature 1!') @feature('myfeature') def fun2(self): print('feature 2!') def build(bld): bld(features='myfeature')
Parameters: k (list of string) – method names
-
waflib.Tools.ccroot.
feature
(*k)¶ Decorator that registers a task generator method that will be executed when the object attribute
feature
contains the corresponding key(s):from waflib.Task import feature @feature('myfeature') def myfunction(self): print('that is my feature!') def build(bld): bld(features='myfeature')
Parameters: k (list of string) – feature names
-
waflib.Tools.ccroot.
taskgen_method
(func)¶ Decorator that registers method as a task generator method. The function must accept a task generator as first parameter:
from waflib.TaskGen import taskgen_method @taskgen_method def mymethod(self): pass
Parameters: func (function) – task generator method to add Return type: function
-
waflib.Tools.ccroot.
extension
(*k)¶ Decorator that registers a task generator method which will be invoked during the processing of source files for the extension given:
from waflib import Task class mytask(Task): run_str = 'cp ${SRC} ${TGT}' @extension('.moo') def create_maa_file(self, node): self.create_task('mytask', node, node.change_ext('.maa')) def build(bld): bld(source='foo.moo')
-
waflib.Tools.ccroot.
conf
(f)¶ Decorator: attach new configuration functions to
waflib.Build.BuildContext
andwaflib.Configure.ConfigurationContext
. The methods bound will accept a parameter named ‘mandatory’ to disable the configuration errors:def configure(conf): conf.find_program('abc', mandatory=False)
Parameters: f (function) – method to bind
-
waflib.Tools.ccroot.
process_objs
(self)[source]¶ Task generator method
Puts object files in the task generator outputs
Feature: fake_obj
-
waflib.Tools.ccroot.
read_object
(self, obj)[source]¶ Configuration Method bound to
waflib.Configure.ConfigurationContext
Read an object file, enabling injection in libs/programs. Will trigger a rebuild if the file changes.
Parameters: obj – object file path, as string or Node
-
waflib.Tools.ccroot.
set_full_paths_hpux
(self)[source]¶ Task generator method
On hp-ux, extend the libpaths and static library paths to absolute paths
Feature: cxxprogram, cprogram
Features defined in this module: