summaryrefslogtreecommitdiff
path: root/doc/user/builders-writing.xml
diff options
context:
space:
mode:
Diffstat (limited to 'doc/user/builders-writing.xml')
-rw-r--r--doc/user/builders-writing.xml362
1 files changed, 181 insertions, 181 deletions
diff --git a/doc/user/builders-writing.xml b/doc/user/builders-writing.xml
index 2dea8f7c..e6e2aaf2 100644
--- a/doc/user/builders-writing.xml
+++ b/doc/user/builders-writing.xml
@@ -151,7 +151,7 @@ This functionality could be invoked as in the following example:
</para>
<programlisting>
- bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET')
+bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET')
</programlisting>
<para>
@@ -187,23 +187,23 @@ This functionality could be invoked as in the following example:
<scons_example name="builderswriting_ex1">
<file name="SConstruct">
- bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET')
- env = Environment(BUILDERS = {'Foo' : bld})
- import os
- env['ENV']['PATH'] = env['ENV']['PATH'] + os.pathsep + os.getcwd()
- env.Foo('file.foo', 'file.input')
+bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET')
+env = Environment(BUILDERS = {'Foo' : bld})
+import os
+env['ENV']['PATH'] = env['ENV']['PATH'] + os.pathsep + os.getcwd()
+env.Foo('file.foo', 'file.input')
</file>
<file name="file.input">
- file.input
+file.input
</file>
<file name="foobuild" chmod="0755">
- cat
+cat
</file>
</scons_example>
<sconstruct>
- bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET')
- env = Environment(BUILDERS = {'Foo' : bld})
+bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET')
+env = Environment(BUILDERS = {'Foo' : bld})
</sconstruct>
<para>
@@ -215,7 +215,7 @@ This functionality could be invoked as in the following example:
</para>
<programlisting>
- env.Foo('file.foo', 'file.input')
+env.Foo('file.foo', 'file.input')
</programlisting>
<para>
@@ -261,22 +261,22 @@ This functionality could be invoked as in the following example:
-->
<scons_example name="builderswriting_ex2">
<file name="SConstruct">
- import SCons.Defaults; SCons.Defaults.ConstructionEnvironment['TOOLS'] = {}; bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET')
- env = Environment(BUILDERS = {'Foo' : bld})
- env.Foo('file.foo', 'file.input')
- env.Program('hello.c')
+import SCons.Defaults; SCons.Defaults.ConstructionEnvironment['TOOLS'] = {}; bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET')
+env = Environment(BUILDERS = {'Foo' : bld})
+env.Foo('file.foo', 'file.input')
+env.Program('hello.c')
</file>
<file name="SConstruct.printme" printme="1">
- bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET')
- env = Environment(BUILDERS = {'Foo' : bld})
- env.Foo('file.foo', 'file.input')
- env.Program('hello.c')
+bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET')
+env = Environment(BUILDERS = {'Foo' : bld})
+env.Foo('file.foo', 'file.input')
+env.Program('hello.c')
</file>
<file name="file.input">
- file.input
+file.input
</file>
<file name="hello.c">
- hello.c
+hello.c
</file>
</scons_example>
@@ -295,31 +295,31 @@ This functionality could be invoked as in the following example:
<scons_example name="builderswriting_ex3">
<file name="SConstruct">
- env = Environment()
- import os
- env['ENV']['PATH'] = env['ENV']['PATH'] + os.pathsep + os.getcwd()
- bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET')
- env.Append(BUILDERS = {'Foo' : bld})
- env.Foo('file.foo', 'file.input')
- env.Program('hello.c')
+env = Environment()
+import os
+env['ENV']['PATH'] = env['ENV']['PATH'] + os.pathsep + os.getcwd()
+bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET')
+env.Append(BUILDERS = {'Foo' : bld})
+env.Foo('file.foo', 'file.input')
+env.Program('hello.c')
</file>
<file name="file.input">
- file.input
+file.input
</file>
<file name="hello.c">
- hello.c
+hello.c
</file>
<file name="foobuild" chmod="0755">
- cat
+cat
</file>
</scons_example>
<sconstruct>
- env = Environment()
- bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET')
- env.Append(BUILDERS = {'Foo' : bld})
- env.Foo('file.foo', 'file.input')
- env.Program('hello.c')
+env = Environment()
+bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET')
+env.Append(BUILDERS = {'Foo' : bld})
+env.Foo('file.foo', 'file.input')
+env.Program('hello.c')
</sconstruct>
<para>
@@ -330,11 +330,11 @@ This functionality could be invoked as in the following example:
</para>
<sconstruct>
- env = Environment()
- bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET')
- env['BUILDERS']['Foo'] = bld
- env.Foo('file.foo', 'file.input')
- env.Program('hello.c')
+env = Environment()
+bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET')
+env['BUILDERS']['Foo'] = bld
+env.Foo('file.foo', 'file.input')
+env.Program('hello.c')
</sconstruct>
<para>
@@ -374,33 +374,33 @@ This functionality could be invoked as in the following example:
<scons_example name="builderswriting_ex4">
<file name="SConstruct">
- bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET',
- suffix = '.foo',
- src_suffix = '.input')
- env = Environment(BUILDERS = {'Foo' : bld})
- import os
- env['ENV']['PATH'] = env['ENV']['PATH'] + os.pathsep + os.getcwd()
- env.Foo('file1')
- env.Foo('file2')
+bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET',
+ suffix = '.foo',
+ src_suffix = '.input')
+env = Environment(BUILDERS = {'Foo' : bld})
+import os
+env['ENV']['PATH'] = env['ENV']['PATH'] + os.pathsep + os.getcwd()
+env.Foo('file1')
+env.Foo('file2')
</file>
<file name="file1.input">
- file1.input
+file1.input
</file>
<file name="file2.input">
- file2.input
+file2.input
</file>
<file name="foobuild" chmod="0755">
- cat
+cat
</file>
</scons_example>
<sconstruct>
- bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET',
- suffix = '.foo',
- src_suffix = '.input')
- env = Environment(BUILDERS = {'Foo' : bld})
- env.Foo('file1')
- env.Foo('file2')
+bld = Builder(action = 'foobuild &lt; $SOURCE &gt; $TARGET',
+ suffix = '.foo',
+ src_suffix = '.input')
+env = Environment(BUILDERS = {'Foo' : bld})
+env.Foo('file1')
+env.Foo('file2')
</sconstruct>
<scons_output example="builderswriting_ex4" suffix="1">
@@ -432,9 +432,9 @@ This functionality could be invoked as in the following example:
</para>
<programlisting>
- def build_function(target, source, env):
- # Code to build "target" from "source"
- return None
+def build_function(target, source, env):
+ # Code to build "target" from "source"
+ return None
</programlisting>
<para>
@@ -521,17 +521,17 @@ This functionality could be invoked as in the following example:
<scons_example name="builderswriting_ex5">
<file name="SConstruct" printme="1">
- def build_function(target, source, env):
- # Code to build "target" from "source"
- return None
- bld = Builder(action = build_function,
- suffix = '.foo',
- src_suffix = '.input')
- env = Environment(BUILDERS = {'Foo' : bld})
- env.Foo('file')
+def build_function(target, source, env):
+ # Code to build "target" from "source"
+ return None
+bld = Builder(action = build_function,
+ suffix = '.foo',
+ src_suffix = '.input')
+env = Environment(BUILDERS = {'Foo' : bld})
+env.Foo('file')
</file>
<file name="file.input">
- file.input
+file.input
</file>
</scons_example>
@@ -565,8 +565,8 @@ This functionality could be invoked as in the following example:
</para>
<programlisting>
- def generate_actions(source, target, env, for_signature):
- return 'foobuild &lt; %s &gt; %s' % (target[0], source[0])
+def generate_actions(source, target, env, for_signature):
+ return 'foobuild &lt; %s &gt; %s' % (target[0], source[0])
</programlisting>
<para>
@@ -668,32 +668,32 @@ This functionality could be invoked as in the following example:
<scons_example name="builderswriting_ex6">
<file name="SConstruct">
- def generate_actions(source, target, env, for_signature):
- return 'foobuild &lt; %s &gt; %s' % (source[0], target[0])
- bld = Builder(generator = generate_actions,
- suffix = '.foo',
- src_suffix = '.input')
- env = Environment(BUILDERS = {'Foo' : bld})
- import os
- env['ENV']['PATH'] = env['ENV']['PATH'] + os.pathsep + os.getcwd()
- env.Foo('file')
+def generate_actions(source, target, env, for_signature):
+ return 'foobuild &lt; %s &gt; %s' % (source[0], target[0])
+bld = Builder(generator = generate_actions,
+ suffix = '.foo',
+ src_suffix = '.input')
+env = Environment(BUILDERS = {'Foo' : bld})
+import os
+env['ENV']['PATH'] = env['ENV']['PATH'] + os.pathsep + os.getcwd()
+env.Foo('file')
</file>
<file name="file.input">
- file.input
+file.input
</file>
<file name="foobuild" chmod="0755">
- cat
+cat
</file>
</scons_example>
<sconstruct>
- def generate_actions(source, target, env, for_signature):
- return 'foobuild &lt; %s &gt; %s' % (source[0], target[0])
- bld = Builder(generator = generate_actions,
- suffix = '.foo',
- src_suffix = '.input')
- env = Environment(BUILDERS = {'Foo' : bld})
- env.Foo('file')
+def generate_actions(source, target, env, for_signature):
+ return 'foobuild &lt; %s &gt; %s' % (source[0], target[0])
+bld = Builder(generator = generate_actions,
+ suffix = '.foo',
+ src_suffix = '.input')
+env = Environment(BUILDERS = {'Foo' : bld})
+env.Foo('file')
</sconstruct>
<scons_output example="builderswriting_ex6" suffix="1">
@@ -746,41 +746,41 @@ This functionality could be invoked as in the following example:
<scons_example name="builderswriting_ex7">
<file name="SConstruct">
- def modify_targets(target, source, env):
- target.append('new_target')
- source.append('new_source')
- return target, source
- bld = Builder(action = 'foobuild $TARGETS - $SOURCES',
- suffix = '.foo',
- src_suffix = '.input',
- emitter = modify_targets)
- env = Environment(BUILDERS = {'Foo' : bld})
- import os
- env['ENV']['PATH'] = env['ENV']['PATH'] + os.pathsep + os.getcwd()
- env.Foo('file')
+def modify_targets(target, source, env):
+ target.append('new_target')
+ source.append('new_source')
+ return target, source
+bld = Builder(action = 'foobuild $TARGETS - $SOURCES',
+ suffix = '.foo',
+ src_suffix = '.input',
+ emitter = modify_targets)
+env = Environment(BUILDERS = {'Foo' : bld})
+import os
+env['ENV']['PATH'] = env['ENV']['PATH'] + os.pathsep + os.getcwd()
+env.Foo('file')
</file>
<file name="file.input">
- file.input
+file.input
</file>
<file name="new_source">
- new_source
+new_source
</file>
<file name="foobuild" chmod="0755">
- cat
+cat
</file>
</scons_example>
<sconstruct>
- def modify_targets(target, source, env):
- target.append('new_target')
- source.append('new_source')
- return target, source
- bld = Builder(action = 'foobuild $TARGETS - $SOURCES',
- suffix = '.foo',
- src_suffix = '.input',
- emitter = modify_targets)
- env = Environment(BUILDERS = {'Foo' : bld})
- env.Foo('file')
+def modify_targets(target, source, env):
+ target.append('new_target')
+ source.append('new_source')
+ return target, source
+bld = Builder(action = 'foobuild $TARGETS - $SOURCES',
+ suffix = '.foo',
+ src_suffix = '.input',
+ emitter = modify_targets)
+env = Environment(BUILDERS = {'Foo' : bld})
+env.Foo('file')
</sconstruct>
<para>
@@ -812,57 +812,57 @@ This functionality could be invoked as in the following example:
<scons_example name="builderswriting_MY_EMITTER">
<file name="SConstruct" printme="1">
- bld = Builder(action = 'my_command $SOURCES &gt; $TARGET',
- suffix = '.foo',
- src_suffix = '.input',
- emitter = '$MY_EMITTER')
- def modify1(target, source, env):
- return target, source + ['modify1.in']
- def modify2(target, source, env):
- return target, source + ['modify2.in']
- env1 = Environment(BUILDERS = {'Foo' : bld},
- MY_EMITTER = modify1)
- env2 = Environment(BUILDERS = {'Foo' : bld},
- MY_EMITTER = modify2)
- env1.Foo('file1')
- env2.Foo('file2')
- import os
- env1['ENV']['PATH'] = env2['ENV']['PATH'] + os.pathsep + os.getcwd()
- env2['ENV']['PATH'] = env2['ENV']['PATH'] + os.pathsep + os.getcwd()
+bld = Builder(action = 'my_command $SOURCES &gt; $TARGET',
+ suffix = '.foo',
+ src_suffix = '.input',
+ emitter = '$MY_EMITTER')
+def modify1(target, source, env):
+ return target, source + ['modify1.in']
+def modify2(target, source, env):
+ return target, source + ['modify2.in']
+env1 = Environment(BUILDERS = {'Foo' : bld},
+ MY_EMITTER = modify1)
+env2 = Environment(BUILDERS = {'Foo' : bld},
+ MY_EMITTER = modify2)
+env1.Foo('file1')
+env2.Foo('file2')
+import os
+env1['ENV']['PATH'] = env2['ENV']['PATH'] + os.pathsep + os.getcwd()
+env2['ENV']['PATH'] = env2['ENV']['PATH'] + os.pathsep + os.getcwd()
</file>
<file name="file1.input">
- file1.input
+file1.input
</file>
<file name="file2.input">
- file2.input
+file2.input
</file>
<file name="modify1.in">
- modify1.input
+modify1.input
</file>
<file name="modify2.in">
- modify2.input
+modify2.input
</file>
<file name="my_command" chmod="0755">
- cat
+cat
</file>
</scons_example>
<sconstruct>
- bld = Builder(action = 'my_command $SOURCES &gt; $TARGET',
- suffix = '.foo',
- src_suffix = '.input',
- emitter = '$MY_EMITTER')
- def modify1(target, source, env):
- return target, source + ['modify1.in']
- def modify2(target, source, env):
- return target, source + ['modify2.in']
- env1 = Environment(BUILDERS = {'Foo' : bld},
- MY_EMITTER = modify1)
- env2 = Environment(BUILDERS = {'Foo' : bld},
- MY_EMITTER = modify2)
- env1.Foo('file1')
- env2.Foo('file2')
+bld = Builder(action = 'my_command $SOURCES &gt; $TARGET',
+ suffix = '.foo',
+ src_suffix = '.input',
+ emitter = '$MY_EMITTER')
+def modify1(target, source, env):
+ return target, source + ['modify1.in']
+def modify2(target, source, env):
+ return target, source + ['modify2.in']
+env1 = Environment(BUILDERS = {'Foo' : bld},
+ MY_EMITTER = modify1)
+env2 = Environment(BUILDERS = {'Foo' : bld},
+ MY_EMITTER = modify2)
+env1.Foo('file1')
+env2.Foo('file2')
</sconstruct>
<para>
@@ -962,19 +962,19 @@ This functionality could be invoked as in the following example:
<scons_example name="builderswriting_site1">
<file name="site_scons/site_init.py" printme="1">
- def TOOL_ADD_HEADER(env):
- """A Tool to add a header from $HEADER to the source file"""
- add_header = Builder(action=['echo "$HEADER" &gt; $TARGET',
- 'cat $SOURCE &gt;&gt; $TARGET'])
- env.Append(BUILDERS = {'AddHeader' : add_header})
- env['HEADER'] = '' # set default value
+def TOOL_ADD_HEADER(env):
+ """A Tool to add a header from $HEADER to the source file"""
+ add_header = Builder(action=['echo "$HEADER" &gt; $TARGET',
+ 'cat $SOURCE &gt;&gt; $TARGET'])
+ env.Append(BUILDERS = {'AddHeader' : add_header})
+ env['HEADER'] = '' # set default value
</file>
<file name="SConstruct">
- env=Environment(tools=['default', TOOL_ADD_HEADER], HEADER="=====")
- env.AddHeader('tgt', 'src')
+env=Environment(tools=['default', TOOL_ADD_HEADER], HEADER="=====")
+env.AddHeader('tgt', 'src')
</file>
<file name="src">
- hi there
+hi there
</file>
</scons_example>
@@ -985,9 +985,9 @@ This functionality could be invoked as in the following example:
</para>
<sconstruct>
- # Use TOOL_ADD_HEADER from site_scons/site_init.py
- env=Environment(tools=['default', TOOL_ADD_HEADER], HEADER="=====")
- env.AddHeader('tgt', 'src')
+# Use TOOL_ADD_HEADER from site_scons/site_init.py
+env=Environment(tools=['default', TOOL_ADD_HEADER], HEADER="=====")
+env.AddHeader('tgt', 'src')
</sconstruct>
<para>
@@ -1036,18 +1036,18 @@ This functionality could be invoked as in the following example:
<scons_example name="builderswriting_site2">
<file name="site_scons/my_utils.py" printme="1">
- from SCons.Script import * # for Execute and Mkdir
- def build_id():
- """Return a build ID (stub version)"""
- return "100"
- def MakeWorkDir(workdir):
- """Create the specified dir immediately"""
- Execute(Mkdir(workdir))
+from SCons.Script import * # for Execute and Mkdir
+def build_id():
+ """Return a build ID (stub version)"""
+ return "100"
+def MakeWorkDir(workdir):
+ """Create the specified dir immediately"""
+ Execute(Mkdir(workdir))
</file>
<file name="SConscript">
- import my_utils
- MakeWorkDir('/tmp/work')
- print "build_id=" + my_utils.build_id()
+import my_utils
+MakeWorkDir('/tmp/work')
+print "build_id=" + my_utils.build_id()
</file>
</scons_example>
@@ -1059,9 +1059,9 @@ This functionality could be invoked as in the following example:
</para>
<sconstruct>
- import my_utils
- print "build_id=" + my_utils.build_id()
- my_utils.MakeWorkDir('/tmp/work')
+import my_utils
+print "build_id=" + my_utils.build_id()
+my_utils.MakeWorkDir('/tmp/work')
</sconstruct>
<para>
@@ -1074,7 +1074,7 @@ This functionality could be invoked as in the following example:
than a &SConstruct; or &SConscript; you always need to do
</para>
<sconstruct>
- from SCons.Script import *
+from SCons.Script import *
</sconstruct>
<para>
@@ -1112,12 +1112,12 @@ This functionality could be invoked as in the following example:
<scons_example name="builderswriting_ex8">
<file name="SConstruct" printme="1">
- env = Environment()
- #env.SourceCode('.', env.BitKeeper('my_command'))
- env.Program('hello.c')
+env = Environment()
+#env.SourceCode('.', env.BitKeeper('my_command'))
+env.Program('hello.c')
</file>
<file name="hello.c">
- hello.c
+hello.c
</file>
</scons_example>