This commit is contained in:
Thomas Nagy 2012-03-30 20:58:26 +02:00
parent ece194056d
commit 1da03523ed
4 changed files with 27 additions and 27 deletions

View File

@ -86,7 +86,7 @@ NOTE: The build commands are using this system: _waf install_ → _waflib.Build.
==== Command composition
To re-use existing commands that have incompatible context classes, insert them in the _command stack_:
To re-use commands that have context object of different base classes, insert them in the _command stack_:
// advbuild_composition
[source,python]
@ -133,7 +133,7 @@ def test(ctx):
Options.commands = lst + Options.commands
---------------
<1> To share data between different commands, use a global variable
<1> A global variable may be used to share data between commands deriving from different classes
<2> The test command is used to add more commands
The following output will be observed:
@ -162,7 +162,7 @@ Waf: Leaving directory `/tmp/advbuild_testcase/build'
==== Binding a command from a Waf tool
When the top-level wscript is read, it is converted into a python module and kept in memory. Commands may be added dynamically by injecting the desired function into that module. We will now show how to load a waf tool to count the amount of task generators in the project.
When the top-level wscript is read, it is converted into a python module and kept in memory. Commands may be added dynamically by injecting the desired function into that module. We will now show how to bind a simple command from a Waf tool:
// advbuild_cmdtool
[source,python]
@ -183,13 +183,16 @@ Waf tools are loaded once for the configuration and for the build. To ensure tha
---------------
from waflib import Context
def cnt(ctx):
def cnt(ctx): <1>
"""do something"""
print('just a test')
Context.g_module.__dict__['cnt'] = cnt
Context.g_module.__dict__['cnt'] = cnt <2>
---------------
<1> The function to bind must accept a `Context` object as first argument
<2> The main wscript file of the project is loaded as a python module and stored as `Context.g_module`
The execution output will be the following.
[source,shishell]

View File

@ -6,7 +6,7 @@ Due to the amount of features provided by Waf, this book cannot be both complete
[options="header"]
|================
|Link|Description
|http://docs.waf.googlecode.com/git/apidocs_16/index.html|The apidocs
|http://docs.waf.googlecode.com/git/apidocs_17/index.html|The apidocs
|http://code.google.com/p/waf|The Waf project page
|http://code.google.com/p/waf/w/list|The Waf wiki, including the frequently asked questions (FAQ)
|http://groups.google.com/group/waf-users|The Waf mailing-list

View File

@ -182,7 +182,7 @@ def configure(ctx):
ctx.find_file('fstab', ['/opt', '/etc'])
---------------
Although these methods are provided by the context class _waflib.Configure.ConfigurationContext_, they will not appear on it in http://docs.waf.googlecode.com/git/apidocs_16/index.html[API documentation]. For modularity reasons, they are defined as simple functions and then bound dynamically:
Although these methods are provided by the context class _waflib.Configure.ConfigurationContext_, they will not appear on it in http://docs.waf.googlecode.com/git/apidocs_17/index.html[API documentation]. For modularity reasons, they are defined as simple functions and then bound dynamically:
[source,python]
---------------

View File

@ -143,7 +143,7 @@ some text
['.lock-wafbuild', 'foo.txt', 'build', 'wscript', '.git']
---------------
NOTE: More methods may be found in the http://docs.waf.googlecode.com/git/apidocs_16/index.html[API documentation]
NOTE: More methods may be found in the http://docs.waf.googlecode.com/git/apidocs_17/index.html[API documentation]
WARNING: These methods are not safe for concurrent access. The node class methods are not meant to be thread-safe.
@ -200,7 +200,7 @@ ctx.path.parent.ant_glob('wscript') <2>
==== Path manipulation: abspath, path_from
The method 'abspath' is used to obtain the absolute path for a node. In the following example, three nodes are used:
The following example illustrates a few ways of obtaining absolute and relative paths:
[source,python]
---------------
@ -215,17 +215,19 @@ def build(ctx):
src = ctx.path.find_resource('wscript')
bld = ctx.path.find_or_declare('out.out')
print(src.abspath(ctx.env)) <2>
print(bld.abspath(ctx.env))
print(dir.abspath(ctx.env)) <3>
print(src.abspath()) <2>
print(bld.abspath())
print(dir.abspath())
print(src.path_from(dir.parent)) <3>
print(ctx.root.path_from(src)) <4>
---------------
<1> Directory node, source node and build node
<2> Computing the absolute path for source node or a build node takes a configuration set as parameter
<3> Computing the absolute path for a directory may use a configuration set or not
<2> Print the absolute path
<3> Compute the path relative to another node
<4> Compute the relative path in reverse order
Here is the execution trace:
Here is the execution trace on a unix-like system:
[source,shishell]
---------------
@ -233,21 +235,16 @@ $ waf distclean configure build
'distclean' finished successfully (0.002s)
'configure' finished successfully (0.005s)
Waf: Entering directory `/tmp/nested/build'
/tmp/nested/wscript <1>
/tmp/nested/build/out.out <2>
/tmp/nested/build/ <3>
/tmp/nested <4>
/tmp/nested/wscript
/tmp/nested/build/out.out
/tmp/nested/build/
/tmp/nested
nested/wscript
../../../..
Waf: Leaving directory `/tmp/nested/build'
'build' finished successfully (0.003s)
---------------
<1> Absolute path for the source node
<2> The absolute path for the build node depends on the variant in use
<3> When a configuration set is provided, the absolute path for a directory node is the build directory representation including the variant
<4> When no configuration set is provided, the directory node absolute path is the one for the source directory
NOTE: Several other methods such as 'relpath_gen' or 'srcpath' are provided. See the http://docs.waf.googlecode.com/git/apidocs_16/index.html[API documentation]
=== BuildContext-specific methods
==== Source and build nodes
@ -310,7 +307,7 @@ def build(bld):
As seen in the previous chapter, Task objects can process files represented as lists of input and output nodes. The task generators
will usually process the input files given as strings to obtain such nodes and bind them to the tasks.
Since the build directory can be enabled or disabled, the following file copy is invalid: footnote:[When file copies cannot be avoided, the best practice is to change the file names]
Because the build directory can be enabled or disabled, the following file copy would be ambiguous: footnote:[When file copies cannot be avoided, the best practice is to change the file names]
[source,python]
---------------