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.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.TaskGen 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 and waflib.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.USELIB_VARS = {'asm': {'ASFLAGS'}, 'c': {'ARCH', 'CCDEPS', 'CFLAGS', 'CPPFLAGS', 'DEFINES', 'FLEXFLAGS', 'FRAMEWORKPATH', 'INCLUDES'}, 'cprogram': {'ARCH', 'FRAMEWORK', 'FRAMEWORKPATH', 'LDFLAGS', 'LIB', 'LIBPATH', 'LINKDEPS', 'LINKFLAGS', 'RPATH', 'STLIB', 'STLIBPATH'}, 'cs': {'ASSEMBLIES', 'CSFLAGS', 'RESOURCES'}, 'cshlib': {'ARCH', 'FRAMEWORK', 'FRAMEWORKPATH', 'LDFLAGS', 'LIB', 'LIBPATH', 'LINKDEPS', 'LINKFLAGS', 'RPATH', 'STLIB', 'STLIBPATH'}, 'cstlib': {'ARFLAGS', 'LINKDEPS'}, 'cxx': {'ARCH', 'CPPFLAGS', 'CXXDEPS', 'CXXFLAGS', 'DEFINES', 'FLEXFLAGS', 'FRAMEWORKPATH', 'INCLUDES'}, 'cxxprogram': {'ARCH', 'FRAMEWORK', 'FRAMEWORKPATH', 'LDFLAGS', 'LIB', 'LIBPATH', 'LINKDEPS', 'LINKFLAGS', 'RPATH', 'STLIB', 'STLIBPATH'}, 'cxxshlib': {'ARCH', 'FRAMEWORK', 'FRAMEWORKPATH', 'LDFLAGS', 'LIB', 'LIBPATH', 'LINKDEPS', 'LINKFLAGS', 'RPATH', 'STLIB', 'STLIBPATH'}, 'cxxstlib': {'ARFLAGS', 'LINKDEPS'}, 'd': {'DFLAGS', 'INCLUDES'}, 'dprogram': {'LIB', 'LIBPATH', 'LINKDEPS', 'LINKFLAGS', 'RPATH', 'STLIB', 'STLIBPATH'}, 'dshlib': {'LIB', 'LIBPATH', 'LINKDEPS', 'LINKFLAGS', 'RPATH', 'STLIB', 'STLIBPATH'}, 'dstlib': {'ARFLAGS', 'LINKDEPS'}, 'fc': {'DEFINES', 'FCFLAGS', 'FCPPFLAGS', 'INCLUDES'}, 'fcprogram': {'LDFLAGS', 'LIB', 'LIBPATH', 'LINKDEPS', 'LINKFLAGS', 'RPATH', 'STLIB', 'STLIBPATH'}, 'fcprogram_test': {'LDFLAGS', 'LIB', 'LIBPATH', 'LINKDEPS', 'LINKFLAGS', 'RPATH', 'STLIB', 'STLIBPATH'}, 'fcshlib': {'LDFLAGS', 'LIB', 'LIBPATH', 'LINKDEPS', 'LINKFLAGS', 'RPATH', 'STLIB', 'STLIBPATH'}, 'fcstlib': {'ARFLAGS', 'LINKDEPS'}, 'includes': {'ARCH', 'FRAMEWORKPATH', 'INCLUDES'}, 'javac': {'CLASSPATH', 'JAVACFLAGS'}}

Mapping for features to waflib.ConfigSet.ConfigSet variables. See waflib.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.Task.Task

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() in tg.env.INCPATHS, and the list of include paths in tg.env.INCLUDES.

Feature

c, cxx, d, asm, fc, includes

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

Inheritance diagram of waflib.Tools.ccroot.stlink_task, waflib.Tools.c.cprogram, waflib.Tools.c.cshlib, waflib.Tools.cxx.cxxstlib, waflib.Tools.cxx.cxxprogram, waflib.Tools.cxx.cxxshlib, waflib.Tools.d.dprogram, waflib.Tools.d.dshlib, waflib.Tools.d.dstlib, waflib.Tools.ccroot.fake_shlib, waflib.Tools.ccroot.fake_stlib, waflib.Tools.asm.asmprogram, waflib.Tools.asm.asmshlib, waflib.Tools.asm.asmstlib

Color for the console display, see waflib.Logs.colors_lst

Try to process link tasks as early as possible

Default installation path for the link task outputs, or None to disable

Default installation mode for the link task outputs

Process the target attribute to add the platform-specific prefix/suffix such as .so or .exe. The settings are retrieved from env.clsname_PATTERN

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:

  1. cwd: current working directory (Node or string)

  2. stdout: set to None to prevent waf from capturing the process standard output

  3. stderr: set to None to prevent waf from capturing the process standard error

  4. timeout: timeout value (Python 3)

Create manifest files for VS-like compilers (msvc, ifort, …)

waflib.ConfigSet.ConfigSet object (make sure to provide one)

List of input nodes, which represent the files used by the task instance

List of output nodes, which represent the files created by the task instance

List of additional nodes to depend on

Set of tasks that must be executed before this one

Base for static link tasks, which use ar most of the time. The target is always removed before being written.

Default installation mode for the static libraries

waflib.ConfigSet.ConfigSet object (make sure to provide one)

List of input nodes, which represent the files used by the task instance

List of output nodes, which represent the files created by the task instance

List of additional nodes to depend on

Set of tasks that must be executed before this one

String representing an additional hash for the class representation

ConfigSet variables that should trigger a rebuild (class attribute used for waflib.Task.Task.sig_vars())

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

Task generator method

Collect the tasks stored in compiled_tasks (created by waflib.Tools.ccroot.create_compiled_task()), and use the outputs for a new instance of waflib.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 of waflib.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 from process_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

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 as libfoo.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]

Create the symbolic links for a versioned shared library. Instances are created by waflib.Tools.ccroot.apply_vnum()

color = 'CYAN'

Color for the console display, see waflib.Logs.colors_lst

ext_in = ['.bin']

File extensions that objects of this task class may use

keyword()[source]

Display keyword used to prettify the console outputs

hasrun
generator
env

waflib.ConfigSet.ConfigSet object (make sure to provide one)

inputs

List of input nodes, which represent the files used by the task instance

outputs

List of output nodes, which represent the files created by the task instance

dep_nodes

List of additional nodes to depend on

run_after

Set of tasks that must be executed before this one

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'

String representing an additional hash for the class representation

class waflib.Tools.ccroot.fake_shlib(*k, **kw)[source]

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 or waflib.Task.ASK_LATER.

Return type

int

hasrun
generator
env

waflib.ConfigSet.ConfigSet object (make sure to provide one)

inputs

List of input nodes, which represent the files used by the task instance

outputs

List of output nodes, which represent the files created by the task instance

dep_nodes

List of additional nodes to depend on

run_after

Set of tasks that must be executed before this one

class waflib.Tools.ccroot.fake_stlib(*k, **kw)[source]

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 or waflib.Task.ASK_LATER.

Return type

int

hasrun
generator
env

waflib.ConfigSet.ConfigSet object (make sure to provide one)

inputs

List of input nodes, which represent the files used by the task instance

outputs

List of output nodes, which represent the files created by the task instance

dep_nodes

List of additional nodes to depend on

run_after

Set of tasks that must be executed before this one

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'

String representing an additional hash for the class representation

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 and waflib.Tools.ccroot.read_stlib.

Feature

fake_lib

class waflib.Tools.ccroot.fake_o(*k, **kw)[source]
hasrun
generator
env

waflib.ConfigSet.ConfigSet object (make sure to provide one)

inputs

List of input nodes, which represent the files used by the task instance

outputs

List of output nodes, which represent the files created by the task instance

dep_nodes

List of additional nodes to depend on

run_after

Set of tasks that must be executed before this one

runnable_status()[source]

Returns the Task status

Returns

a task state in waflib.Task.RUN_ME, waflib.Task.SKIP_ME, waflib.Task.CANCEL_ME or waflib.Task.ASK_LATER.

Return type

int

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: