5 This file is processed by the bin/SConsDoc.py module.
6 See its __doc__ string for a discussion of the format.
10 <!ENTITY % scons SYSTEM '../../doc/scons.mod'>
12 <!ENTITY % builders-mod SYSTEM '../../doc/generated/builders.mod'>
14 <!ENTITY % functions-mod SYSTEM '../../doc/generated/functions.mod'>
16 <!ENTITY % tools-mod SYSTEM '../../doc/generated/tools.mod'>
18 <!ENTITY % variables-mod SYSTEM '../../doc/generated/variables.mod'>
22 <sconsdoc xmlns="http://www.scons.org/dbxsd/v1.0"
23 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24 xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">
26 <tool name="textfile">
29 Set &consvars; for the &b-Textfile; and &b-Substfile; builders.
33 <item>LINESEPARATOR</item>
34 <item>SUBSTFILEPREFIX</item>
35 <item>SUBSTFILESUFFIX</item>
36 <item>TEXTFILEPREFIX</item>
37 <item>TEXTFILESUFFIX</item>
40 <item>SUBST_DICT</item>
44 <builder name="Textfile">
47 The &b-Textfile; builder generates a single text file from
48 a template consisting of a list of strings, replacing text
49 using the &cv-link-SUBST_DICT; &consvar; (if set) -
50 see &b-link-Substfile; for a description of replacement.
51 The strings will be separated in the target file using the
53 &cv-link-LINESEPARATOR; &consvar;;
54 the line separator is not emitted after the last string.
55 Nested lists of source strings
57 Source strings need not literally be Python strings:
58 they can be Nodes or Python objects that convert cleanly
59 to &f-link-Value; nodes
63 The prefix and suffix specified by the &cv-link-TEXTFILEPREFIX;
64 and &cv-link-TEXTFILESUFFIX; &consvars;
65 (by default an empty string and <filename>.txt</filename>, respectively)
66 are automatically added to the target if they are not already present.
71 # builds/writes foo.txt
72 env.Textfile(target='foo.txt', source=['Goethe', 42, 'Schiller'])
74 # builds/writes bar.txt
75 env.Textfile(target='bar', source=['lalala', 'tanteratei'], LINESEPARATOR='|*')
77 # nested lists are flattened automatically
78 env.Textfile(target='blob', source=['lalala', ['Goethe', 42, 'Schiller'], 'tanteratei'])
80 # files may be used as input by wraping them in File()
82 target='concat', # concatenate files with a marker between
83 source=[File('concat1'), File('concat2')],
84 LINESEPARATOR='====================\n',
90 <para><filename>foo.txt</filename></para>
97 <para><filename>bar.txt</filename></para>
102 <para><filename>blob.txt</filename></para>
114 <builder name="Substfile">
117 The &b-Substfile; builder creates a single text file from
118 a template consisting of a file or set of files (or nodes),
119 replacing text using the &cv-link-SUBST_DICT; &consvar; (if set).
120 If a set, they are concatenated into the target file
121 using the value of the
122 &cv-link-LINESEPARATOR; &consvar; as a separator between contents;
123 the separator is not emitted after the contents of the last file.
124 Nested lists of source files
125 are flattened. See also &b-link-Textfile;.
129 If a single source file name is specified and has a <filename>.in</filename> suffix,
130 the suffix is stripped and the remainder of the name is used as the default target name.
134 The prefix and suffix specified by the &cv-link-SUBSTFILEPREFIX;
135 and &cv-link-SUBSTFILESUFFIX; &consvars;
136 (an empty string by default in both cases)
137 are automatically added to the target if they are not already present.
141 If a construction variable named &cv-link-SUBST_DICT; is present,
142 it may be either a Python dictionary or a sequence of
143 (<replaceable>key</replaceable>, <replaceable>value</replaceable>) tuples.
144 If it is a dictionary it is converted into a list of tuples
145 with unspecified order,
146 so if one key is a prefix of another key
147 or if one substitution could be further expanded by another subsitition,
148 it is unpredictable whether the expansion will occur.
152 Any occurrences of a key in the source
153 are replaced by the corresponding value,
154 which may be a Python callable function or a string.
155 If the value is a callable, it is called with no arguments to get a string.
156 Strings are <emphasis>subst</emphasis>-expanded
157 and the result replaces the key.
161 env = Environment(tools=['default'])
163 env['prefix'] = '/usr/bin'
164 script_dict = {'@prefix@': '/bin', '@exec_prefix@': '$prefix'}
165 env.Substfile('script.in', SUBST_DICT=script_dict)
167 conf_dict = {'%VERSION%': '1.2.3', '%BASE%': 'MyProg'}
168 env.Substfile('config.h.in', conf_dict, SUBST_DICT=conf_dict)
170 # UNPREDICTABLE - one key is a prefix of another
171 bad_foo = {'$foo': '$foo', '$foobar': '$foobar'}
172 env.Substfile('foo.in', SUBST_DICT=bad_foo)
174 # PREDICTABLE - keys are applied longest first
175 good_foo = [('$foobar', '$foobar'), ('$foo', '$foo')]
176 env.Substfile('foo.in', SUBST_DICT=good_foo)
178 # UNPREDICTABLE - one substitution could be futher expanded
179 bad_bar = {'@bar@': '@soap@', '@soap@': 'lye'}
180 env.Substfile('bar.in', SUBST_DICT=bad_bar)
182 # PREDICTABLE - substitutions are expanded in order
183 good_bar = (('@bar@', '@soap@'), ('@soap@', 'lye'))
184 env.Substfile('bar.in', SUBST_DICT=good_bar)
186 # the SUBST_DICT may be in common (and not an override)
188 subst = Environment(tools=['textfile'], SUBST_DICT=substitutions)
189 substitutions['@foo@'] = 'foo'
190 subst['SUBST_DICT']['@bar@'] = 'bar'
193 [Value('#include "@foo@.h"'), Value('#include "@bar@.h"'), "common.in", "pgm1.in"],
197 [Value('#include "@foo@.h"'), Value('#include "@bar@.h"'), "common.in", "pgm2.in"],
204 <cvar name="LINESEPARATOR">
207 The separator used by the &b-link-Substfile; and &b-link-Textfile; builders.
208 This value is used between sources when constructing the target.
209 It defaults to the current system line separator.
214 <cvar name="SUBST_DICT">
217 The dictionary used by the &b-link-Substfile; or &b-link-Textfile; builders
218 for substitution values.
219 It can be anything acceptable to the <function>dict()</function> constructor,
220 so in addition to a dictionary,
221 lists of tuples are also acceptable.
226 <cvar name="SUBSTFILEPREFIX">
229 The prefix used for &b-link-Substfile; file names,
230 an empty string by default.
235 <cvar name="SUBSTFILESUFFIX">
238 The suffix used for &b-link-Substfile; file names,
239 an empty string by default.
244 <cvar name="TEXTFILEPREFIX">
247 The prefix used for &b-link-Textfile; file names,
248 an empty string by default.
253 <cvar name="TEXTFILESUFFIX">
256 The suffix used for &b-link-Textfile; file names;
257 <filename>.txt</filename> by default.