Build

Classes related to the build phase (build, clean, install, step, etc)

The inheritance tree is the following:

waflib.Build.CACHE_DIR

Location of the cache files

waflib.Build.CACHE_SUFFIX

Suffix for the cache files

waflib.Build.INSTALL

Positive value ‘->’ install, see waflib.Build.BuildContext.is_install

waflib.Build.UNINSTALL

Negative value ‘<-‘ uninstall, see waflib.Build.BuildContext.is_install

waflib.Build.SAVED_ATTRS

Build class members to save between the runs (root, node_deps, raw_deps, task_sigs)

waflib.Build.CFG_FILES

Files from the build directory to hash before starting the build (config.h written during the configuration)

waflib.Build.POST_AT_ONCE

Post mode: all task generators are posted before the build really starts

waflib.Build.POST_LAZY

Post mode: post the task generators group after group

waflib.Build.POST_BOTH

Post mode: post the task generators at once, then re-check them for each group

class waflib.Build.BuildContext(**kw)[source]

Bases: waflib.Context.Context

executes the build

is_install

Non-zero value when installing or uninstalling file

post_mode

post the task generators at once, group-by-group, or both

task_sigs

Signatures of the tasks (persists between build executions)

node_deps

Dict of node dependencies found by waflib.Task.Task.scan() (persists between build executions)

raw_deps

Dict of custom data returned by waflib.Task.Task.scan() (persists between build executions)

deps_man

Manual dependencies set by waflib.Build.BuildContext.add_manual_dependency()

current_group

Current build group

groups

List containing lists of task generators

group_names

Map group names to the group lists. See waflib.Build.BuildContext.add_group()

get_variant_dir()[source]

Getter for the variant_dir attribute

variant_dir

Getter for the variant_dir attribute

__call__(*k, **kw)[source]

Create a task generator and add it to the current build group. The following forms are equivalent:

def build(bld):
        tg = bld(a=1, b=2)

def build(bld):
        tg = bld()
        tg.a = 1
        tg.b = 2

def build(bld):
        tg = TaskGen.task_gen(a=1, b=2)
        bld.add_to_group(tg, None)
Parameters:group (string) – group name to add the task generator to
__copy__()[source]

Implemented to prevents copies of build contexts (raises an exception)

install_files(*k, **kw)[source]

Actual implementation provided by waflib.Build.InstallContext.install_files()

install_as(*k, **kw)[source]

Actual implementation provided by waflib.Build.InstallContext.install_as()

Actual implementation provided by waflib.Build.InstallContext.symlink_as()

load_envs()[source]

The configuration command creates files of the form build/c4che/NAMEcache.py. This method creates a waflib.ConfigSet.ConfigSet instance for each NAME by reading those files. The config sets are then stored in the dict waflib.Build.BuildContext.allenvs.

init_dirs()[source]

Initialize the project directory and the build directory by creating the nodes waflib.Build.BuildContext.srcnode and waflib.Build.BuildContext.bldnode corresponding to top_dir and variant_dir respectively. The bldnode directory will be created if it does not exist.

execute()[source]

Restore the data from previous builds and call waflib.Build.BuildContext.execute_build(). Overrides from waflib.Context.Context.execute()

execute_build()[source]

Execute the build by:

restore(*k, **kw)[source]

Load the data from a previous run, sets the attributes listed in waflib.Build.SAVED_ATTRS

store(*k, **kw)[source]

Store the data for next runs, sets the attributes listed in waflib.Build.SAVED_ATTRS. Uses a temporary file to avoid problems on ctrl+c.

compile()[source]

Run the build by creating an instance of waflib.Runner.Parallel The cache file is not written if the build is up to date (no task executed).

setup(tool, tooldir=None, funs=None)[source]

Import waf tools, used to import those accessed during the configuration:

def configure(conf):
        conf.load('glib2')

def build(bld):
        pass # glib2 is imported implicitly
Parameters:
  • tool (list) – tool list
  • tooldir (list of string) – optional tool directory (sys.path)
  • funs – unused variable
get_env()[source]

Getter for the env property

set_env(val)[source]

Setter for the env property

env

Getter for the env property

add_manual_dependency(path, value)[source]

Adds a dependency from a node object to a value:

def build(bld):
        bld.add_manual_dependency(
                bld.path.find_resource('wscript'),
                bld.root.find_resource('/etc/fstab'))
Parameters:
launch_node()[source]

Returns the launch directory as a waflib.Node.Node object

hash_env_vars(env, vars_lst)[source]

Hash configuration set variables:

def build(bld):
        bld.hash_env_vars(bld.env, ['CXX', 'CC'])
Parameters:
get_tgen_by_name(name)[source]

Retrieves a task generator from its name or its target name the name must be unique:

def build(bld):
        tg = bld(name='foo')
        tg == bld.get_tgen_by_name('foo')
progress_line(state, total, col1, col2)[source]

Compute the progress bar used by waf -p

declare_chain(*k, **kw)[source]

Wrapper for waflib.TaskGen.declare_chain() provided for convenience

pre_build()[source]

Execute user-defined methods before the build starts, see waflib.Build.BuildContext.add_pre_fun()

post_build()[source]

Executes the user-defined methods after the build is successful, see waflib.Build.BuildContext.add_post_fun()

add_pre_fun(meth)[source]

Bind a method to execute after the scripts are read and before the build starts:

def mycallback(bld):
        print("Hello, world!")

def build(bld):
        bld.add_pre_fun(mycallback)
add_post_fun(meth)[source]

Bind a method to execute immediately after the build is successful:

def call_ldconfig(bld):
        bld.exec_command('/sbin/ldconfig')

def build(bld):
        if bld.cmd == 'install':
                bld.add_pre_fun(call_ldconfig)
get_group(x)[source]

Get the group x, or return the current group if x is None

Parameters:x (string, int or None) – name or number or None
add_to_group(tgen, group=None)[source]

add a task or a task generator for the build

get_group_name(g)[source]

name for the group g (utility)

get_group_idx(tg)[source]

Index of the group containing the task generator given as argument:

def build(bld):
        tg = bld(name='nada')
        0 == bld.get_group_idx(tg)
Parameters:tg (waflib.TaskGen.task_gen) – Task generator object
add_group(name=None, move=True)[source]

Add a new group of tasks/task generators. By default the new group becomes the default group for new task generators.

Parameters:
  • name (string) – name for this group
  • move (bool) – set the group created as default group (True by default)
set_group(idx)[source]

Set the current group to be idx: now new task generators will be added to this group by default:

def build(bld):
        bld(rule='touch ${TGT}', target='foo.txt')
        bld.add_group() # now the current group is 1
        bld(rule='touch ${TGT}', target='bar.txt')
        bld.set_group(0) # now the current group is 0
        bld(rule='touch ${TGT}', target='truc.txt') # build truc.txt before bar.txt
Parameters:idx (string or int) – group name or group index
total()[source]

Approximate task count: this value may be inaccurate if task generators are posted lazily (see waflib.Build.BuildContext.post_mode). The value waflib.Runner.Parallel.total is updated during the task execution.

get_targets()[source]

Return the task generator corresponding to the ‘targets’ list, used by waflib.Build.BuildContext.get_build_iterator():

$ waf --targets=myprogram,myshlib
post_group()[source]

Post the task generators from the group indexed by self.cur, used by waflib.Build.BuildContext.get_build_iterator()

get_tasks_group(idx)[source]

Return all the tasks for the group of num idx, used by waflib.Build.BuildContext.get_build_iterator()

get_build_iterator()[source]

Creates a generator object that returns lists of tasks executable in parallel (yield)

Returns:tasks which can be executed immediatly
Return type:list of waflib.Task.TaskBase
class waflib.Build.inst(*k, **kw)[source]

Bases: waflib.Task.Task

Special task used for installing files and symlinks, it behaves both like a task
and like a task generator
post()[source]

Same interface as in waflib.TaskGen.task_gen.post()

runnable_status()[source]

Installation tasks are always executed, so this method returns either waflib.Task.ASK_LATER or waflib.Task.RUN_ME.

__str__()[source]

Return an empty string to disable the display

get_install_path(destdir=True)[source]

Installation path obtained from self.dest and prefixed by the destdir. The variables such as ‘${PREFIX}/bin’ are substituted.

exec_install_files()[source]

Predefined method for installing files

exec_install_as()[source]

Predefined method for installing one file with a given name

Predefined method for installing a symlink

class waflib.Build.InstallContext(**kw)[source]

Bases: waflib.Build.BuildContext

installs the targets on the system

do_install(src, tgt, chmod=420)[source]

Copy a file from src to tgt with given file permissions. The actual copy is not performed if the source and target file have the same size and the same timestamps. When the copy occurs, the file is first removed and then copied (prevent stale inodes).

This method is overridden in waflib.Build.UninstallContext.do_install() to remove the file.

Parameters:
  • src (string) – file name as absolute path
  • tgt (string) – file destination, as absolute path
  • chmod (int) – installation mode

Create a symlink from tgt to src.

This method is overridden in waflib.Build.UninstallContext.do_link() to remove the symlink.

Parameters:
  • src (string) – file name as absolute path
  • tgt (string) – file destination, as absolute path
run_task_now(tsk, postpone)[source]

This method is called by waflib.Build.InstallContext.install_files(), waflib.Build.InstallContext.install_as() and waflib.Build.InstallContext.symlink_as() immediately after the installation task is created. Its role is to force the immediate execution if necessary, that is when postpone=False was given.

install_files(dest, files, env=None, chmod=420, relative_trick=False, cwd=None, add=True, postpone=True)[source]

Create a task to install files on the system:

def build(bld):
        bld.install_files('${DATADIR}', self.path.find_resource('wscript'))
Parameters:
  • dest (string) – absolute path of the destination directory
  • files (list of strings or list of nodes) – input files
  • env (Configuration set) – configuration set for performing substitutions in dest
  • relative_trick (bool) – preserve the folder hierarchy when installing whole folders
  • cwd (waflib.Node.Node) – parent node for searching srcfile, when srcfile is not a waflib.Node.Node
  • add (bool) – add the task created to a build group - set False only if the installation task is created after the build has started
  • postpone (bool) – execute the task immediately to perform the installation
install_as(dest, srcfile, env=None, chmod=420, cwd=None, add=True, postpone=True)[source]

Create a task to install a file on the system with a different name:

def build(bld):
        bld.install_as('${PREFIX}/bin', 'myapp', chmod=Utils.O755)
Parameters:
  • dest (string) – absolute path of the destination file
  • srcfile (string or node) – input file
  • cwd (waflib.Node.Node) – parent node for searching srcfile, when srcfile is not a waflib.Node.Node
  • env (Configuration set) – configuration set for performing substitutions in dest
  • add (bool) – add the task created to a build group - set False only if the installation task is created after the build has started
  • postpone (bool) – execute the task immediately to perform the installation

Create a task to install a symlink:

def build(bld):
        bld.symlink_as('${PREFIX}/lib/libfoo.so', 'libfoo.so.1.2.3')
Parameters:
  • dest (string) – absolute path of the symlink
  • src (string) – absolute or relative path of the link
  • env (Configuration set) – configuration set for performing substitutions in dest
  • add (bool) – add the task created to a build group - set False only if the installation task is created after the build has started
  • postpone (bool) – execute the task immediately to perform the installation
class waflib.Build.UninstallContext(**kw)[source]

Bases: waflib.Build.InstallContext

removes the targets installed

do_install(src, tgt, chmod=420)[source]

See waflib.Build.InstallContext.do_install()

See waflib.Build.InstallContext.do_link()

execute()[source]

See waflib.Context.Context.execute()

class waflib.Build.CleanContext(**kw)[source]

Bases: waflib.Build.BuildContext

cleans the project

execute()[source]

See waflib.Context.Context.execute()

clean()[source]

clean the data and some files in the build dir .. well, TODO

class waflib.Build.ListContext(**kw)[source]

Bases: waflib.Build.BuildContext

lists the targets to execute

execute()[source]

See waflib.Context.Context.execute().

class waflib.Build.StepContext(**kw)[source]

Bases: waflib.Build.BuildContext

executes tasks in a step-by-step fashion, for debugging

compile()[source]

Compile the tasks matching the input/output files given (regular expression matching). Derived from waflib.Build.BuildContext.compile():

$ waf step --files=foo.c,bar.c,in:truc.c,out:bar.o
$ waf step --files=in:foo.cpp.1.o # link task only

Previous topic

Feature reference

Next topic

ConfigSet

This Page