2 <!ENTITY % scons SYSTEM "../scons.mod">
4 <!ENTITY % builders-mod SYSTEM "builders.mod">
6 <!ENTITY % functions-mod SYSTEM "functions.mod">
8 <!ENTITY % tools-mod SYSTEM "tools.mod">
10 <!ENTITY % variables-mod SYSTEM "variables.mod">
14 <variablelist xmlns="http://www.scons.org/dbxsd/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">
15 <varlistentry id="f-Action">
16 <term><function>Action</function>(<parameter>action, [output, [var, ...]] [key=value, ...]</parameter>)</term>
17 <term><replaceable>env</replaceable>.<methodname>Action</methodname>(<parameter>action, [output, [var, ...]] [key=value, ...]</parameter>)</term>
19 A factory function to create an Action object for
21 <parameter>action</parameter>.
22 See the manpage section "Action Objects"
23 for a complete explanation of the arguments and behavior.
27 Note that the &f-env-Action;
28 form of the invocation will expand
29 construction variables in any argument strings,
31 <parameter>action</parameter>
32 argument, at the time it is called
33 using the construction variables in the
34 <replaceable>env</replaceable>
35 construction environment through which
36 &f-env-Action; was called.
37 The &f-Action; global function
38 form delays all variable expansion
39 until the Action object is actually used.
43 <varlistentry id="f-AddMethod">
44 <term><function>AddMethod</function>(<parameter>object, function, [name]</parameter>)</term>
45 <term><replaceable>env</replaceable>.<methodname>AddMethod</methodname>(<parameter>function, [name]</parameter>)</term>
47 Adds <parameter>function</parameter> to an object as a method.
48 <parameter>function</parameter> will be called with an instance
49 object as the first argument as for other methods.
50 If <parameter>name</parameter> is given, it is used as
51 the name of the new method, else the name of
52 <parameter>function</parameter> is used.
55 When the global function &f-AddMethod; is called,
56 the object to add the method to must be passed as the first argument;
57 typically this will be &Environment;,
58 in order to create a method which applies to all &consenvs;
59 subsequently constructed.
60 When called using the &f-env-AddMethod; form,
61 the method is added to the specified &consenv; only.
62 Added methods propagate through &f-env-Clone; calls.
70 # Function to add must accept an instance argument.
71 # The Python convention is to call this 'self'.
72 def my_method(self, arg):
73 print("my_method() got", arg)
75 # Use the global function to add a method to the Environment class:
76 AddMethod(Environment, my_method)
80 # Use the optional name argument to set the name of the method:
81 env.AddMethod(my_method, 'other_method_name')
82 env.other_method_name('another arg')
86 <varlistentry id="f-AddOption">
87 <term><function>AddOption</function>(<parameter>arguments</parameter>)</term>
89 Adds a local (project-specific) command-line option.
90 <parameter>arguments</parameter>
91 are the same as those supported by the <function>add_option</function>
92 method in the standard Python library module <systemitem>optparse</systemitem>,
93 with a few additional capabilities noted below.
94 See the documentation for
95 <systemitem>optparse</systemitem>
96 for a thorough discussion of its option-processing capabities.
100 In addition to the arguments and values supported by the
101 <systemitem>optparse</systemitem>
102 <function>add_option</function>
103 method, &f-AddOption;
105 <parameter>nargs</parameter>
107 a string consisting of a question mark
108 (<literal>'?'</literal>)
109 to indicate that the option argument for
110 that option string is optional.
111 If the option string is present on the
112 command line but has no matching option
113 argument, the value of the
114 <parameter>const</parameter>
115 keyword argument is produced as the value
117 If the option string is omitted from
118 the command line, the value of the
119 <parameter>default</parameter>
120 keyword argument is produced, as usual;
122 <parameter>default</parameter>
123 keyword argument in the &f-AddOption; call,
124 <constant>None</constant> is produced.
128 <systemitem>optparse</systemitem> recognizes
129 abbreviations of long option names,
130 as long as they can be unambiguously resolved.
132 <function>add_option</function> is called to
133 define a <option>--devicename</option> option,
134 it will recognize <option>--device</option>,
135 <option>--dev</option>
136 and so forth as long as there is no other option
137 which could also match to the same abbreviation.
139 &f-AddOption; do not support
140 the automatic recognition of abbreviations.
141 Instead, to allow specific abbreviations,
142 include them as synonyms in the &f-AddOption; call itself.
146 Once a new command-line option has been added with
148 the option value may be accessed using
151 &f-link-env-GetOption;.
152 &f-link-SetOption; is not currently supported for
153 options added with &f-AddOption;.
155 The value may also be set using
161 require overriding any default value.
163 value specified on the command line will
164 <emphasis>always</emphasis>
165 override a value set by any SConscript file.
170 Help text for an option is a combination
171 of the string supplied in the
172 <parameter>help</parameter> keyword
173 argument to &f-AddOption; and information
174 collected from the other keyword arguments.
175 Such help is displayed if the
176 <option>-h</option> command line option
177 is used (but not with <option>-H</option>).
178 Help for all local options is displayed
179 under the separate heading
180 <emphasis role="bold">Local Options</emphasis>.
181 The options are unsorted - they will appear
182 in the help text in the order in which the
199 help='installation prefix',
201 env = Environment(PREFIX=GetOption('prefix'))
204 <para>For that example,
205 the following help text would be produced:</para>
209 --prefix=DIR installation prefix
213 Help text for local options may be unavailable if
214 the &f-link-Help; function has been called,
215 see the &f-Help; documentation for details.
220 As an artifact of the internal implementation,
221 the behavior of options added by &AddOption;
222 which take option arguments is undefined
223 <emphasis>if</emphasis> whitespace
224 (rather than an <literal>=</literal> sign) is used as
225 the separator on the command line.
226 Users should avoid such usage; it is recommended
227 to add a note to this effect to project documentation
228 if the situation is likely to arise.
229 In addition, if the <parameter>nargs</parameter>
230 keyword is used to specify more than one following
231 option argument (that is, with a value of <constant>2</constant>
232 or greater), such arguments would necessarily
233 be whitespace separated, triggering the issue.
234 Developers should not use &AddOption; this way.
235 Future versions of &SCons; will likely forbid such usage.
241 <varlistentry id="f-AddPostAction">
242 <term><function>AddPostAction</function>(<parameter>target, action</parameter>)</term>
243 <term><replaceable>env</replaceable>.<methodname>AddPostAction</methodname>(<parameter>target, action</parameter>)</term>
245 Arranges for the specified
246 <parameter>action</parameter>
249 <parameter>target</parameter>
251 <parameter>action</parameter> may be
252 an Action object, or anything that
253 can be converted into an Action object.
254 See the manpage section "Action Objects"
255 for a complete explanation.
259 When multiple targets are supplied,
260 the action may be called multiple times,
261 once after each action that generates
262 one or more targets in the list.
266 foo = Program('foo.c')
267 # remove execute permission from binary:
268 AddPostAction(foo, Chmod('$TARGET', "a-x"))
273 <varlistentry id="f-AddPreAction">
274 <term><function>AddPreAction</function>(<parameter>target, action</parameter>)</term>
275 <term><replaceable>env</replaceable>.<methodname>AddPreAction</methodname>(<parameter>target, action</parameter>)</term>
277 Arranges for the specified
278 <parameter>action</parameter>
281 <parameter>target</parameter>
283 <parameter>action</parameter> may be
284 an Action object, or anything that
285 can be converted into an Action object.
286 See the manpage section "Action Objects"
287 for a complete explanation.
291 When multiple targets are specified,
292 the action(s) may be called multiple times,
293 once before each action that generates
294 one or more targets in the list.
298 Note that if any of the targets are built in multiple steps,
299 the action will be invoked just
300 before the "final" action that specifically
301 generates the specified target(s).
302 For example, when building an executable program
303 from a specified source
304 <filename>.c</filename>
305 file via an intermediate object file:
309 foo = Program('foo.c')
310 AddPreAction(foo, 'pre_action')
315 <literal>pre_action</literal>
316 would be executed before
318 calls the link command that actually
319 generates the executable program binary
320 <filename>foo</filename>,
321 not before compiling the
322 <filename>foo.c</filename>
323 file into an object file.
327 <varlistentry id="f-Alias">
328 <term><function>Alias</function>(<parameter>alias, [source, [action]]</parameter>)</term>
329 <term><replaceable>env</replaceable>.<methodname>Alias</methodname>(<parameter>alias, [source, [action]]</parameter>)</term>
331 Creates an <firstterm>alias</firstterm> target that
332 can be used as a reference to zero or more other targets,
333 specified by the optional <parameter>source</parameter> parameter.
334 Aliases provide a way to give a shorter or more descriptive
335 name to specific targets,
336 and to group multiple targets under a single name.
337 The alias name, or an Alias Node object,
338 may be used as a dependency of any other target,
339 including another alias.
343 <parameter>alias</parameter> and <parameter>source</parameter>
344 may each be a string or Node object,
345 or a list of strings or Node objects;
346 if Nodes are used for
347 <parameter>alias</parameter>
348 they must be Alias nodes.
349 If <parameter>source</parameter> is omitted,
350 the alias is created but has no reference;
351 if selected for building this will result in a
352 <quote>Nothing to be done.</quote> message.
353 An empty alias can be used to define the alias
354 in a visible place in the project;
355 it can later be appended to in a subsidiary SConscript file
356 with the actual target(s) to refer to.
358 <parameter>action</parameter>
359 parameter specifies an action or list of actions
360 that will be executed
361 whenever the any of the alias targets are out-of-date.
365 &f-Alias; can be called for an existing alias,
366 which appends the <parameter>alias</parameter>
367 and/or <parameter>action</parameter> arguments
368 to the existing lists for that alias.
372 Returns a list of Alias Node objects representing the alias(es),
373 which exist outside of any physical file system.
374 The alias name space is separate from the name space for
375 tangible targets; to avoid confusion do not reuse
376 target names as alias names.
385 Alias('install', '/usr/bin')
386 Alias(['install', 'install-lib'], '/usr/local/lib')
388 env.Alias('install', ['/usr/local/bin', '/usr/local/lib'])
389 env.Alias('install', ['/usr/local/man'])
391 env.Alias('update', ['file1', 'file2'], "update_database $SOURCES")
395 <varlistentry id="f-AllowSubstExceptions">
396 <term><function>AllowSubstExceptions</function>(<parameter>[exception, ...]</parameter>)</term>
398 Specifies the exceptions that will be allowed
399 when expanding construction variables.
401 any construction variable expansions that generate a
402 <literal>NameError</literal>
404 <literal>IndexError</literal>
405 exception will expand to a
406 <literal>''</literal>
407 (an empty string) and not cause scons to fail.
408 All exceptions not in the specified list
409 will generate an error message
410 and terminate processing.
415 &f-AllowSubstExceptions;
416 is called multiple times,
417 each call completely overwrites the previous list
418 of allowed exceptions.
426 # Requires that all construction variable names exist.
427 # (You may wish to do this if you want to enforce strictly
428 # that all construction variables must be defined before use.)
429 AllowSubstExceptions()
431 # Also allow a string containing a zero-division expansion
432 # like '${1 / 0}' to evalute to ''.
433 AllowSubstExceptions(IndexError, NameError, ZeroDivisionError)
437 <varlistentry id="f-AlwaysBuild">
438 <term><function>AlwaysBuild</function>(<parameter>target, ...</parameter>)</term>
439 <term><replaceable>env</replaceable>.<methodname>AlwaysBuild</methodname>(<parameter>target, ...</parameter>)</term>
442 <parameter>target</parameter>
443 so that it is always assumed to be out of date,
444 and will always be rebuilt if needed.
447 does not add its target(s) to the default target list,
448 so the targets will only be built
449 if they are specified on the command line,
450 or are a dependent of a target specified on the command line--but
452 <emphasis>always</emphasis>
453 be built if so specified.
454 Multiple targets can be passed in to a single call to
459 <varlistentry id="f-Append">
460 <term><replaceable>env</replaceable>.<methodname>Append</methodname>(<parameter>key=val, [...]</parameter>)</term>
462 Appends value(s) intelligently to &consvars; in
463 <varname>env</varname>.
464 The &consvars; and values to add to them are passed as
465 <parameter>key=val</parameter> pairs (&Python; keyword arguments).
466 &f-env-Append; is designed to allow adding values
467 without having to think about the data type of an existing &consvar;.
468 Regular &Python; syntax can also be used to manipulate the &consvar;,
469 but for that you may need to know the types involved,
470 for example pure &Python; lets you directly "add" two lists of strings,
471 but adding a string to a list or a list to a string requires
472 different syntax - things &f-Append; takes care of.
473 Some pre-defined &consvars; do have type expectations
474 based on how &SCons; will use them:
475 for example &cv-link-CPPDEFINES; is often a string or a list of strings,
476 but can also be a list of tuples or a dictionary;
477 while &cv-link-LIBEMITTER;
478 is expected to be a callable or list of callables,
479 and &cv-link-BUILDERS; is expected to be a dictionary.
480 Consult the documentation for the various &consvars; for more details.
484 The following descriptions apply to both the &f-Append;
485 and &f-Prepend; methods, as well as their
486 <emphasis role="bold">Unique</emphasis> variants,
487 with the differences being the insertion point of the added values
488 and whether duplication is allowed.
492 <parameter>val</parameter> can be almost any type.
493 If <varname>env</varname> does not have a &consvar;
494 named <parameter>key</parameter>,
495 then <parameter>key</parameter> is simply
496 stored with a value of <parameter>val</parameter>.
497 Otherwise, <parameter>val</parameter> is
498 combinined with the existing value,
499 possibly converting into an appropriate type
500 which can hold the expanded contents.
501 There are a few special cases to be aware of.
502 Normally, when two strings are combined,
503 the result is a new string containing their concatenation
504 (and you are responsible for supplying any needed separation);
505 however, the contents of &cv-link-CPPDEFINES; will
506 will be postprocessed by adding a prefix and/or suffix
507 to each entry when the command line is produced,
508 so &SCons; keeps them separate -
509 appending a string will result in a separate string entry,
510 not a combined string.
511 For &cv-CPPDEFINES;. as well as
512 &cv-link-LIBS;, and the various <literal>*PATH</literal> variables,
513 &SCons; will amend the variable by supplying the compiler-specific
514 syntax (e.g. prepending a <literal>-D</literal> or <literal>/D</literal>
515 prefix for &cv-CPPDEFINES;), so you should omit this syntax when
516 adding values to these variables.
517 Examples (gcc syntax shown in the expansion of &CPPDEFINES;):
521 env = Environment(CXXFLAGS="-std=c11", CPPDEFINES="RELEASE")
522 print(f"CXXFLAGS = {env['CXXFLAGS']}, CPPDEFINES = {env['CPPDEFINES']}")
523 # notice including a leading space in CXXFLAGS addition
524 env.Append(CXXFLAGS=" -O", CPPDEFINES="EXTRA")
525 print(f"CXXFLAGS = {env['CXXFLAGS']}, CPPDEFINES = {env['CPPDEFINES']}")
526 print("CPPDEFINES will expand to", env.subst('$_CPPDEFFLAGS'))
531 CXXFLAGS = -std=c11, CPPDEFINES = RELEASE
532 CXXFLAGS = -std=c11 -O, CPPDEFINES = deque(['RELEASE', 'EXTRA'])
533 CPPDEFINES will expand to -DRELEASE -DEXTRA
534 scons: `.' is up to date.
538 Because &cv-link-CPPDEFINES; is intended for command-line
539 specification of C/C++ preprocessor macros,
540 additional syntax is accepted when adding to it.
541 The preprocessor accepts arguments to predefine a macro name by itself
542 (<computeroutput>-DFOO</computeroutput> for most compilers,
543 <computeroutput>/DFOO</computeroutput> for Microsoft C++),
544 which gives it an implicit value of <constant>1</constant>,
545 or can be given with a replacement value
546 (<computeroutput>-DBAR=TEXT</computeroutput>).
547 &SCons; follows these rules when adding to &cv-CPPDEFINES;:
551 <para>A string is split on spaces,
552 giving an easy way to enter multiple macros in one addition.
553 Use an <literal>=</literal> to specify a valued macro.</para>
556 <para>A tuple is treated as a valued macro.
557 Use the value <constant>None</constant> if the macro should not have a value.
558 It is an error to supply more than two elements in such a tuple.</para>
561 <para>A list is processed in order,
562 adding each item without further interpretation.
563 In this case, space-separated strings are not split.</para>
566 <para>A dictionary is processed in order,
567 adding each key:value pair as a valued macro.
568 Use the value <constant>None</constant> if the macro should not have a value.
578 env = Environment(CPPDEFINES="FOO")
579 print("CPPDEFINES =", env['CPPDEFINES'])
580 env.Append(CPPDEFINES="BAR=1")
581 print("CPPDEFINES =", env['CPPDEFINES'])
582 env.Append(CPPDEFINES=[("OTHER", 2)])
583 print("CPPDEFINES =", env['CPPDEFINES'])
584 env.Append(CPPDEFINES={"EXTRA": "arg"})
585 print("CPPDEFINES =", env['CPPDEFINES'])
586 print("CPPDEFINES will expand to", env.subst('$_CPPDEFFLAGS'))
592 CPPDEFINES = deque(['FOO', 'BAR=1'])
593 CPPDEFINES = deque(['FOO', 'BAR=1', ('OTHER', 2)])
594 CPPDEFINES = deque(['FOO', 'BAR=1', ('OTHER', 2), ('EXTRA', 'arg')])
595 CPPDEFINES will expand to -DFOO -DBAR=1 -DOTHER=2 -DEXTRA=arg
596 scons: `.' is up to date.
600 Examples of adding multiple macros:
605 env.Append(CPPDEFINES=[("ONE", 1), "TWO", ("THREE", )])
606 print("CPPDEFINES =", env['CPPDEFINES'])
607 env.Append(CPPDEFINES={"FOUR": 4, "FIVE": None})
608 print("CPPDEFINES =", env['CPPDEFINES'])
609 print("CPPDEFINES will expand to", env.subst('$_CPPDEFFLAGS'))
614 CPPDEFINES = [('ONE', 1), 'TWO', ('THREE',)]
615 CPPDEFINES = deque([('ONE', 1), 'TWO', ('THREE',), ('FOUR', 4), ('FIVE', None)])
616 CPPDEFINES will expand to -DONE=1 -DTWO -DTHREE -DFOUR=4 -DFIVE
617 scons: `.' is up to date.
621 <emphasis>Changed in version 4.5</emphasis>:
622 clarifined the use of tuples vs. other types,
623 handling is now consistent across the four functions.
628 env.Append(CPPDEFINES=("MACRO1", "MACRO2"))
629 print("CPPDEFINES =", env['CPPDEFINES'])
630 env.Append(CPPDEFINES=[("MACRO3", "MACRO4")])
631 print("CPPDEFINES =", env['CPPDEFINES'])
632 print("CPPDEFINES will expand to", env.subst('$_CPPDEFFLAGS'))
637 CPPDEFINES = ('MACRO1', 'MACRO2')
638 CPPDEFINES = deque(['MACRO1', 'MACRO2', ('MACRO3', 'MACRO4')])
639 CPPDEFINES will expand to -DMACRO1 -DMACRO2 -DMACRO3=MACRO4
640 scons: `.' is up to date.
644 See &cv-link-CPPDEFINES; for more details.
648 Appending a string <parameter>val</parameter>
649 to a dictonary-typed &consvar; enters
650 <parameter>val</parameter> as the key in the dictionary,
651 and <literal>None</literal> as its value.
652 Using a tuple type to supply a <literal>key, value</literal>
653 only works for the special case of &cv-CPPDEFINES;
658 Although most combinations of types work without
659 needing to know the details, some combinations
660 do not make sense and &Python; raises an exception.
664 When using &f-env-Append; to modify &consvars;
665 which are path specifications (conventionally,
666 the names of such end in <literal>PATH</literal>),
667 it is recommended to add the values as a list of strings,
668 even if you are only adding a single string.
669 The same goes for adding library names to &cv-LIBS;.
673 env.Append(CPPPATH=["#/include"])
677 See also &f-link-env-AppendUnique;,
678 &f-link-env-Prepend; and &f-link-env-PrependUnique;.
683 <varlistentry id="f-AppendENVPath">
684 <term><replaceable>env</replaceable>.<methodname>AppendENVPath</methodname>(<parameter>name, newpath, [envname, sep, delete_existing=False]</parameter>)</term>
686 Append path elements specified by <parameter>newpath</parameter>
687 to the given search path string or list <parameter>name</parameter>
688 in mapping <parameter>envname</parameter> in the &consenv;.
689 Supplying <parameter>envname</parameter> is optional:
690 the default is the execution environment &cv-link-ENV;.
691 Optional <parameter>sep</parameter> is used as the search path separator,
692 the default is the platform's separator (<systemitem>os.pathsep</systemitem>).
693 A path element will only appear once.
694 Any duplicates in <parameter>newpath</parameter> are dropped,
695 keeping the last appearing (to preserve path order).
696 If <parameter>delete_existing</parameter>
697 is <constant>False</constant> (the default)
698 any addition duplicating an existing path element is ignored;
699 if <parameter>delete_existing</parameter>
700 is <constant>True</constant> the existing value will
701 be dropped and the path element will be added at the end.
702 To help maintain uniqueness all paths are normalized (using
703 <systemitem>os.path.normpath</systemitem>
705 <systemitem>os.path.normcase</systemitem>).
713 print('before:', env['ENV']['INCLUDE'])
714 include_path = '/foo/bar:/foo'
715 env.AppendENVPath('INCLUDE', include_path)
716 print('after:', env['ENV']['INCLUDE'])
722 after: /biz:/foo/bar:/foo
726 See also &f-link-env-PrependENVPath;.
731 <varlistentry id="f-AppendUnique">
732 <term><replaceable>env</replaceable>.<methodname>AppendUnique</methodname>(<parameter>key=val, [...], [delete_existing=False]</parameter>)</term>
734 Append values to &consvars; in the current &consenv;,
735 maintaining uniqueness.
736 Works like &f-link-env-Append;,
737 except that values that would become duplicates
739 If <parameter>delete_existing</parameter>
740 is set to a true value, then for any duplicate,
741 the existing instance of <parameter>val</parameter> is first removed,
742 then <parameter>val</parameter> is appended,
743 having the effect of moving it to the end.
751 env.AppendUnique(CCFLAGS='-g', FOO=['foo.yyy'])
755 See also &f-link-env-Append;,
757 and &f-link-env-PrependUnique;.
761 <varlistentry id="f-Builder">
762 <term><function>Builder</function>(<parameter>action, [arguments]</parameter>)</term>
763 <term><replaceable>env</replaceable>.<methodname>Builder</methodname>(<parameter>action, [arguments]</parameter>)</term>
765 Creates a Builder object for
767 <parameter>action</parameter>.
768 See the manpage section "Builder Objects"
769 for a complete explanation of the arguments and behavior.
774 <function>env.Builder</function>()
775 form of the invocation will expand
776 construction variables in any arguments strings,
778 <parameter>action</parameter>
780 at the time it is called
781 using the construction variables in the
782 <varname>env</varname>
783 construction environment through which
784 &f-env-Builder; was called.
787 form delays all variable expansion
788 until after the Builder object is actually called.
792 <varlistentry id="f-CacheDir">
793 <term><function>CacheDir</function>(<parameter>cache_dir, custom_class=None</parameter>)</term>
794 <term><replaceable>env</replaceable>.<methodname>CacheDir</methodname>(<parameter>cache_dir, custom_class=None</parameter>)</term>
798 to maintain a derived-file cache in
799 <parameter>cache_dir</parameter>.
800 The derived files in the cache will be shared
801 among all the builds specifying the same
802 <parameter>cache_dir</parameter>.
804 <parameter>cache_dir</parameter>
806 <constant>None</constant>
807 disables derived file caching.
811 Calling the environment method
812 &f-link-env-CacheDir;
813 limits the effect to targets built
814 through the specified construction environment.
815 Calling the global function
817 sets a global default
818 that will be used by all targets built
819 through construction environments
820 that do not set up environment-specific
821 caching by calling &f-env-CacheDir;.
825 Caching behavior can be configured by passing a specialized cache
826 class as the optional <parameter>custom_class</parameter> parameter.
827 This class must be a subclass of
828 <classname>SCons.CacheDir.CacheDir</classname>.
829 &SCons; will internally invoke the custom class for performing
831 If the parameter is omitted or set to
832 <constant>None</constant>, &SCons; will use the default
833 <classname>SCons.CacheDir.CacheDir</classname> class.
837 When derived-file caching
840 finds a derived file that needs to be rebuilt,
841 it will first look in the cache to see if a
842 file with matching &buildsig; exists
843 (indicating the input file(s) and build action(s)
844 were identical to those for the current target),
845 and if so, will retrieve the file from the cache.
848 <computeroutput>Retrieved `file' from cache</computeroutput>
849 instead of the normal build message.
850 If the derived file is not present in the cache,
853 then place a copy of the built file in the cache,
854 identified by its &buildsig;, for future use.
859 <computeroutput>Retrieved `file' from cache</computeroutput>
860 messages are useful for human consumption,
861 but less useful when comparing log files between
862 &scons; runs which will show differences that are
863 noisy and not actually significant.
865 use the <option>--cache-show</option> option.
866 With this option, &scons; changes printing
867 to always show the action that would
868 have been used to build the file without caching.
873 may be disabled for any invocation
874 of &scons; by giving the
875 <option>--cache-disable</option>
877 cache updating may be disabled, leaving cache
878 fetching enabled, by giving the
879 <option>--cache-readonly</option> option.
884 <option>--cache-force</option>
888 <emphasis>all</emphasis>
889 derived files into the cache,
890 even if they already existed
891 and were not built by this invocation.
892 This is useful to populate a cache
894 <parameter>cache_dir</parameter>
896 or to bring a cache up to date after
897 a build with cache updating disabled
898 (<option>--cache-disable</option>
899 or <option>--cache-readonly</option>)
906 method can be used to disable caching of specific files. This can be
907 useful if inputs and/or outputs of some tool are impossible to
908 predict or prohibitively large.
912 Note that (at this time) &SCons; provides no facilities
913 for managing the derived-file cache. It is up to the developer
914 to arrange for cache pruning, expiry, access control, etc. if needed.
919 <varlistentry id="f-Clean">
920 <term><function>Clean</function>(<parameter>targets, files_or_dirs</parameter>)</term>
921 <term><replaceable>env</replaceable>.<methodname>Clean</methodname>(<parameter>targets, files_or_dirs</parameter>)</term>
923 This specifies a list of files or directories which should be removed
924 whenever the targets are specified with the
927 The specified targets may be a list
928 or an individual target.
932 and create new targets or add files and directories to the
933 clean list for the specified targets.
937 Multiple files or directories should be specified
938 either as separate arguments to the
940 method, or as a list.
942 will also accept the return value of any of the construction environment
950 function overrides calling
953 and any targets passed to both functions will
954 <emphasis>not</emphasis>
965 Clean('foo', ['bar', 'baz'])
966 Clean('dist', env.Program('hello', 'hello.c'))
967 Clean(['foo', 'bar'], 'something_else_to_clean')
972 installing the project creates a subdirectory for the documentation.
973 This statement causes the subdirectory to be removed
974 if the project is deinstalled.
977 Clean(docdir, os.path.join(docdir, projectname))
981 <varlistentry id="f-Clone">
982 <term><replaceable>env</replaceable>.<methodname>Clone</methodname>(<parameter>[key=val, ...]</parameter>)</term>
984 Returns a separate copy of a construction environment.
985 If there are any keyword arguments specified,
986 they are added to the returned copy,
987 overwriting any existing values
997 env3 = env.Clone(CCFLAGS='-g')
1001 Additionally, a list of tools and a toolpath may be specified, as in
1002 the &f-link-Environment; constructor:
1009 env4 = env.Clone(tools=['msvc', MyTool])
1014 <parameter>parse_flags</parameter>
1015 keyword argument is also recognized to allow merging command-line
1016 style arguments into the appropriate construction
1017 variables (see &f-link-env-MergeFlags;).
1021 # create an environment for compiling programs that use wxWidgets
1022 wx_env = env.Clone(parse_flags='!wx-config --cflags --cxxflags')
1026 <varlistentry id="f-Command">
1027 <term><function>Command</function>(<parameter>target, source, action, [key=val, ...]</parameter>)</term>
1028 <term><replaceable>env</replaceable>.<methodname>Command</methodname>(<parameter>target, source, action, [key=val, ...]</parameter>)</term>
1030 Executes a specific <parameter>action</parameter>
1031 (or list of actions)
1032 to build a <parameter>target</parameter> file or files
1033 from a <parameter>source</parameter> file or files.
1034 This is more convenient
1035 than defining a separate Builder object
1036 for a single special-case build.
1041 &Command; function accepts
1042 <parameter>source_scanner</parameter>,
1043 <parameter>target_scanner</parameter>,
1044 <parameter>source_factory</parameter>, and
1045 <parameter>target_factory</parameter>
1046 keyword arguments. These arguments can
1049 that will be used to apply a custom
1050 scanner for a source or target.
1051 For example, the global
1052 <literal>DirScanner</literal>
1054 if any of the sources will be directories
1055 that must be scanned on-disk for
1056 changes to files that aren't
1057 already specified in other Builder of function calls.
1058 The <parameter>*_factory</parameter> arguments take a factory function that
1059 &Command; will use to turn any sources or targets
1060 specified as strings into SCons Nodes.
1061 See the manpage section "Builder Objects"
1062 for more information about how these
1063 arguments work in a Builder.
1067 Any other keyword arguments specified override any
1068 same-named existing construction variables.
1072 An action can be an external command,
1073 specified as a string,
1074 or a callable &Python; object;
1075 see the manpage section "Action Objects"
1076 for more complete information.
1077 Also note that a string specifying an external command
1078 may be preceded by an at-sign
1079 (<literal>@</literal>)
1080 to suppress printing the command in question,
1082 (<literal>-</literal>)
1083 to ignore the exit status of the external command.
1094 action="$FOO_BUILD < $SOURCES > $TARGET"
1100 action=["rm -f $TARGET", "$BAR_BUILD < $SOURCES > $TARGET"],
1101 ENV={'PATH': '/usr/local/bin/'},
1106 def rename(env, target, source):
1107 os.rename('.tmp', str(target[0]))
1113 action=["$BAZ_BUILD < $SOURCES > .tmp", rename],
1120 function will usually assume, by default,
1121 that the specified targets and/or sources are Files,
1122 if no other part of the configuration
1123 identifies what type of entries they are.
1124 If necessary, you can explicitly specify
1125 that targets or source nodes should
1126 be treated as directories
1139 env.Command('ddd.list', Dir('ddd'), 'ls -l $SOURCE > $TARGET')
1141 env['DISTDIR'] = 'destination/directory'
1142 env.Command(env.Dir('$DISTDIR')), None, make_distdir)
1146 Also note that SCons will usually
1147 automatically create any directory necessary to hold a target file,
1148 so you normally don't need to create directories by hand.
1152 <varlistentry id="f-Configure">
1153 <term><function>Configure</function>(<parameter>env, [custom_tests, conf_dir, log_file, config_h]</parameter>)</term>
1154 <term><replaceable>env</replaceable>.<methodname>Configure</methodname>(<parameter>[custom_tests, conf_dir, log_file, config_h]</parameter>)</term>
1156 Creates a &Configure; object for integrated
1157 functionality similar to GNU <command>autoconf</command>.
1158 See the manpage section "Configure Contexts"
1159 for a complete explanation of the arguments and behavior.
1163 <varlistentry id="f-DebugOptions">
1164 <term><function>DebugOptions</function>(<parameter>[json]</parameter>)</term>
1166 Allows setting options for SCons debug options. Currently the only supported value is
1167 <emphasis>json</emphasis> which sets the path to the json file created when
1168 <literal>--debug=json</literal> is set.
1171 DebugOptions(json='#/build/output/scons_stats.json')
1175 <varlistentry id="f-Decider">
1176 <term><function>Decider</function>(<parameter>function</parameter>)</term>
1177 <term><replaceable>env</replaceable>.<methodname>Decider</methodname>(<parameter>function</parameter>)</term>
1179 Specifies that all up-to-date decisions for
1180 targets built through this construction environment
1181 will be handled by the specified
1182 <parameter>function</parameter>.
1183 <parameter>function</parameter> can be the name of
1184 a function or one of the following strings
1185 that specify the predefined decision function
1186 that will be applied:
1192 <term><literal>"content"</literal></term>
1195 Specifies that a target shall be considered out of date and rebuilt
1196 if the dependency's content has changed since the last time
1197 the target was built,
1198 as determined by performing a checksum
1199 on the dependency's contents using the selected hash function,
1200 and comparing it to the checksum recorded the
1201 last time the target was built.
1202 <literal>content</literal> is the default decider.
1205 <emphasis>Changed in version 4.1:</emphasis>
1206 The decider was renamed to <literal>content</literal>
1207 since the hash function is now selectable.
1208 The former name, <literal>MD5</literal>,
1209 can still be used as a synonym, but is deprecated.
1214 <term><literal>"content-timestamp"</literal></term>
1217 Specifies that a target shall be considered out of date and rebuilt
1218 if the dependency's content has changed since the last time
1219 the target was built,
1220 except that dependencies with a timestamp that matches
1221 the last time the target was rebuilt will be
1222 assumed to be up-to-date and
1223 <emphasis>not</emphasis>
1225 This provides behavior very similar
1227 <literal>content</literal>
1228 behavior of always checksumming file contents,
1229 with an optimization of not checking
1230 the contents of files whose timestamps haven't changed.
1231 The drawback is that SCons will
1232 <emphasis>not</emphasis>
1233 detect if a file's content has changed
1234 but its timestamp is the same,
1235 as might happen in an automated script
1238 and runs the build again,
1239 all within a single second.
1242 <emphasis>Changed in version 4.1:</emphasis>
1243 The decider was renamed to <literal>content-timestamp</literal>
1244 since the hash function is now selectable.
1245 The former name, <literal>MD5-timestamp</literal>,
1246 can still be used as a synonym, but is deprecated.
1251 <term><literal>"timestamp-newer"</literal></term>
1254 Specifies that a target shall be considered out of date and rebuilt
1255 if the dependency's timestamp is newer than the target file's timestamp.
1256 This is the behavior of the classic Make utility,
1258 <literal>make</literal>
1259 can be used a synonym for
1260 <literal>timestamp-newer</literal>.
1265 <term><literal>"timestamp-match"</literal></term>
1268 Specifies that a target shall be considered out of date and rebuilt
1269 if the dependency's timestamp is different than the
1270 timestamp recorded the last time the target was built.
1271 This provides behavior very similar to the classic Make utility
1272 (in particular, files are not opened up so that their
1273 contents can be checksummed)
1274 except that the target will also be rebuilt if a
1275 dependency file has been restored to a version with an
1276 <emphasis>earlier</emphasis>
1277 timestamp, such as can happen when restoring files from backup archives.
1289 # Use exact timestamp matches by default.
1290 Decider('timestamp-match')
1292 # Use hash content signatures for any targets built
1293 # with the attached construction environment.
1294 env.Decider('content')
1298 In addition to the above already-available functions, the
1299 <parameter>function</parameter>
1300 argument may be a &Python; function you supply.
1301 Such a function must accept the following four arguments:
1307 <term><parameter>dependency</parameter></term>
1310 The Node (file) which
1312 <parameter>target</parameter>
1314 if it has "changed" since the last tme
1315 <parameter>target</parameter>
1321 <term><parameter>target</parameter></term>
1324 The Node (file) being built.
1326 this is what should get rebuilt
1328 <parameter>dependency</parameter>
1334 <term><parameter>prev_ni</parameter></term>
1337 Stored information about the state of the
1338 <parameter>dependency</parameter>
1340 <parameter>target</parameter>
1342 This can be consulted to match various
1343 file characteristics
1344 such as the timestamp,
1345 size, or &contentsig;.
1350 <term><parameter>repo_node</parameter></term>
1353 If set, use this Node instead of the one specified by
1354 <parameter>dependency</parameter>
1355 to determine if the dependency has changed.
1356 This argument is optional so should be written
1357 as a default argument (typically it would be
1358 written as <parameter>repo_node=None</parameter>).
1359 A caller will normally only set this if the
1360 target only exists in a Repository.
1370 <parameter>function</parameter>
1371 should return a value which evaluates
1372 <constant>True</constant>
1374 <parameter>dependency</parameter>
1375 has "changed" since the last time
1377 <parameter>target</parameter>
1379 (indicating that the target
1380 <emphasis>should</emphasis>
1382 and a value which evaluates
1383 <constant>False</constant>
1385 (indicating that the target should
1386 <emphasis>not</emphasis>
1388 Note that the decision can be made
1389 using whatever criteria are appopriate.
1390 Ignoring some or all of the function arguments
1391 is perfectly normal.
1399 def my_decider(dependency, target, prev_ni, repo_node=None):
1400 return not os.path.exists(str(target))
1402 env.Decider(my_decider)
1406 <varlistentry id="f-Default">
1407 <term><function>Default</function>(<parameter>target[, ...]</parameter>)</term>
1408 <term><replaceable>env</replaceable>.<methodname>Default</methodname>(<parameter>target[, ...]</parameter>)</term>
1410 Specify default targets to the &SCons; target selection mechanism.
1411 Any call to &f-Default; will cause &SCons; to use the
1412 defined default target list instead of
1413 its built-in algorithm for determining default targets
1414 (see the manpage section "Target Selection").
1418 <parameter>target</parameter> may be one or more strings,
1420 a <classname>NodeList</classname> as returned by a Builder,
1421 or <constant>None</constant>.
1422 A string <parameter>target</parameter> may be the name of
1423 a file or directory, or a target previously defined by a call to
1424 &f-link-Alias; (defining the alias later will still create
1425 the alias, but it will not be recognized as a default).
1426 Calls to &f-Default; are additive.
1427 A <parameter>target</parameter> of
1428 <literal>None</literal>
1429 will clear any existing default target list;
1432 will add to the (now empty) default target list
1437 Both forms of this call affect the
1438 same global list of default targets; the
1439 construction environment method applies
1440 construction variable expansion to the targets.
1444 The current list of targets added using
1445 &f-Default; is available in the
1446 &DEFAULT_TARGETS; list (see below).
1454 Default('foo', 'bar', 'baz')
1455 env.Default(['a', 'b', 'c'])
1456 hello = env.Program('hello', 'hello.c')
1462 <varlistentry id="f-DefaultEnvironment">
1463 <term><function>DefaultEnvironment</function>(<parameter>[**kwargs]</parameter>)</term>
1465 Instantiates and returns the global &consenv; object.
1466 This environment is used internally by SCons
1467 when it executes many of the global functions listed in this section
1468 (that is, those not called as methods of a specific &consenv;).
1469 The &defenv; is a singleton:
1470 the keyword arguments are used only on the first call;
1471 on subsequent calls the already-constructed object is returned
1472 and any keyword arguments are silently ignored.
1473 The &defenv; can still be modified after instantiation
1474 in the same way as any other &consenv;.
1475 The &defenv; is independent:
1476 modifying it has no effect on any other &consenv;
1477 constructed by an &f-link-Environment; or &f-link-Clone; call.
1481 It is not mandatory to call &f-DefaultEnvironment;:
1482 the &defenv; is instantiated automatically when the
1483 build phase begins if this function has not been called;
1484 however calling it explicitly gives the opportunity to
1485 affect and examine the contents of the &defenv;.
1486 Instantiation happens even if no build instructions
1487 appar to use it, as there are internal uses.
1488 If there are no uses in the project &SConscript; files,
1489 a small performance gain may be seen by calling
1490 &f-DefaultEnvironment; with an empty tools list,
1491 thus avoiding that part of the initialization cost.
1492 This is mainly of interest in testing when &scons; is
1493 launched repeatedly in a short time period:
1496 DefaultEnvironment(tools=[])
1500 <varlistentry id="f-Depends">
1501 <term><function>Depends</function>(<parameter>target, dependency</parameter>)</term>
1502 <term><replaceable>env</replaceable>.<methodname>Depends</methodname>(<parameter>target, dependency</parameter>)</term>
1504 Specifies an explicit dependency;
1506 <parameter>target</parameter>
1509 <parameter>dependency</parameter>
1512 <parameter>target</parameter>
1514 <parameter>dependency</parameter>
1516 (usually the path name of a file or directory)
1518 or a list of strings or Node objects
1519 (such as returned by a Builder call).
1520 This should only be necessary
1521 for cases where the dependency
1522 is not caught by a Scanner
1531 env.Depends('foo', 'other-input-file-for-foo')
1533 mylib = env.Library('mylib.c')
1534 installed_lib = env.Install('lib', mylib)
1535 bar = env.Program('bar.c')
1537 # Arrange for the library to be copied into the installation
1538 # directory before trying to build the "bar" program.
1539 # (Note that this is for example only. A "real" library
1540 # dependency would normally be configured through the $LIBS
1541 # and $LIBPATH variables, not using an env.Depends() call.)
1543 env.Depends(bar, installed_lib)
1547 <varlistentry id="f-Detect">
1548 <term><replaceable>env</replaceable>.<methodname>Detect</methodname>(<parameter>progs</parameter>)</term>
1550 Find an executable from one or more choices:
1551 <parameter>progs</parameter> may be a string or a list of strings.
1552 Returns the first value from <parameter>progs</parameter>
1553 that was found, or <constant>None</constant>.
1554 Executable is searched by checking the paths in the execution environment
1555 (<varname>env</varname><literal>['ENV']['PATH']</literal>).
1556 On Windows systems, additionally applies the filename suffixes found in
1557 the execution environment
1558 (<varname>env</varname><literal>['ENV']['PATHEXT']</literal>)
1559 but will not include any such extension in the return value.
1560 &f-env-Detect; is a wrapper around &f-link-env-WhereIs;.
1564 <varlistentry id="f-Dictionary">
1565 <term><replaceable>env</replaceable>.<methodname>Dictionary</methodname>(<parameter>[vars]</parameter>)</term>
1567 Returns a dictionary object
1568 containing the &consvars; in the &consenv;.
1569 If there are any arguments specified,
1570 the values of the specified &consvars;
1571 are returned as a string (if one
1572 argument) or as a list of strings.
1580 cvars = env.Dictionary()
1581 cc_values = env.Dictionary('CC', 'CCFLAGS', 'CCCOM')
1585 <varlistentry id="f-Dir">
1586 <term><function>Dir</function>(<parameter>name, [directory]</parameter>)</term>
1587 <term><replaceable>env</replaceable>.<methodname>Dir</methodname>(<parameter>name, [directory]</parameter>)</term>
1589 Returns Directory Node(s).
1590 A Directory Node is an object that represents a directory.
1591 <parameter>name</parameter>
1592 can be a relative or absolute path or a list of such paths.
1593 <parameter>directory</parameter>
1594 is an optional directory that will be used as the parent directory.
1596 <parameter>directory</parameter>
1597 is specified, the current script's directory is used as the parent.
1602 <parameter>name</parameter>
1603 is a single pathname, the corresponding node is returned.
1605 <parameter>name</parameter>
1606 is a list, SCons returns a list of nodes.
1607 Construction variables are expanded in
1608 <parameter>name</parameter>.
1612 Directory Nodes can be used anywhere you
1613 would supply a string as a directory name
1614 to a Builder method or function.
1615 Directory Nodes have attributes and methods
1616 that are useful in many situations;
1617 see manpage section "File and Directory Nodes"
1618 for more information.
1622 <varlistentry id="f-Dump">
1623 <term><replaceable>env</replaceable>.<methodname>Dump</methodname>(<parameter>[key], [format]</parameter>)</term>
1625 Serializes &consvars; to a string.
1626 The method supports the following formats specified by
1627 <parameter>format</parameter>:
1630 <term><literal>pretty</literal></term>
1633 Returns a pretty printed representation of the environment (if
1634 <parameter>format</parameter>
1635 is not specified, this is the default).
1640 <term><literal>json</literal></term>
1643 Returns a JSON-formatted string representation of the environment.
1649 If <varname>key</varname> is
1650 <constant>None</constant> (the default) the entire
1651 dictionary of &consvars; is serialized.
1652 If supplied, it is taken as the name of a &consvar;
1653 whose value is serialized.
1662 print(env.Dump('CCCOM'))
1670 '$CC -c -o $TARGET $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS $SOURCES'
1674 While this SConstruct:
1687 'ARCOM': '$AR $ARFLAGS $TARGET $SOURCES\n$RANLIB $RANLIBFLAGS $TARGET',
1690 'ASCOM': '$AS $ASFLAGS -o $TARGET $SOURCES',
1696 <varlistentry id="f-EnsurePythonVersion">
1697 <term><function>EnsurePythonVersion</function>(<parameter>major, minor</parameter>)</term>
1699 Ensure that the Python version is at least
1700 <varname>major</varname>.<varname>minor</varname>.
1702 print out an error message and exit SCons with a non-zero exit code if the
1703 actual Python version is not late enough.
1711 EnsurePythonVersion(2,2)
1715 <varlistentry id="f-EnsureSConsVersion">
1716 <term><function>EnsureSConsVersion</function>(<parameter>major, minor, [revision]</parameter>)</term>
1718 Ensure that the SCons version is at least
1719 <varname>major.minor</varname>,
1721 <varname>major.minor.revision</varname>.
1723 <varname>revision</varname>
1726 print out an error message and exit SCons with a non-zero exit code if the
1727 actual SCons version is not late enough.
1735 EnsureSConsVersion(0,14)
1737 EnsureSConsVersion(0,96,90)
1741 <varlistentry id="f-Environment">
1742 <term><function>Environment</function>(<parameter>[key=value, ...]</parameter>)</term>
1743 <term><replaceable>env</replaceable>.<methodname>Environment</methodname>(<parameter>[key=value, ...]</parameter>)</term>
1745 Return a new construction environment
1746 initialized with the specified
1747 <parameter>key</parameter>=<replaceable>value</replaceable>
1749 The keyword arguments
1750 <parameter>parse_flags</parameter>,
1751 <parameter>platform</parameter>,
1752 <parameter>toolpath</parameter>,
1753 <parameter>tools</parameter>
1754 and <parameter>variables</parameter>
1755 are also specially recognized.
1756 See the manpage section "Construction Environments" for more details.
1760 <varlistentry id="f-Execute">
1761 <term><function>Execute</function>(<parameter>action, [actionargs ...]</parameter>)</term>
1762 <term><replaceable>env</replaceable>.<methodname>Execute</methodname>(<parameter>action, [actionargs ...]</parameter>)</term>
1765 <parameter>action</parameter>
1766 may be an Action object
1767 or it may be a command-line string,
1769 or executable &Python; function,
1770 each of which will first be converted
1771 into an Action object
1773 Any additional arguments to &f-Execute;
1774 are passed on to the &f-link-Action; factory function
1775 which actually creates the Action object
1776 (see the manpage section <link linkend="action_objects">Action Objects</link>
1777 for a description). Example:
1781 Execute(Copy('file.out', 'file.in'))
1784 <para>&f-Execute; performs its action immediately,
1785 as part of the SConscript-reading phase.
1786 There are no sources or targets declared in an
1787 &f-Execute; call, so any objects it manipulates
1788 will not be tracked as part of the &SCons; dependency graph.
1789 In the example above, neither
1790 <filename>file.out</filename> nor
1791 <filename>file.in</filename> will be tracked objects.
1795 &f-Execute; returns the exit value of the command
1796 or return value of the &Python; function.
1798 prints an error message if the executed
1799 <parameter>action</parameter>
1800 fails (exits with or returns a non-zero value),
1802 <emphasis>not</emphasis>,
1803 automatically terminate the build for such a failure.
1804 If you want the build to stop in response to a failed
1807 you must explicitly check for a non-zero return value:
1811 if Execute("mkdir sub/dir/ectory"):
1812 # The mkdir failed, don't try to build.
1817 <varlistentry id="f-Exit">
1818 <term><function>Exit</function>(<parameter>[value]</parameter>)</term>
1824 <varname>value</varname>.
1825 A default exit value of
1826 <literal>0</literal>
1828 is used if no value is specified.
1832 <varlistentry id="f-Export">
1833 <term><function>Export</function>(<parameter>[vars...], [key=value...]</parameter>)</term>
1834 <term><replaceable>env</replaceable>.<methodname>Export</methodname>(<parameter>[vars...], [key=value...]</parameter>)</term>
1836 Exports variables for sharing with other SConscript files.
1837 The variables are added to a global collection where
1838 they can be imported by other SConscript files.
1839 <parameter>vars</parameter> may be one or more
1840 strings, or a list of strings. If any string
1841 contains whitespace, it is split automatically
1842 into individual strings. Each string must
1843 match the name of a variable that is in scope
1844 during evaluation of the current SConscript file,
1845 or an exception is raised.
1849 A <parameter>vars</parameter> argument
1850 may also be a dictionary or
1851 individual keyword arguments;
1852 in accordance with &Python; syntax rules,
1853 keyword arguments must come after any
1854 non-keyword arguments.
1855 The dictionary/keyword form can be used
1856 to map the local name of a variable to
1857 a different name to be used for imports.
1858 See the Examples for an illustration of the syntax.
1862 &f-Export; calls are cumulative. Specifying a previously
1863 exported variable will replace the previous value in the collection.
1864 Both local variables and global variables can be exported.
1868 To use an exported variable, an SConscript must
1869 call &f-link-Import; to bring it into its own scope.
1870 Importing creates an additional reference to the object that
1871 was originally exported, so if that object is mutable,
1872 changes made will be visible to other users of that object.
1881 # Make env available for all SConscript files to Import().
1885 # Make env and package available for all SConscript files:.
1886 Export("env", "package")
1888 # Make env and package available for all SConscript files:
1889 Export(["env", "package"])
1891 # Make env available using the name debug:
1894 # Make env available using the name debug:
1895 Export({"debug": env})
1901 function also supports an &exports;
1902 argument that allows exporting one or more variables
1903 to the SConscript files invoked by that call (only).
1904 See the description of that function for details.
1908 <varlistentry id="f-File">
1909 <term><function>File</function>(<parameter>name, [directory]</parameter>)</term>
1910 <term><replaceable>env</replaceable>.<methodname>File</methodname>(<parameter>name, [directory]</parameter>)</term>
1912 Returns File Node(s).
1913 A File Node is an object that represents a file.
1914 <parameter>name</parameter>
1915 can be a relative or absolute path or a list of such paths.
1916 <parameter>directory</parameter>
1917 is an optional directory that will be used as the parent directory.
1919 <parameter>directory</parameter>
1920 is specified, the current script's directory is used as the parent.
1925 <parameter>name</parameter>
1926 is a single pathname, the corresponding node is returned.
1928 <parameter>name</parameter>
1929 is a list, SCons returns a list of nodes.
1930 Construction variables are expanded in
1931 <parameter>name</parameter>.
1935 File Nodes can be used anywhere you
1936 would supply a string as a file name
1937 to a Builder method or function.
1938 File Nodes have attributes and methods
1939 that are useful in many situations;
1940 see manpage section "File and Directory Nodes"
1941 for more information.
1945 <varlistentry id="f-FindFile">
1946 <term><function>FindFile</function>(<parameter>file, dirs</parameter>)</term>
1947 <term><replaceable>env</replaceable>.<methodname>FindFile</methodname>(<parameter>file, dirs</parameter>)</term>
1950 <parameter>file</parameter>
1951 in the path specified by
1952 <parameter>dirs</parameter>.
1953 <parameter>dirs</parameter>
1954 may be a list of directory names or a single directory name.
1955 In addition to searching for files that exist in the filesystem,
1956 this function also searches for derived files
1957 that have not yet been built.
1965 foo = env.FindFile('foo', ['dir1', 'dir2'])
1969 <varlistentry id="f-FindInstalledFiles">
1970 <term><function>FindInstalledFiles</function>()</term>
1971 <term><replaceable>env</replaceable>.<methodname>FindInstalledFiles</methodname>()</term>
1973 Returns the list of targets set up by the
1981 This function serves as a convenient method to select the contents of
1990 Install('/bin', ['executable_a', 'executable_b'])
1992 # will return the file node list
1993 # ['/bin/executable_a', '/bin/executable_b']
1994 FindInstalledFiles()
1996 Install('/lib', ['some_library'])
1998 # will return the file node list
1999 # ['/bin/executable_a', '/bin/executable_b', '/lib/some_library']
2000 FindInstalledFiles()
2004 <varlistentry id="f-FindPathDirs">
2005 <term><function>FindPathDirs</function>(<parameter>variable</parameter>)</term>
2008 (actually a callable Python object)
2009 intended to be used as the
2010 <varname>path_function</varname>
2011 of a Scanner object.
2012 The returned object will look up the specified
2013 <varname>variable</varname>
2014 in a construction environment
2015 and treat the construction variable's value as a list of
2016 directory paths that should be searched
2026 is generally preferable to
2028 <varname>path_function</varname>
2029 for the following reasons:
2030 1) The returned list will contain all appropriate directories
2031 found in source trees
2035 or in code repositories
2041 2) scons will identify expansions of
2042 <varname>variable</varname>
2043 that evaluate to the same list of directories as,
2044 in fact, the same list,
2045 and avoid re-scanning the directories for files,
2054 def my_scan(node, env, path, arg):
2055 # Code to scan file contents goes here...
2056 return include_files
2058 scanner = Scanner(name = 'myscanner',
2060 path_function = FindPathDirs('MYPATH'))
2064 <varlistentry id="f-FindSourceFiles">
2065 <term><function>FindSourceFiles</function>(<parameter>node='"."'</parameter>)</term>
2066 <term><replaceable>env</replaceable>.<methodname>FindSourceFiles</methodname>(<parameter>node='"."'</parameter>)</term>
2068 Returns the list of nodes which serve as the source of the built files.
2069 It does so by inspecting the dependency tree starting at the optional
2071 <parameter>node</parameter>
2072 which defaults to the '"."'-node. It will then return all leaves of
2073 <parameter>node</parameter>.
2074 These are all children which have no further children.
2078 This function is a convenient method to select the contents of a Source
2087 Program('src/main_a.c')
2088 Program('src/main_b.c')
2091 # returns ['main_c.c', 'src/main_a.c', 'SConstruct', 'src/main_b.c']
2094 # returns ['src/main_b.c', 'src/main_a.c' ]
2095 FindSourceFiles('src')
2099 As you can see build support files (SConstruct in the above example)
2100 will also be returned by this function.
2104 <varlistentry id="f-Flatten">
2105 <term><function>Flatten</function>(<parameter>sequence</parameter>)</term>
2106 <term><replaceable>env</replaceable>.<methodname>Flatten</methodname>(<parameter>sequence</parameter>)</term>
2108 Takes a sequence (that is, a &Python; list or tuple)
2109 that may contain nested sequences
2110 and returns a flattened list containing
2111 all of the individual elements in any sequence.
2112 This can be helpful for collecting
2113 the lists returned by calls to Builders;
2114 other Builders will automatically
2115 flatten lists specified as input,
2116 but direct &Python; manipulation of
2117 these lists does not.
2125 foo = Object('foo.c')
2126 bar = Object('bar.c')
2128 # Because `foo' and `bar' are lists returned by the Object() Builder,
2129 # `objects' will be a list containing nested lists:
2130 objects = ['f1.o', foo, 'f2.o', bar, 'f3.o']
2132 # Passing such a list to another Builder is all right because
2133 # the Builder will flatten the list automatically:
2134 Program(source = objects)
2136 # If you need to manipulate the list directly using &Python;, you need to
2137 # call Flatten() yourself, or otherwise handle nested lists:
2138 for object in Flatten(objects):
2143 <varlistentry id="f-GetBuildFailures">
2144 <term><function>GetBuildFailures</function>()</term>
2146 Returns a list of exceptions for the
2147 actions that failed while
2148 attempting to build targets.
2149 Each element in the returned list is a
2150 <classname>BuildError</classname>
2152 with the following attributes
2153 that record various aspects
2154 of the build failure:
2158 <literal>.node</literal>
2159 The node that was being built
2160 when the build failure occurred.
2164 <literal>.status</literal>
2165 The numeric exit status
2166 returned by the command or Python function
2167 that failed when trying to build the
2172 <literal>.errstr</literal>
2173 The SCons error string
2174 describing the build failure.
2175 (This is often a generic
2176 message like "Error 2"
2177 to indicate that an executed
2178 command exited with a status of 2.)
2182 <literal>.filename</literal>
2183 The name of the file or
2184 directory that actually caused the failure.
2185 This may be different from the
2186 <literal>.node</literal>
2189 if an attempt to build a target named
2190 <filename>sub/dir/target</filename>
2192 <filename>sub/dir</filename>
2193 directory could not be created,
2195 <literal>.node</literal>
2197 <filename>sub/dir/target</filename>
2199 <literal>.filename</literal>
2201 <filename>sub/dir</filename>.
2205 <literal>.executor</literal>
2206 The SCons Executor object
2209 This can be used to retrieve
2210 the construction environment used
2211 for the failed action.
2215 <literal>.action</literal>
2216 The actual SCons Action object that failed.
2217 This will be one specific action
2218 out of the possible list of
2219 actions that would have been
2220 executed to build the target.
2224 <literal>.command</literal>
2225 The actual expanded command that was executed and failed,
2229 and other construction variables.
2234 &f-GetBuildFailures;
2236 will always return an empty list
2237 until any build failure has occurred,
2239 &f-GetBuildFailures;
2240 will always return an empty list
2243 files are being read.
2244 Its primary intended use is
2245 for functions that will be
2246 executed before SCons exits
2247 by passing them to the
2249 <function>atexit.register</function>()
2257 def print_build_failures():
2258 from SCons.Script import GetBuildFailures
2259 for bf in GetBuildFailures():
2260 print("%s failed: %s" % (bf.node, bf.errstr))
2262 atexit.register(print_build_failures)
2266 <varlistentry id="f-GetBuildPath">
2267 <term><function>GetBuildPath</function>(<parameter>file, [...]</parameter>)</term>
2268 <term><replaceable>env</replaceable>.<methodname>GetBuildPath</methodname>(<parameter>file, [...]</parameter>)</term>
2272 path name (or names) for the specified
2273 <parameter>file</parameter>
2276 <parameter>file</parameter>
2280 Nodes or strings representing path names.
2284 <varlistentry id="f-GetLaunchDir">
2285 <term><function>GetLaunchDir</function>()</term>
2287 Returns the absolute path name of the directory from which
2289 was initially invoked.
2290 This can be useful when using the
2291 <option>-u</option>,
2295 options, which internally
2296 change to the directory in which the
2302 <varlistentry id="f-GetOption">
2303 <term><function>GetOption</function>(<parameter>name</parameter>)</term>
2304 <term><replaceable>env</replaceable>.<methodname>GetOption</methodname>(<parameter>name</parameter>)</term>
2306 Query the value of settable options which may have been set
2307 on the command line, or by using the &f-link-SetOption; function.
2308 The value of the option is returned in a type matching how the
2309 option was declared - see the documentation for the
2310 corresponding command line option for information about each specific
2315 <parameter>name</parameter> can be an entry from the following table,
2316 which shows the corresponding command line arguments
2317 that could affect the value.
2318 <parameter>name</parameter> can be also be the destination
2319 variable name from a project-specific option added using the
2320 &f-link-AddOption; function, as long as that addition has been
2321 processed prior to the &f-GetOption; call in the &SConscript; files.
2324 <informaltable rowsep="1" colsep="1" frame="topbot">
2328 <entry align="left">Query name</entry>
2329 <entry align="left">Command-line options</entry>
2330 <entry align="left">Notes</entry>
2336 <entry><varname>cache_debug</varname></entry>
2337 <entry><option>--cache-debug</option></entry>
2340 <entry><varname>cache_disable</varname></entry>
2342 <option>--cache-disable</option>,
2343 <option>--no-cache</option>
2347 <entry><varname>cache_force</varname></entry>
2349 <option>--cache-force</option>,
2350 <option>--cache-populate</option>
2354 <entry><varname>cache_readonly</varname></entry>
2355 <entry><option>--cache-readonly</option></entry>
2358 <entry><varname>cache_show</varname></entry>
2359 <entry><option>--cache-show</option></entry>
2362 <entry><varname>clean</varname></entry>
2364 <option>-c</option>,
2365 <option>--clean</option>,
2366 <option>--remove</option>
2370 <entry><varname>climb_up</varname></entry>
2375 <option>--up</option>
2376 <option>--search_up</option>
2380 <entry><varname>config</varname></entry>
2381 <entry><option>--config</option></entry>
2384 <entry><varname>debug</varname></entry>
2385 <entry><option>--debug</option></entry>
2388 <entry><varname>directory</varname></entry>
2389 <entry><option>-C</option>, <option>--directory</option></entry>
2392 <entry><varname>diskcheck</varname></entry>
2393 <entry><option>--diskcheck</option></entry>
2396 <entry><varname>duplicate</varname></entry>
2397 <entry><option>--duplicate</option></entry>
2400 <entry><varname>enable_virtualenv</varname></entry>
2401 <entry><option>--enable-virtualenv</option></entry>
2404 <entry><varname>experimental</varname></entry>
2405 <entry><option>--experimental</option></entry>
2406 <entry><emphasis>since 4.2</emphasis></entry>
2409 <entry><varname>file</varname></entry>
2411 <option>-f</option>,
2412 <option>--file</option>,
2413 <option>--makefile</option>,
2414 <option>--sconstruct</option>
2418 <entry><varname>hash_format</varname></entry>
2419 <entry><option>--hash-format</option></entry>
2420 <entry><emphasis>since 4.2</emphasis></entry>
2423 <entry><varname>help</varname></entry>
2424 <entry><option>-h</option>, <option>--help</option></entry>
2427 <entry><varname>ignore_errors</varname></entry>
2428 <entry><option>-i</option>, <option>--ignore-errors</option></entry>
2431 <entry><varname>ignore_virtualenv</varname></entry>
2432 <entry><option>--ignore-virtualenv</option></entry>
2435 <entry><varname>implicit_cache</varname></entry>
2436 <entry><option>--implicit-cache</option></entry>
2439 <entry><varname>implicit_deps_changed</varname></entry>
2440 <entry><option>--implicit-deps-changed</option></entry>
2443 <entry><varname>implicit_deps_unchanged</varname></entry>
2444 <entry><option>--implicit-deps-unchanged</option></entry>
2447 <entry><varname>include_dir</varname></entry>
2448 <entry><option>-I</option>, <option>--include-dir</option></entry>
2451 <entry><varname>install_sandbox</varname></entry>
2452 <entry><option>--install-sandbox</option></entry>
2453 <entry>Available only if the &t-link-install; tool has been called</entry>
2456 <entry><varname>keep_going</varname></entry>
2457 <entry><option>-k</option>, <option>--keep-going</option></entry>
2460 <entry><varname>max_drift</varname></entry>
2461 <entry><option>--max-drift</option></entry>
2464 <entry><varname>md5_chunksize</varname></entry>
2466 <option>--hash-chunksize</option>,
2467 <option>--md5-chunksize</option>
2469 <entry><emphasis><option>--hash-chunksize</option> since 4.2</emphasis></entry>
2472 <entry><varname>no_exec</varname></entry>
2474 <option>-n</option>,
2475 <option>--no-exec</option>,
2476 <option>--just-print</option>,
2477 <option>--dry-run</option>,
2478 <option>--recon</option>
2482 <entry><varname>no_progress</varname></entry>
2483 <entry><option>-Q</option></entry>
2486 <entry><varname>num_jobs</varname></entry>
2487 <entry><option>-j</option>, <option>--jobs</option></entry>
2490 <entry><varname>package_type</varname></entry>
2491 <entry><option>--package-type</option></entry>
2492 <entry>Available only if the &t-link-packaging; tool has been called</entry>
2495 <entry><varname>profile_file</varname></entry>
2496 <entry><option>--profile</option></entry>
2499 <entry><varname>question</varname></entry>
2500 <entry><option>-q</option>, <option>--question</option></entry>
2503 <entry><varname>random</varname></entry>
2504 <entry><option>--random</option></entry>
2507 <entry><varname>repository</varname></entry>
2509 <option>-Y</option>,
2510 <option>--repository</option>,
2511 <option>--srcdir</option>
2515 <entry><varname>silent</varname></entry>
2517 <option>-s</option>,
2518 <option>--silent</option>,
2519 <option>--quiet</option>
2523 <entry><varname>site_dir</varname></entry>
2524 <entry><option>--site-dir</option>, <option>--no-site-dir</option></entry>
2527 <entry><varname>stack_size</varname></entry>
2528 <entry><option>--stack-size</option></entry>
2531 <entry><varname>taskmastertrace_file</varname></entry>
2532 <entry><option>--taskmastertrace</option></entry>
2535 <entry><varname>tree_printers</varname></entry>
2536 <entry><option>--tree</option></entry>
2539 <entry><varname>warn</varname></entry>
2540 <entry><option>--warn</option>, <option>--warning</option></entry>
2548 <varlistentry id="f-Glob">
2549 <term><function>Glob</function>(<parameter>pattern, [ondisk=True, source=False, strings=False, exclude=None]</parameter>)</term>
2550 <term><replaceable>env</replaceable>.<methodname>Glob</methodname>(<parameter>pattern, [ondisk=True, source=False, strings=False, exclude=None]</parameter>)</term>
2552 Returns a possibly empty list of Nodes (or strings) that match
2553 pathname specification <parameter>pattern</parameter>.
2554 <parameter>pattern</parameter> can be absolute,
2556 or (most commonly) relative to the directory of the current
2558 &f-Glob; matches both files stored on disk and Nodes
2559 which &SCons; already knows about, even if any corresponding
2560 file is not currently stored on disk.
2561 The evironment method form (&f-env-Glob;)
2562 performs string substition on
2563 <parameter>pattern</parameter>
2564 and returns whatever matches the resulting expanded pattern.
2565 The results are sorted, unlike for the similar &Python;
2566 <systemitem>glob.glob</systemitem> function,
2567 to ensure build order will be stable.
2571 <parameter>pattern</parameter>
2572 can contain POSIX-style shell metacharacters for matching:
2575 <informaltable rowsep="1" colsep="1" frame="topbot">
2579 <entry>Pattern</entry>
2580 <entry>Meaning</entry>
2585 <entry><literal>*</literal></entry>
2586 <entry>matches everything</entry>
2589 <entry><literal>?</literal></entry>
2590 <entry>matches any single character</entry>
2593 <entry><literal>[seq]</literal></entry>
2594 <entry>matches any character in <emphasis>seq</emphasis>
2595 (can be a list or a range).</entry>
2598 <entry><literal>[!seq]</literal></entry>
2599 <entry>matches any character not in <emphasis>seq</emphasis></entry>
2606 For a literal match, wrap the metacharacter in brackets to
2607 escape the normal behavior.
2608 For example, <literal>'[?]'</literal> matches the character
2609 <literal>'?'</literal>.
2613 Filenames starting with a dot are specially handled -
2614 they can only be matched by patterns that start with a dot
2615 (or have a dot immediately following a pathname separator
2616 character, or slash), they are not not matched by the metacharacters.
2617 Metacharacter matches also do not span directory separators.
2622 understands repositories
2626 and source directories
2630 and returns a Node (or string, if so configured) match
2631 in the local (SConscript) directory
2632 if a matching Node is found
2633 anywhere in a corresponding
2634 repository or source directory.
2639 <parameter>ondisk</parameter>
2640 argument evaluates false,
2641 the search for matches on disk is disabled,
2642 and only matches from
2643 already-configured File or Dir Nodes are returned.
2644 The default is to return Nodes for
2645 matches on disk as well.
2650 <parameter>source</parameter>
2651 argument evaluates true,
2652 and the local directory is a variant directory,
2653 then &f-Glob; returnes Nodes from
2654 the corresponding source directory,
2655 rather than the local directory.
2656 <!-- XXX what about generated files that don't exist in src but will be sources? -->
2661 <parameter>strings</parameter>
2662 argument evaluates true,
2664 returns matches as strings, rather than Nodes.
2665 The returned strings will be relative to
2666 the local (SConscript) directory.
2667 (Note that while this may make it easier to perform
2668 arbitrary manipulation of file names,
2669 it loses the context &SCons; would have in the Node,
2670 so if the returned strings are
2671 passed to a different
2674 any Node translation there will be relative
2685 <parameter>exclude</parameter>
2686 argument may be set to a pattern or a list of patterns
2687 descibing files or directories
2688 to filter out of the match list.
2689 Elements matching a least one specified pattern will be excluded.
2690 These patterns use the same syntax as for
2691 <parameter>pattern</parameter>.
2699 Program("foo", Glob("*.c"))
2700 Zip("/tmp/everything", Glob(".??*") + Glob("*"))
2701 sources = Glob("*.cpp", exclude=["os_*_specific_*.cpp"]) \
2702 + Glob("os_%s_specific_*.cpp" % currentOS)
2707 <varlistentry id="f-Help">
2708 <term><function>Help</function>(<parameter>text, append=False, local_only=False</parameter>)</term>
2709 <term><replaceable>env</replaceable>.<methodname>Help</methodname>(<parameter>text, append=False, local_only=False</parameter>)</term>
2711 Adds <parameter>text</parameter> to the help message shown when
2712 &scons; is called with the
2713 <option>-h</option> or <option>--help</option>
2717 On the first call to &f-Help;,
2718 if <parameter>append</parameter> is <constant>False</constant>
2719 (the default), any existing help text is discarded.
2720 The default help text is the help for the &scons;
2721 command itself plus help collected from any
2722 project-local &f-link-AddOption; calls.
2723 This is the help printed if &f-Help; has never been called.
2724 If <parameter>append</parameter> is <constant>True</constant>,
2725 <parameter>text</parameter> is appended to
2726 the existing help text.
2727 If <parameter>local_only</parameter> is also <constant>True</constant>
2728 (the default is <constant>False</constant>),
2729 the project-local help from &f-AddOption; calls is preserved
2730 in the help message but the &scons; command help is not.
2734 &f-Help; ignore the keyword arguments
2735 <parameter>append</parameter> and
2736 <parameter>local_only</parameter>
2737 and always append to the existing help text.
2740 <emphasis>Changed in 4.6.0</emphasis>: added <parameter>local_only</parameter>.
2745 <varlistentry id="f-Ignore">
2746 <term><function>Ignore</function>(<parameter>target, dependency</parameter>)</term>
2747 <term><replaceable>env</replaceable>.<methodname>Ignore</methodname>(<parameter>target, dependency</parameter>)</term>
2749 Ignores <parameter>dependency</parameter>
2751 <parameter>target</parameter> needs to be rebuilt.
2752 <parameter>target</parameter> and
2753 <parameter>dependency</parameter>
2754 can each be a single filename or Node
2755 or a list of filenames or Nodes.
2759 &f-Ignore; can also be used to
2760 remove a target from the default build
2761 by specifying the directory the target will be built in as
2762 <parameter>target</parameter>
2763 and the file you want to skip selecting for building as
2764 <parameter>dependency</parameter>.
2765 Note that this only removes the target from
2766 the default target selection algorithm:
2767 if it is a dependency of another object being
2768 built &SCons; still builds it normally.
2769 See the third and forth examples below.
2777 env.Ignore('foo', 'foo.c')
2778 env.Ignore('bar', ['bar1.h', 'bar2.h'])
2779 env.Ignore('.', 'foobar.obj')
2780 env.Ignore('bar', 'bar/foobar.obj')
2784 <varlistentry id="f-Import">
2785 <term><function>Import</function>(<parameter>vars...</parameter>)</term>
2786 <term><replaceable>env</replaceable>.<methodname>Import</methodname>(<parameter>vars...</parameter>)</term>
2788 Imports variables into the scope of the current SConscript file.
2789 <parameter>vars</parameter>
2790 must be strings representing names of variables
2791 which have been previously exported either by the
2792 &f-link-Export; function or by the
2793 &exports; argument to the
2794 &f-link-SConscript; function.
2795 Variables exported by the
2798 Multiple variable names can be passed to
2800 as separate arguments, as a list of strings,
2801 or as words in a space-separated string.
2802 The wildcard <literal>"*"</literal> can be used to import all
2803 available variables.
2807 If the imported variable is mutable,
2808 changes made locally will be reflected in the object the
2809 variable is bound to. This allows subsidiary SConscript files
2810 to contribute to building up, for example, a &consenv;.
2819 Import("env", "variable")
2820 Import(["env", "variable"])
2825 <varlistentry id="f-Literal">
2826 <term><function>Literal</function>(<parameter>string</parameter>)</term>
2827 <term><replaceable>env</replaceable>.<methodname>Literal</methodname>(<parameter>string</parameter>)</term>
2830 <parameter>string</parameter>
2831 will be preserved as-is
2832 and not have construction variables expanded.
2836 <varlistentry id="f-Local">
2837 <term><function>Local</function>(<parameter>targets</parameter>)</term>
2838 <term><replaceable>env</replaceable>.<methodname>Local</methodname>(<parameter>targets</parameter>)</term>
2841 <parameter>targets</parameter>
2842 will have copies made in the local tree,
2843 even if an already up-to-date copy
2844 exists in a repository.
2845 Returns a list of the target Node or Nodes.
2849 <varlistentry id="f-MergeFlags">
2850 <term><replaceable>env</replaceable>.<methodname>MergeFlags</methodname>(<parameter>arg, [unique]</parameter>)</term>
2853 <parameter>arg</parameter>
2854 into &consvars; in the current &consenv;.
2856 <parameter>arg</parameter>
2857 is not a dictionary,
2858 it is converted to one by calling
2859 &f-link-env-ParseFlags;
2861 before the values are merged.
2863 <parameter>arg</parameter>
2864 must be a single value,
2865 so multiple strings must
2866 be passed in as a list,
2867 not as separate arguments to
2872 If <literal>unique</literal> is true (the default),
2873 duplicate values are not stored.
2874 When eliminating duplicate values,
2875 any &consvars; that end with
2877 <literal>PATH</literal>
2878 keep the left-most unique value.
2879 All other &consvars; keep
2880 the right-most unique value.
2881 If <literal>unique</literal> is false,
2882 values are added even if they are duplicates.
2890 # Add an optimization flag to $CCFLAGS.
2891 env.MergeFlags('-O3')
2893 # Combine the flags returned from running pkg-config with an optimization
2894 # flag and merge the result into the construction variables.
2895 env.MergeFlags(['!pkg-config gtk+-2.0 --cflags', '-O3'])
2897 # Combine an optimization flag with the flags returned from running pkg-config
2898 # twice and merge the result into the construction variables.
2902 '!pkg-config gtk+-2.0 --cflags --libs',
2903 '!pkg-config libpng12 --cflags --libs',
2909 <varlistentry id="f-NoCache">
2910 <term><function>NoCache</function>(<parameter>target, ...</parameter>)</term>
2911 <term><replaceable>env</replaceable>.<methodname>NoCache</methodname>(<parameter>target, ...</parameter>)</term>
2913 Specifies a list of files which should
2914 <emphasis>not</emphasis>
2915 be cached whenever the
2917 method has been activated.
2918 The specified targets may be a list
2919 or an individual target.
2923 Multiple files should be specified
2924 either as separate arguments to the
2926 method, or as a list.
2928 will also accept the return value of any of the construction environment
2935 on directories and other non-File Node types has no effect because
2936 only File Nodes are cached.
2945 NoCache(env.Program('hello', 'hello.c'))
2949 <varlistentry id="f-NoClean">
2950 <term><function>NoClean</function>(<parameter>target, ...</parameter>)</term>
2951 <term><replaceable>env</replaceable>.<methodname>NoClean</methodname>(<parameter>target, ...</parameter>)</term>
2953 Specifies a list of files or directories which should
2954 <emphasis>not</emphasis>
2955 be removed whenever the targets (or their dependencies)
2956 are specified with the
2958 command line option.
2959 The specified targets may be a list
2960 or an individual target.
2964 and prevent each specified target
2965 from being removed by calls to the
2971 Multiple files or directories should be specified
2972 either as separate arguments to the
2974 method, or as a list.
2976 will also accept the return value of any of the construction environment
2983 for a target overrides calling
2985 for the same target,
2986 and any targets passed to both functions will
2987 <emphasis>not</emphasis>
2999 NoClean(env.Program('hello', 'hello.c'))
3003 <varlistentry id="f-ParseConfig">
3004 <term><replaceable>env</replaceable>.<methodname>ParseConfig</methodname>(<parameter>command, [function, unique]</parameter>)</term>
3006 Updates the current &consenv; with the values extracted
3007 from the output of running external <parameter>command</parameter>,
3008 by passing it to a helper <parameter>function</parameter>.
3009 <parameter>command</parameter> may be a string
3010 or a list of strings representing the command and
3012 If <parameter>function</parameter>
3013 is omitted or <constant>None</constant>,
3014 &f-link-env-MergeFlags; is used.
3016 duplicate values are not
3017 added to any construction variables;
3019 <parameter>unique=False</parameter>
3020 to allow duplicate values to be added.
3024 <parameter>command</parameter> is executed using the
3025 SCons execution environment (that is, the &consvar;
3026 &cv-link-ENV; in the current &consenv;).
3027 If <parameter>command</parameter> needs additional information
3028 to operate properly, that needs to be set in the execution environment.
3029 For example, <command>pkg-config</command>
3030 may need a custom value set in the <envar>PKG_CONFIG_PATH</envar>
3031 environment variable.
3035 &f-env-MergeFlags; needs to understand
3036 the output produced by <parameter>command</parameter>
3037 in order to distribute it to appropriate &consvars;.
3038 &f-env-MergeFlags; uses a separate function to
3039 do that processing -
3040 see &f-link-env-ParseFlags; for the details, including a
3041 a table of options and corresponding construction variables.
3042 To provide alternative processing of the output of
3043 <parameter>command</parameter>,
3044 you can suppply a custom
3045 <parameter>function</parameter>,
3046 which must accept three arguments:
3047 the &consenv; to modify,
3048 a string argument containing the output from running
3049 <parameter>command</parameter>,
3051 <parameter>unique</parameter> flag.
3055 <varlistentry id="f-ParseDepends">
3056 <term><function>ParseDepends</function>(<parameter>filename, [must_exist, only_one]</parameter>)</term>
3057 <term><replaceable>env</replaceable>.<methodname>ParseDepends</methodname>(<parameter>filename, [must_exist, only_one]</parameter>)</term>
3059 Parses the contents of <parameter>filename</parameter>
3060 as a list of dependencies in the style of
3063 <application>mkdep</application>,
3064 and explicitly establishes all of the listed dependencies.
3070 if <parameter>filename</parameter>
3073 <parameter>must_exist</parameter>
3074 argument may be set to <constant>True</constant>
3076 raise an exception if the file does not exist,
3077 or is otherwise inaccessible.
3082 <parameter>only_one</parameter>
3083 argument may be set to <constant>True</constant>
3084 to have &SCons; raise an exception
3085 if the file contains dependency
3086 information for more than one target.
3087 This can provide a small sanity check
3088 for files intended to be generated
3089 by, for example, the
3090 <literal>gcc -M</literal>
3092 which should typically only
3093 write dependency information for
3094 one output file into a corresponding
3095 <filename>.d</filename>
3100 <parameter>filename</parameter>
3101 and all of the files listed therein
3102 will be interpreted relative to
3103 the directory of the
3105 file which calls the
3111 <varlistentry id="f-ParseFlags">
3112 <term><replaceable>env</replaceable>.<methodname>ParseFlags</methodname>(<parameter>flags, ...</parameter>)</term>
3114 Parses one or more strings containing
3115 typical command-line flags for GCC-style tool chains
3116 and returns a dictionary with the flag values
3117 separated into the appropriate SCons construction variables.
3118 Intended as a companion to the
3119 &f-link-env-MergeFlags;
3120 method, but allows for the values in the returned dictionary
3121 to be modified, if necessary,
3122 before merging them into the construction environment.
3125 will call this method if its argument is not a dictionary,
3126 so it is usually not necessary to call
3128 directly unless you want to manipulate the values.)
3132 If the first character in any string is
3133 an exclamation mark (<literal>!</literal>),
3134 the rest of the string is executed as a command,
3135 and the output from the command is
3136 parsed as GCC tool chain command-line flags
3137 and added to the resulting dictionary.
3138 This can be used to call a <filename>*-config</filename>
3139 command typical of the POSIX programming environment
3141 <command>pkg-config</command>).
3142 Note that such a command is executed using the
3143 SCons execution environment;
3144 if the command needs additional information,
3145 that information needs to be explicitly provided.
3146 See &f-link-ParseConfig; for more details.
3150 Flag values are translated according to the prefix found,
3151 and added to the following construction variables:
3155 -arch CCFLAGS, LINKFLAGS
3157 -framework FRAMEWORKS
3158 -frameworkdir= FRAMEWORKPATH
3159 -fmerge-all-constants CCFLAGS, LINKFLAGS
3160 -fopenmp CCFLAGS, LINKFLAGS
3161 -fsanitize CCFLAGS, LINKFLAGS
3164 -isysroot CCFLAGS, LINKFLAGS
3171 -mno-cygwin CCFLAGS, LINKFLAGS
3173 -openmp CCFLAGS, LINKFLAGS
3174 -pthread CCFLAGS, LINKFLAGS
3176 -Wa, ASFLAGS, CCFLAGS
3183 + CCFLAGS, LINKFLAGS
3187 Any other strings not associated with options
3188 are assumed to be the names of libraries
3191 construction variable.
3195 Examples (all of which produce the same result):
3199 dict = env.ParseFlags('-O2 -Dfoo -Dbar=1')
3200 dict = env.ParseFlags('-O2', '-Dfoo', '-Dbar=1')
3201 dict = env.ParseFlags(['-O2', '-Dfoo -Dbar=1'])
3202 dict = env.ParseFlags('-O2', '!echo -Dfoo -Dbar=1')
3206 <varlistentry id="f-Platform">
3207 <term><function>Platform</function>(<parameter>plat</parameter>)</term>
3208 <term><replaceable>env</replaceable>.<methodname>Platform</methodname>(<parameter>plat</parameter>)</term>
3210 When called as a global function,
3211 returns a callable platform object
3212 selected by <parameter>plat</parameter>
3213 (defaults to the detected platform for the
3215 that can be used to initialize
3216 a construction environment by passing it as the
3217 <parameter>platform</parameter> keyword argument to the
3218 &f-link-Environment; function.
3226 env = Environment(platform=Platform('win32'))
3230 When called as a method of an environment,
3231 calls the platform object indicated by
3232 <parameter>plat</parameter>
3233 to update that environment.
3237 env.Platform('posix')
3241 See the manpage section "Construction Environments" for more details.
3245 <varlistentry id="f-Precious">
3246 <term><function>Precious</function>(<parameter>target, ...</parameter>)</term>
3247 <term><replaceable>env</replaceable>.<methodname>Precious</methodname>(<parameter>target, ...</parameter>)</term>
3250 <varname>target</varname>
3251 as precious so it is not deleted before it is rebuilt. Normally
3253 deletes a target before building it.
3254 Multiple targets can be passed in to a single call to
3259 <varlistentry id="f-Prepend">
3260 <term><replaceable>env</replaceable>.<methodname>Prepend</methodname>(<parameter>key=val, [...]</parameter>)</term>
3262 Prepend values to &consvars; in the current &consenv;,
3263 Works like &f-link-env-Append; (see for details),
3264 except that values are added to the front,
3265 rather than the end, of any existing value of the &consvar;
3273 env.Prepend(CCFLAGS='-g ', FOO=['foo.yyy'])
3277 See also &f-link-env-Append;,
3278 &f-link-env-AppendUnique;
3279 and &f-link-env-PrependUnique;.
3283 <varlistentry id="f-PrependENVPath">
3284 <term><replaceable>env</replaceable>.<methodname>PrependENVPath</methodname>(<parameter>name, newpath, [envname, sep, delete_existing=True]</parameter>)</term>
3286 Prepend path elements specified by <parameter>newpath</parameter>
3287 to the given search path string or list <parameter>name</parameter>
3288 in mapping <parameter>envname</parameter> in the &consenv;.
3289 Supplying <parameter>envname</parameter> is optional:
3290 the default is the execution environment &cv-link-ENV;.
3291 Optional <parameter>sep</parameter> is used as the search path separator,
3292 the default is the platform's separator (<systemitem>os.pathsep</systemitem>).
3293 A path element will only appear once.
3294 Any duplicates in <parameter>newpath</parameter> are dropped,
3295 keeping the first appearing (to preserve path order).
3296 If <parameter>delete_existing</parameter>
3297 is <constant>False</constant>
3298 any addition duplicating an existing path element is ignored;
3299 if <parameter>delete_existing</parameter>
3300 is <constant>True</constant> (the default) the existing value will
3301 be dropped and the path element will be inserted at the beginning.
3302 To help maintain uniqueness all paths are normalized (using
3303 <systemitem>os.path.normpath</systemitem>
3305 <systemitem>os.path.normcase</systemitem>).
3313 print('before:', env['ENV']['INCLUDE'])
3314 include_path = '/foo/bar:/foo'
3315 env.PrependENVPath('INCLUDE', include_path)
3316 print('after:', env['ENV']['INCLUDE'])
3319 <para>Yields:</para>
3323 after: /foo/bar:/foo:/biz
3327 See also &f-link-env-AppendENVPath;.
3332 <varlistentry id="f-PrependUnique">
3333 <term><replaceable>env</replaceable>.<methodname>PrependUnique</methodname>(<parameter>key=val, [...], [delete_existing=False]</parameter>)</term>
3335 Prepend values to &consvars; in the current &consenv;,
3336 maintaining uniqueness.
3337 Works like &f-link-env-Append;,
3338 except that values are added to the front,
3339 rather than the end, of the &consvar;,
3340 and values that would become duplicates
3342 If <parameter>delete_existing</parameter>
3343 is set to a true value, then for any duplicate,
3344 the existing instance of <parameter>val</parameter> is first removed,
3345 then <parameter>val</parameter> is inserted,
3346 having the effect of moving it to the front.
3354 env.PrependUnique(CCFLAGS='-g', FOO=['foo.yyy'])
3358 See also &f-link-env-Append;,
3359 &f-link-env-AppendUnique;
3360 and &f-link-env-Prepend;.
3364 <varlistentry id="f-Progress">
3365 <term><function>Progress</function>(<parameter>callable, [interval]</parameter>)</term>
3366 <term><function>Progress</function>(<parameter>string, [interval, file, overwrite]</parameter>)</term>
3367 <term><function>Progress</function>(<parameter>list_of_strings, [interval, file, overwrite]</parameter>)</term>
3369 Allows SCons to show progress made during the build
3370 by displaying a string or calling a function while
3371 evaluating Nodes (e.g. files).
3375 If the first specified argument is a Python callable
3376 (a function or an object that has a
3377 <methodname>__call__</methodname> method),
3378 the function will be called
3380 <varname>interval</varname>
3381 times a Node is evaluated (default <constant>1</constant>).
3382 The callable will be passed the evaluated Node
3383 as its only argument.
3384 (For future compatibility,
3385 it's a good idea to also add
3386 <parameter>*args</parameter>
3388 <parameter>**kwargs</parameter>
3389 as arguments to your function or method signatures.
3390 This will prevent the code from breaking
3391 if &SCons; ever changes the interface
3392 to call the function with additional arguments in the future.)
3396 An example of a simple custom progress function
3397 that prints a string containing the Node name
3402 def my_progress_function(node, *args, **kwargs):
3403 print('Evaluating node %s!' % node)
3404 Progress(my_progress_function, interval=10)
3408 A more complicated example of a custom progress display object
3409 that prints a string containing a count
3410 every 100 evaluated Nodes.
3412 <literal>\r</literal>
3414 at the end so that the string
3415 will overwrite itself on a display:
3420 class ProgressCounter(object):
3422 def __call__(self, node, *args, **kw):
3424 sys.stderr.write('Evaluated %s nodes\r' % self.count)
3426 Progress(ProgressCounter(), interval=100)
3430 If the first argument to
3431 &f-Progress; is a string or list of strings,
3432 it is taken as text to be displayed every
3433 <varname>interval</varname>
3435 If the first argument is a list of strings,
3436 then each string in the list will be displayed
3437 in rotating fashion every
3438 <varname>interval</varname>
3443 The default is to print the string on standard output.
3444 An alternate output stream
3445 may be specified with the
3446 <parameter>file</parameter>
3447 keyword argument, which the
3448 caller must pass already opened.
3452 The following will print a series of dots
3453 on the error output,
3454 one dot for every 100 evaluated Nodes:
3459 Progress('.', interval=100, file=sys.stderr)
3463 If the string contains the verbatim substring
3464 <literal>$TARGET;</literal>,
3465 it will be replaced with the Node.
3466 Note that, for performance reasons, this is
3467 <emphasis>not</emphasis>
3468 a regular SCons variable substition,
3469 so you can not use other variables
3470 or use curly braces.
3471 The following example will print the name of
3472 every evaluated Node,
3473 using a carriage return)
3474 (<literal>\r</literal>)
3475 to cause each line to overwritten by the next line,
3477 <parameter>overwrite</parameter>
3478 keyword argument (default <literal>False</literal>)
3479 to make sure the previously-printed
3480 file name is overwritten with blank spaces:
3485 Progress('$TARGET\r', overwrite=True)
3489 A list of strings can be used to implement a "spinner"
3490 on the user's screen as follows, changing every
3491 five evaluated Nodes:
3495 Progress(['-\r', '\\\r', '|\r', '/\r'], interval=5)
3499 <varlistentry id="f-Pseudo">
3500 <term><function>Pseudo</function>(<parameter>target, ...</parameter>)</term>
3501 <term><replaceable>env</replaceable>.<methodname>Pseudo</methodname>(<parameter>target, ...</parameter>)</term>
3503 This indicates that each given
3504 <varname>target</varname>
3505 should not be created by the build rule, and if the target is created,
3506 an error will be generated. This is similar to the gnu make .PHONY
3507 target. However, in the vast majority of cases, an
3509 is more appropriate.
3511 Multiple targets can be passed in to a single call to
3516 <varlistentry id="f-PyPackageDir">
3517 <term><function>PyPackageDir</function>(<parameter>modulename</parameter>)</term>
3518 <term><replaceable>env</replaceable>.<methodname>PyPackageDir</methodname>(<parameter>modulename</parameter>)</term>
3520 This returns a Directory Node similar to Dir.
3521 The python module / package is looked up and if located
3522 the directory is returned for the location.
3523 <parameter>modulename</parameter>
3524 Is a named python package / module to
3525 lookup the directory for it's location.
3529 <parameter>modulename</parameter>
3530 is a list, SCons returns a list of Dir nodes.
3531 Construction variables are expanded in
3532 <parameter>modulename</parameter>.
3536 <varlistentry id="f-Replace">
3537 <term><replaceable>env</replaceable>.<methodname>Replace</methodname>(<parameter>key=val, [...]</parameter>)</term>
3539 Replaces construction variables in the Environment
3540 with the specified keyword arguments.
3548 env.Replace(CCFLAGS='-g', FOO='foo.xxx')
3552 <varlistentry id="f-Repository">
3553 <term><function>Repository</function>(<parameter>directory</parameter>)</term>
3554 <term><replaceable>env</replaceable>.<methodname>Repository</methodname>(<parameter>directory</parameter>)</term>
3557 <parameter>directory</parameter>
3558 is a repository to be searched for files.
3562 and each one adds to the list of
3563 repositories that will be searched.
3569 a repository is a copy of the source tree,
3570 from the top-level directory on down,
3572 both source files and derived files
3573 that can be used to build targets in
3574 the local source tree.
3575 The canonical example would be an
3576 official source tree maintained by an integrator.
3577 If the repository contains derived files,
3578 then the derived files should have been built using
3580 so that the repository contains the necessary
3581 signature information to allow
3583 to figure out when it is appropriate to
3584 use the repository copy of a derived file,
3585 instead of building one locally.
3589 Note that if an up-to-date derived file
3590 already exists in a repository,
3593 <emphasis>not</emphasis>
3594 make a copy in the local directory tree.
3595 In order to guarantee that a local copy
3603 <varlistentry id="f-Requires">
3604 <term><function>Requires</function>(<parameter>target, prerequisite</parameter>)</term>
3605 <term><replaceable>env</replaceable>.<methodname>Requires</methodname>(<parameter>target, prerequisite</parameter>)</term>
3607 Specifies an order-only relationship
3608 between the specified target file(s)
3609 and the specified prerequisite file(s).
3610 The prerequisite file(s)
3611 will be (re)built, if necessary,
3612 <emphasis>before</emphasis>
3614 but the target file(s) do not actually
3615 depend on the prerequisites
3616 and will not be rebuilt simply because
3617 the prerequisite file(s) change.
3625 env.Requires('foo', 'file-that-must-be-built-before-foo')
3629 <varlistentry id="f-Return">
3630 <term><function>Return</function>(<parameter>[vars..., stop=True]</parameter>)</term>
3632 Return to the calling SConscript, optionally
3633 returning the values of variables named in
3634 <varname>vars</varname>.
3635 Multiple strings contaning variable names may be passed to
3636 &f-Return;. A string containing white space
3637 is split into individual variable names.
3638 Returns the value if one variable is specified,
3639 else returns a tuple of values.
3640 Returns an empty tuple if <parameter>vars</parameter>
3645 By default &Return; stops processing the current SConscript
3646 and returns immediately.
3648 <literal>stop</literal>
3650 may be set to a false value
3651 to continue processing the rest of the SConscript
3654 call (this was the default behavior prior to SCons 0.98.)
3655 However, the values returned
3656 are still the values of the variables in the named
3657 <varname>vars</varname>
3668 # Returns no values (evaluates False)
3671 # Returns the value of the 'foo' Python variable.
3674 # Returns the values of the Python variables 'foo' and 'bar'.
3675 Return("foo", "bar")
3677 # Returns the values of Python variables 'val1' and 'val2'.
3682 <varlistentry id="f-Scanner">
3683 <term><function>Scanner</function>(<parameter>function, [name, argument, skeys, path_function, node_class, node_factory, scan_check, recursive]</parameter>)</term>
3684 <term><replaceable>env</replaceable>.<methodname>Scanner</methodname>(<parameter>function, [name, argument, skeys, path_function, node_class, node_factory, scan_check, recursive]</parameter>)</term>
3686 Creates a Scanner object for
3688 <parameter>function</parameter>.
3689 See manpage section "Scanner Objects"
3690 for a complete explanation of the arguments and behavior.
3694 <varlistentry id="f-SConscript">
3695 <term><function>SConscript</function>(<parameter>scriptnames, [exports, variant_dir, duplicate, must_exist]</parameter>)</term>
3696 <term><replaceable>env</replaceable>.<methodname>SConscript</methodname>(<parameter>scriptnames, [exports, variant_dir, duplicate, must_exist]</parameter>)</term>
3697 <term><function>SConscript</function>(<parameter>dirs=subdirs, [name=scriptname, exports, variant_dir, duplicate, must_exist]</parameter>)</term>
3698 <term><replaceable>env</replaceable>.<methodname>SConscript</methodname>(<parameter>dirs=subdirs, [name=scriptname, exports, variant_dir, duplicate, must_exist]</parameter>)</term>
3700 Executes subsidiary SConscript (build configuration) file(s).
3701 There are two ways to call the
3702 &f-SConscript; function.
3706 The first calling style is to supply
3707 one or more SConscript file names
3708 as the first positional argument,
3709 which can be a string or a list of strings.
3710 If there is a second positional argument,
3711 it is treated as if the
3712 <varname>exports</varname>
3713 keyword argument had been given (see below).
3717 SConscript('SConscript') # run SConscript in the current directory
3718 SConscript('src/SConscript') # run SConscript in the src directory
3719 SConscript(['src/SConscript', 'doc/SConscript'])
3720 SConscript(Split('src/SConscript doc/SConscript'))
3721 config = SConscript('MyConfig.py')
3725 The second calling style is to omit the positional argument naming
3726 the script and instead specify directory names using the
3727 <varname>dirs</varname> keyword argument.
3728 The value can be a string or list of strings.
3731 will execute a subsidiary configuration file named
3732 &SConscript; (by default)
3733 in each of the specified directories.
3734 You may specify a name other than
3736 by supplying an optional
3737 <varname>name</varname>=<replaceable>scriptname</replaceable>
3739 The first three examples below have the same effect
3740 as the first three examples above:
3743 SConscript(dirs='.') # run SConscript in the current directory
3744 SConscript(dirs='src') # run SConscript in the src directory
3745 SConscript(dirs=['src', 'doc'])
3746 SConscript(dirs=['sub1', 'sub2'], name='MySConscript')
3751 <varname>exports</varname>
3752 keyword argument specifies variables to make available
3753 for use by the called SConscripts,
3754 which are evaluated in an isolated context
3755 and otherwise do not have access to local variables
3756 from the calling SConscript.
3757 The value may be a string or list of strings representing
3758 variable names, or a dictionary mapping local names to
3759 the names they can be imported by.
3760 For the first (scriptnames) calling style,
3761 a second positional argument will also be interpreted as
3762 <varname>exports</varname>;
3763 the second (directory) calling style accepts no
3764 positional arguments and must use the keyword form.
3765 These variables are locally exported only to the called
3766 SConscript file(s), and take precedence over any same-named
3767 variables in the global pool managed by the
3770 <!-- If multiple dirs are provided, each script gets a fresh export. -->
3771 The subsidiary SConscript files
3774 function to import the variables into their local scope.
3778 foo = SConscript('sub/SConscript', exports='env')
3779 SConscript('dir/SConscript', exports=['env', 'variable'])
3780 SConscript(dirs='subdir', exports='env variable')
3781 SConscript(dirs=['one', 'two', 'three'], exports='shared_info')
3786 <varname>variant_dir</varname>
3787 argument is present, it causes an effect equivalent to the
3788 &f-link-VariantDir; function,
3789 but in effect only within the scope of the &f-SConscript; call.
3790 The <varname>variant_dir</varname>
3791 argument is interpreted relative to the directory of the
3792 <emphasis>calling</emphasis> SConscript file.
3793 The source directory is the directory in which the
3794 <emphasis>called</emphasis> SConscript
3795 file resides and the SConscript
3796 file is evaluated as if it were in the
3797 <varname>variant_dir</varname>
3801 SConscript('src/SConscript', variant_dir='build')
3809 VariantDir('build', 'src')
3810 SConscript('build/SConscript')
3814 If the sources are in the same directory as the
3819 SConscript('SConscript', variant_dir='build')
3827 VariantDir('build', '.')
3828 SConscript('build/SConscript')
3833 <varname>duplicate</varname> argument is
3834 interpreted as for &f-link-VariantDir;.
3835 If the <varname>variant_dir</varname> argument
3836 is omitted, the <varname>duplicate</varname> argument is ignored.
3837 See the description of
3839 for additional details and restrictions.
3845 <varname>variant_dir</varname>
3847 <varname>src_dir</varname>
3849 xxxxx everything is in a state of confusion.
3852 SConscript(dirs = 'src', variant_dir = 'build', src_dir = '.')
3853 runs src/SConscript in build/src, but
3854 SConscript(dirs = 'lib', variant_dir = 'build', src_dir = 'src')
3855 runs lib/SConscript (in lib!). However,
3856 SConscript(dirs = 'src', variant_dir = 'build', src_dir = 'src')
3857 runs src/SConscript in build. Moreover,
3858 SConscript(dirs = 'src/lib', variant_dir = 'build', src_dir = 'src')
3859 runs src/lib/SConscript in build/lib. Moreover,
3860 SConscript(dirs = 'build/src/lib', variant_dir = 'build', src_dir = 'src')
3861 can't find build/src/lib/SConscript, even though it ought to exist.
3870 and what about this alternative?
3871 TODO??? SConscript('build/SConscript', src_dir='src')
3877 <varname>must_exist</varname>
3878 is <constant>True</constant> (the default),
3879 an exception is raised if a requested
3880 SConscript file is not found.
3881 To allow missing scripts to be silently ignored
3882 (the default behavior prior to &SCons; version 3.1),
3884 <literal>must_exist=False</literal> in the &f-SConscript; call.
3888 <emphasis>Changed in 4.6.0</emphasis>: <parameter>must_exist</parameter>
3889 now defaults to <constant>True</constant>.
3893 Here are some composite examples:
3897 # collect the configuration information and use it to build src and doc
3898 shared_info = SConscript('MyConfig.py')
3899 SConscript('src/SConscript', exports='shared_info')
3900 SConscript('doc/SConscript', exports='shared_info')
3904 # build debugging and production versions. SConscript
3905 # can use Dir('.').path to determine variant.
3906 SConscript('SConscript', variant_dir='debug', duplicate=0)
3907 SConscript('SConscript', variant_dir='prod', duplicate=0)
3911 # build debugging and production versions. SConscript
3912 # is passed flags to use.
3913 opts = { 'CPPDEFINES' : ['DEBUG'], 'CCFLAGS' : '-pgdb' }
3914 SConscript('SConscript', variant_dir='debug', duplicate=0, exports=opts)
3915 opts = { 'CPPDEFINES' : ['NODEBUG'], 'CCFLAGS' : '-O' }
3916 SConscript('SConscript', variant_dir='prod', duplicate=0, exports=opts)
3920 # build common documentation and compile for different architectures
3921 SConscript('doc/SConscript', variant_dir='build/doc', duplicate=0)
3922 SConscript('src/SConscript', variant_dir='build/x86', duplicate=0)
3923 SConscript('src/SConscript', variant_dir='build/ppc', duplicate=0)
3927 &f-SConscript; returns the values of any variables
3928 named by the executed SConscript file(s) in arguments
3929 to the &f-link-Return; function.
3930 If a single &f-SConscript; call causes multiple scripts to
3931 be executed, the return value is a tuple containing
3932 the returns of each of the scripts. If an executed
3933 script does not explicitly call &Return;, it returns
3934 <constant>None</constant>.
3939 <varlistentry id="f-SConscriptChdir">
3940 <term><function>SConscriptChdir</function>(<parameter>value</parameter>)</term>
3944 changes its working directory
3945 to the directory in which each
3946 subsidiary SConscript file lives
3947 while reading and processing that script.
3948 This behavior may be disabled
3949 by specifying an argument which
3950 evaluates false, in which case
3952 will stay in the top-level directory
3953 while reading all SConscript files.
3954 (This may be necessary when building from repositories,
3955 when all the directories in which SConscript files may be found
3956 don't necessarily exist locally.)
3957 You may enable and disable
3958 this ability by calling
3968 SConscriptChdir(False)
3969 SConscript('foo/SConscript') # will not chdir to foo
3970 SConscriptChdir(True)
3971 SConscript('bar/SConscript') # will chdir to bar
3975 <varlistentry id="f-SConsignFile">
3976 <term><function>SConsignFile</function>(<parameter>[name, dbm_module]</parameter>)</term>
3977 <term><replaceable>env</replaceable>.<methodname>SConsignFile</methodname>(<parameter>[name, dbm_module]</parameter>)</term>
3979 Specify where to store the &SCons; file signature database,
3980 and which database format to use.
3981 This may be useful to specify alternate
3982 database files and/or file locations for different types of builds.
3985 The optional <parameter>name</parameter> argument
3986 is the base name of the database file(s).
3987 If not an absolute path name,
3988 these are placed relative to the directory containing the
3989 top-level &SConstruct; file.
3991 <filename>.sconsign</filename>.
3992 The actual database file(s) stored on disk
3993 may have an appropriate suffix appended
3995 <parameter>dbm_module</parameter>
3998 The optional <parameter>dbm_module</parameter>
3999 argument specifies which
4000 &Python; database module to use
4001 for reading/writing the file.
4002 The module must be imported first;
4003 then the imported module name
4004 is passed as the argument.
4005 The default is a custom
4006 <systemitem>SCons.dblite</systemitem>
4007 module that uses pickled
4008 &Python; data structures,
4009 which works on all &Python; versions.
4010 See documentation of the &Python;
4011 <systemitem>dbm</systemitem> module
4012 for other available types.
4015 If called with no arguments,
4016 the database will default to
4017 <filename>.sconsign.dblite</filename>
4018 in the top directory of the project,
4019 which is also the default if
4020 if &f-SConsignFile; is not called.
4023 The setting is global, so the only difference
4024 between the global function and the environment method form
4025 is variable expansion on <parameter>name</parameter>.
4026 There should only be one active call to this
4027 function/method in a given build setup.
4031 <parameter>name</parameter>
4033 <constant>None</constant>,
4035 will store file signatures
4037 <filename>.sconsign</filename>
4038 file in each directory,
4039 not in a single combined database file.
4040 This is a backwards-compatibility meaure to support
4041 what was the default behavior
4042 prior to &SCons; 0.97 (i.e. before 2008).
4043 Use of this mode is discouraged and may be
4044 deprecated in a future &SCons; release.
4052 # Explicitly stores signatures in ".sconsign.dblite"
4053 # in the top-level SConstruct directory (the default behavior).
4056 # Stores signatures in the file "etc/scons-signatures"
4057 # relative to the top-level SConstruct directory.
4058 # SCons will add a database suffix to this name.
4059 SConsignFile("etc/scons-signatures")
4061 # Stores signatures in the specified absolute file name.
4062 # SCons will add a database suffix to this name.
4063 SConsignFile("/home/me/SCons/signatures")
4065 # Stores signatures in a separate .sconsign file
4066 # in each directory.
4069 # Stores signatures in a GNU dbm format .sconsign file
4071 SConsignFile(dbm_module=dbm.gnu)
4075 <varlistentry id="f-SetDefault">
4076 <term><replaceable>env</replaceable>.<methodname>SetDefault</methodname>(<parameter>key=val, [...]</parameter>)</term>
4078 Sets construction variables to default values specified with the keyword
4079 arguments if (and only if) the variables are not already set.
4080 The following statements are equivalent:
4084 env.SetDefault(FOO='foo')
4085 if 'FOO' not in env:
4090 <varlistentry id="f-SetOption">
4091 <term><function>SetOption</function>(<parameter>name, value</parameter>)</term>
4092 <term><replaceable>env</replaceable>.<methodname>SetOption</methodname>(<parameter>name, value</parameter>)</term>
4094 Sets &scons; option variable <parameter>name</parameter>
4095 to <parameter>value</parameter>.
4096 These options are all also settable via
4097 command-line options but the variable name
4098 may differ from the command-line option name -
4099 see the table for correspondences.
4100 A value set via command-line option will take
4101 precedence over one set with &f-SetOption;, which
4102 allows setting a project default in the scripts and
4103 temporarily overriding it via command line.
4104 &f-SetOption; calls can also be placed in the
4105 <filename>site_init.py</filename> file.
4109 See the documentation in the manpage for the
4110 corresponding command line option for information about each specific option.
4111 The <parameter>value</parameter> parameter is mandatory,
4112 for option values which are boolean in nature
4113 (that is, the command line option does not take an argument)
4114 use a <parameter>value</parameter>
4115 which evaluates to true (e.g. <constant>True</constant>,
4116 <constant>1</constant>) or false (e.g. <constant>False</constant>,
4117 <constant>0</constant>).
4121 Options which affect the reading and processing of SConscript files
4122 are not settable using &f-SetOption; since those files must
4123 be read in order to find the &f-SetOption; call in the first place.
4127 The settable variables with their associated command-line options are:
4130 <informaltable rowsep="1" colsep="1" frame="topbot">
4134 <entry align="left">Settable name</entry>
4135 <entry align="left">Command-line options</entry>
4136 <entry align="left">Notes</entry>
4142 <entry><varname>clean</varname></entry>
4144 <option>-c</option>,
4145 <option>--clean</option>,
4146 <option>--remove</option>
4151 <entry><varname>diskcheck</varname></entry>
4152 <entry><option>--diskcheck</option></entry>
4156 <entry><varname>duplicate</varname></entry>
4157 <entry><option>--duplicate</option></entry>
4161 <entry><varname>experimental</varname></entry>
4162 <entry><option>--experimental</option></entry>
4163 <entry><emphasis>since 4.2</emphasis></entry>
4167 <entry><varname>hash_chunksize</varname></entry>
4168 <entry><option>--hash-chunksize</option></entry>
4170 Actually sets <varname>md5_chunksize</varname>.
4171 <emphasis>since 4.2</emphasis>
4176 <entry><varname>hash_format</varname></entry>
4177 <entry><option>--hash-format</option></entry>
4178 <entry><emphasis>since 4.2</emphasis></entry>
4182 <entry><varname>help</varname></entry>
4183 <entry><option>-h</option>, <option>--help</option></entry>
4187 <entry><varname>implicit_cache</varname></entry>
4188 <entry><option>--implicit-cache</option></entry>
4192 <entry><varname>implicit_deps_changed</varname></entry>
4193 <entry><option>--implicit-deps-changed</option></entry>
4195 Also sets <varname>implicit_cache</varname>.
4196 <emphasis>(settable since 4.2)</emphasis>
4201 <entry><varname>implicit_deps_unchanged</varname></entry>
4202 <entry><option>--implicit-deps-unchanged</option></entry>
4204 Also sets <varname>implicit_cache</varname>.
4205 <emphasis>(settable since 4.2)</emphasis>
4210 <entry><varname>max_drift</varname></entry>
4211 <entry><option>--max-drift</option></entry>
4215 <entry><varname>md5_chunksize</varname></entry>
4216 <entry><option>--md5-chunksize</option></entry>
4220 <entry><varname>no_exec</varname></entry>
4222 <option>-n</option>,
4223 <option>--no-exec</option>,
4224 <option>--just-print</option>,
4225 <option>--dry-run</option>,
4226 <option>--recon</option>
4231 <entry><varname>no_progress</varname></entry>
4232 <entry><option>-Q</option></entry>
4235 <para>If <varname>no_progress</varname> is set via &f-SetOption;
4236 in an SConscript file
4237 (but not if set in a <filename>site_init.py</filename> file)
4238 there will still be an initial status message about
4239 reading SConscript files since &SCons; has
4240 to start reading them before it can see the
4248 <entry><varname>num_jobs</varname></entry>
4249 <entry><option>-j</option>, <option>--jobs</option></entry>
4253 <entry><varname>random</varname></entry>
4254 <entry><option>--random</option></entry>
4258 <entry><varname>silent</varname></entry>
4260 <option>-s</option>,
4261 <option>--silent</option>,
4262 <option>--quiet</option>
4267 <entry><varname>stack_size</varname></entry>
4268 <entry><option>--stack-size</option></entry>
4272 <entry><varname>warn</varname></entry>
4273 <entry><option>--warn</option></entry>
4285 SetOption('max_drift', 0)
4289 <varlistentry id="f-SideEffect">
4290 <term><function>SideEffect</function>(<parameter>side_effect, target</parameter>)</term>
4291 <term><replaceable>env</replaceable>.<methodname>SideEffect</methodname>(<parameter>side_effect, target</parameter>)</term>
4294 <parameter>side_effect</parameter>
4295 as a side effect of building
4296 <parameter>target</parameter>.
4298 <parameter>side_effect</parameter>
4300 <parameter>target</parameter>
4301 can be a list, a file name, or a node.
4302 A side effect is a target file that is created or updated
4303 as a side effect of building other targets.
4304 For example, a Windows PDB
4305 file is created as a side effect of building the .obj
4306 files for a static library,
4307 and various log files are created updated
4308 as side effects of various TeX commands.
4309 If a target is a side effect of multiple build commands,
4311 will ensure that only one set of commands
4312 is executed at a time.
4313 Consequently, you only need to use this method
4314 for side-effect targets that are built as a result of
4315 multiple build commands.
4319 Because multiple build commands may update
4320 the same side effect file,
4322 <parameter>side_effect</parameter>
4324 <emphasis>not</emphasis>
4325 automatically removed
4327 <parameter>target</parameter>
4331 (Note, however, that the
4332 <parameter>side_effect</parameter>
4333 might be removed as part of
4334 cleaning the directory in which it lives.)
4335 If you want to make sure the
4336 <parameter>side_effect</parameter>
4337 is cleaned whenever a specific
4338 <parameter>target</parameter>
4340 you must specify this explicitly
4349 This function returns the list of side effect Node objects that were successfully added.
4350 If the list of side effects contained any side effects that had already been added,
4351 they are not added and included in the returned list.
4355 <varlistentry id="f-Split">
4356 <term><function>Split</function>(<parameter>arg</parameter>)</term>
4357 <term><replaceable>env</replaceable>.<methodname>Split</methodname>(<parameter>arg</parameter>)</term>
4359 If <parameter>arg</parameter> is a string,
4360 splits on whitespace and returns a list of
4361 strings without whitespace.
4362 This mode is the most common case,
4363 and can be used to split a list of filenames
4364 (for example) rather than having to type them as a
4365 list of individually quoted words.
4366 If <parameter>arg</parameter> is a list or tuple
4367 returns the list or tuple unchanged.
4368 If <parameter>arg</parameter> is any other type of object,
4369 returns a list containing just the object.
4370 These non-string cases do not actually do any spliting,
4371 but allow an argument variable to be passed to
4372 &f-Split; without having to first check its type.
4380 files = Split("f1.c f2.c f3.c")
4381 files = env.Split("f4.c f5.c f6.c")
4390 <varlistentry id="f-subst">
4391 <term><replaceable>env</replaceable>.<methodname>subst</methodname>(<parameter>input, [raw, target, source, conv]</parameter>)</term>
4393 Performs &consvar; interpolation
4394 (<firstterm>substitution</firstterm>)
4395 on <parameter>input</parameter>,
4396 which can be a string or a sequence.
4397 Substitutable elements take the form
4398 <literal>${<replaceable>expression</replaceable>}</literal>,
4399 although if there is no ambiguity in recognizing the element,
4400 the braces can be omitted.
4401 A literal <emphasis role="bold">$</emphasis> can be entered by
4402 using <emphasis role="bold">$$</emphasis>.
4407 leading or trailing white space will
4408 be removed from the result,
4409 and all sequences of white space
4410 will be compressed to a single space character.
4412 <literal>$(</literal>
4414 <literal>$)</literal>
4415 character sequences will be stripped from the returned string,
4417 <parameter>raw</parameter>
4418 argument may be set to
4419 <literal>1</literal>
4420 if you want to preserve white space and
4421 <literal>$(</literal>-<literal>$)</literal>
4424 <parameter>raw</parameter>
4425 argument may be set to
4426 <literal>2</literal>
4427 if you want to additionally discard
4428 all characters between any
4429 <literal>$(</literal>
4431 <literal>$)</literal>
4433 (as is done for signature calculation).
4437 If <parameter>input</parameter> is a sequence
4439 the individual elements of
4440 the sequence will be expanded,
4441 and the results will be returned as a list.
4446 <parameter>target</parameter>
4448 <parameter>source</parameter>
4450 must be set to lists of
4451 target and source nodes, respectively,
4458 to be available for expansion.
4459 This is usually necessary if you are
4462 from within a &Python; function used
4467 Returned string values or sequence elements
4468 are converted to their string representation by default.
4470 <parameter>conv</parameter>
4472 may specify a conversion function
4473 that will be used in place of
4475 For example, if you want &Python; objects
4476 (including SCons Nodes)
4477 to be returned as &Python; objects,
4478 you can use a &Python;
4479 lambda expression to pass in an unnamed function
4480 that simply returns its unconverted argument.
4488 print(env.subst("The C compiler is: $CC"))
4490 def compile(target, source, env):
4491 sourceDir = env.subst(
4497 source_nodes = env.subst('$EXPAND_TO_NODELIST', conv=lambda x: x)
4501 <varlistentry id="f-Tag">
4502 <term><function>Tag</function>(<parameter>node, tags</parameter>)</term>
4504 Annotates file or directory Nodes with
4505 information about how the
4507 Builder should package those files or directories.
4508 All Node-level tags are optional.
4516 # makes sure the built library will be installed with 644 file access mode
4517 Tag(Library('lib.c'), UNIX_ATTR="0o644")
4519 # marks file2.txt to be a documentation file
4520 Tag('file2.txt', DOC)
4524 <varlistentry id="f-Tool">
4525 <term><function>Tool</function>(<parameter>name, [toolpath, **kwargs]</parameter>)</term>
4526 <term><replaceable>env</replaceable>.<methodname>Tool</methodname>(<parameter>name, [toolpath, **kwargs]</parameter>)</term>
4528 Locates the tool specification module <parameter>name</parameter>
4529 and returns a callable tool object for that tool.
4530 The tool module is searched for in standard locations
4531 and in any paths specified by the optional
4532 <parameter>toolpath</parameter> parameter.
4533 The standard locations are &SCons;' own internal
4534 path for tools plus the toolpath, if any (see the
4535 <emphasis role="bold">Tools</emphasis> section in the manual page
4537 Any additional keyword arguments
4538 <parameter>kwargs</parameter> are passed
4539 to the tool module's <function>generate</function> function
4540 during tool object construction.
4544 When called, the tool object
4545 updates a &consenv; with &consvars; and arranges
4546 any other initialization
4547 needed to use the mechanisms that tool describes.
4551 When the &f-env-Tool; form is used,
4552 the tool object is automatically called to update <varname>env</varname>
4553 and the value of <parameter>tool</parameter> is
4554 appended to the &cv-link-TOOLS;
4555 &consvar; in that environment.
4559 <emphasis>Changed in version 4.2:</emphasis>
4560 &f-env-Tool; now returns the tool object,
4561 previously it did not return (i.e. returned <constant>None</constant>).
4570 env.Tool('opengl', toolpath=['build/tools'])
4574 When the global function &f-Tool; form is used,
4575 the tool object is constructed but not called,
4576 as it lacks the context of an environment to update.
4577 The tool object can be passed to an
4578 &f-link-Environment; or &f-link-Clone; call
4579 as part of the <parameter>tools</parameter> keyword argument,
4580 in which case the tool is applied to the environment being constructed,
4581 or it can be called directly,
4582 in which case a &consenv; to update must be
4583 passed as the argument.
4584 Either approach will also update the
4585 &cv-TOOLS; &consvar;.
4593 env = Environment(tools=[Tool('msvc')])
4596 msvctool = Tool('msvc')
4597 msvctool(env) # adds 'msvc' to the TOOLS variable
4598 gltool = Tool('opengl', toolpath = ['tools'])
4599 gltool(env) # adds 'opengl' to the TOOLS variable
4603 <varlistentry id="f-ValidateOptions">
4604 <term><function>ValidateOptions</function>(<parameter>[throw_exception=False]</parameter>)</term>
4606 Check that all the options specified on the command line are either
4607 &SCons; built-in options or defined via calls to &f-link-AddOption;.
4608 &SCons; will eventually fail on unknown options anyway, but calling
4609 this function allows the build to "fail fast" before executing
4610 expensive logic later in the build.
4614 This function should only be called after the last &f-AddOption;
4615 call in your &SConscript; logic.
4616 Be aware that some tools call &f-AddOption;, if you are getting
4617 error messages for arguments that they add, you will need to ensure
4618 that those tools are loaded before calling &f-ValidateOptions;.
4622 If there are any unknown command line options, &f-ValidateOptions;
4623 prints an error message and exits with an error exit status.
4624 If the optional <parameter>throw_exception</parameter> argument is
4625 <literal>True</literal> (default is <literal>False</literal>),
4626 a <exceptionname>SConsBadOptionError</exceptionname> is raised,
4627 giving an opportunity for the &SConscript; logic to catch that
4628 exception and handle invalid options appropriately. Note that
4629 this exception name needs to be imported (see the example below).
4633 A common build problem is typos (or thinkos) - a user enters an option
4634 that is just a little off the expected value, or perhaps a different
4635 word with a similar meaning. It may be useful to abort the build
4636 before going too far down the wrong path. For example:
4640 $ <userinput>scons --compilers=mingw</userinput> # the correct flag is --compiler
4644 Here &SCons; could go off and run a bunch of configure steps with
4645 the default value of <literal>--compiler</literal>, since the
4646 incorrect command line did not actually supply a value to it,
4647 costing developer time to track down why the configure logic
4648 made the "wrong" choices. This example shows catching this:
4651 <programlisting language="python">
4652 from SCons.Script.SConsOptions import SConsBadOptionError
4662 # ... other SConscript logic ...
4665 ValidateOptions(throw_exception=True)
4666 except SConsBadOptionError as e:
4667 print(f"ValidateOptions detects a fail: ", e.opt_str)
4671 <para><emphasis>New in version 4.5.0</emphasis></para>
4675 <varlistentry id="f-Value">
4676 <term><function>Value</function>(<parameter>value, [built_value], [name]</parameter>)</term>
4677 <term><replaceable>env</replaceable>.<methodname>Value</methodname>(<parameter>value, [built_value], [name]</parameter>)</term>
4679 Returns a Node object representing the specified &Python; value. Value
4680 Nodes can be used as dependencies of targets. If the result of
4682 <function>str</function>(<parameter>value</parameter>)
4683 changes between SCons runs, any targets depending on
4684 <function>Value</function>(<parameter>value</parameter>)
4686 (This is true even when using timestamps to decide if
4687 files are up-to-date.)
4688 When using timestamp source signatures, Value Nodes'
4689 timestamps are equal to the system time when the Node is created.
4693 The returned Value Node object has a
4694 <function>write</function>()
4695 method that can be used to "build" a Value Node
4696 by setting a new value.
4698 <parameter>built_value</parameter>
4699 argument can be specified
4700 when the Value Node is created
4701 to indicate the Node should already be considered
4703 There is a corresponding
4704 <function>read</function>()
4705 method that will return the built value of the Node.
4709 The optional <parameter>name</parameter> parameter can be provided as an
4710 alternative name for the resulting <literal>Value</literal> node;
4711 this is advised if the <parameter>value</parameter> parameter
4712 cannot be converted to a string.
4716 <emphasis>Changed in version 4.0:</emphasis>
4717 the <parameter>name</parameter> parameter was added.
4727 def create(target, source, env):
4728 # A function that will write a 'prefix=$SOURCE'
4729 # string into the file name specified as the
4731 with open(str(target[0]), 'wb') as f:
4732 f.write('prefix=' + source[0].get_contents())
4734 # Fetch the prefix= argument, if any, from the command
4735 # line, and use /usr/local as the default.
4736 prefix = ARGUMENTS.get('prefix', '/usr/local')
4738 # Attach a .Config() builder for the above function action
4739 # to the construction environment.
4740 env['BUILDERS']['Config'] = Builder(action=create)
4741 env.Config(target='package-config', source=Value(prefix))
4743 def build_value(target, source, env):
4744 # A function that "builds" a Python Value by updating
4745 # the Python value with the contents of the file
4746 # specified as the source of the Builder call ($SOURCE).
4747 target[0].write(source[0].get_contents())
4749 output = env.Value('before')
4750 input = env.Value('after')
4752 # Attach a .UpdateValue() builder for the above function
4753 # action to the construction environment.
4754 env['BUILDERS']['UpdateValue'] = Builder(action=build_value)
4755 env.UpdateValue(target=Value(output), source=Value(input))
4759 <varlistentry id="f-VariantDir">
4760 <term><function>VariantDir</function>(<parameter>variant_dir, src_dir, [duplicate]</parameter>)</term>
4761 <term><replaceable>env</replaceable>.<methodname>VariantDir</methodname>(<parameter>variant_dir, src_dir, [duplicate]</parameter>)</term>
4763 Sets up a mapping to define a variant build directory in
4764 <parameter>variant_dir</parameter>.
4765 <parameter>src_dir</parameter> may not be underneath
4766 <parameter>variant_dir</parameter>.
4767 A &f-VariantDir; mapping is global, even if called using the
4768 &f-env-VariantDir; form.
4770 can be called multiple times with the same
4771 <parameter>src_dir</parameter>
4772 to set up multiple variant builds with different options.
4776 Note if <parameter>variant_dir</parameter>
4777 is not under the project top directory,
4778 target selection rules will not pick targets in the
4779 variant directory unless they are explicitly specified.
4783 When files in <parameter>variant_dir</parameter> are referenced,
4784 &SCons; backfills as needed with files from <parameter>src_dir</parameter>
4785 to create a complete build directory.
4787 physically duplicates the source files, SConscript files,
4788 and directory structure as needed into the variant directory.
4789 Thus, a build performed in the variant directory is guaranteed to be identical
4790 to a build performed in the source directory even if
4791 intermediate source files are generated during the build,
4792 or if preprocessors or other scanners search for included files
4793 using paths relative to the source file,
4794 or if individual compilers or other invoked tools are hard-coded
4795 to put derived files in the same directory as source files.
4796 Only the files &SCons; calculates are needed for the build are
4797 duplicated into <parameter>variant_dir</parameter>.
4798 If possible on the platform,
4799 the duplication is performed by linking rather than copying.
4800 This behavior is affected by the
4801 <option>--duplicate</option>
4802 command-line option.
4806 Duplicating the source files may be disabled by setting the
4807 <parameter>duplicate</parameter>
4809 <constant>False</constant>.
4812 to invoke Builders using the path names of source files in
4813 <parameter>src_dir</parameter>
4814 and the path names of derived files within
4815 <parameter>variant_dir</parameter>.
4816 This is more efficient than duplicating,
4817 and is safe for most builds;
4818 revert to <literal>duplicate=True</literal>
4819 if it causes problems.
4824 works most naturally when used with a subsidiary SConscript file.
4825 The subsidiary SConscript file must be called as if it were in
4826 <parameter>variant_dir</parameter>,
4827 regardless of the value of
4828 <parameter>duplicate</parameter>.
4829 When calling an SConscript file, you can use the
4830 <parameter>exports</parameter> keyword argument
4831 to pass parameters (individually or as an appropriately set up environment)
4832 so the SConscript can pick up the right settings for that variant build.
4833 The SConscript must &f-link-Import; these to use them. Example:
4837 env1 = Environment(...settings for variant1...)
4838 env2 = Environment(...settings for variant2...)
4840 # run src/SConscript in two variant directories
4841 VariantDir('build/variant1', 'src')
4842 SConscript('build/variant1/SConscript', exports={"env": env1})
4843 VariantDir('build/variant2', 'src')
4844 SConscript('build/variant2/SConscript', exports={"env": env2})
4849 &f-link-SConscript; function
4850 for another way to specify a variant directory
4851 in conjunction with calling a subsidiary SConscript file.
4859 # use names in the build directory, not the source directory
4860 VariantDir('build', 'src', duplicate=0)
4861 Program('build/prog', 'build/source.c')
4863 # this builds both the source and docs in a separate subtree
4864 VariantDir('build', '.', duplicate=0)
4865 SConscript(dirs=['build/src','build/doc'])
4867 # same as previous example, but only uses SConscript
4868 SConscript(dirs='src', variant_dir='build/src', duplicate=0)
4869 SConscript(dirs='doc', variant_dir='build/doc', duplicate=0)
4873 <varlistentry id="f-WhereIs">
4874 <term><function>WhereIs</function>(<parameter>program, [path, pathext, reject]</parameter>)</term>
4875 <term><replaceable>env</replaceable>.<methodname>WhereIs</methodname>(<parameter>program, [path, pathext, reject]</parameter>)</term>
4877 Searches for the specified executable
4878 <parameter>program</parameter>,
4879 returning the full path to the program
4880 or <constant>None</constant>.
4883 When called as a &consenv; method,
4884 searches the paths in the
4885 <parameter>path</parameter> keyword argument,
4886 or if <constant>None</constant> (the default)
4887 the paths listed in the &consenv;
4888 (<varname>env</varname><literal>['ENV']['PATH']</literal>).
4889 The external environment's path list
4890 (<literal>os.environ['PATH']</literal>)
4891 is used as a fallback if the key
4892 <varname>env</varname><literal>['ENV']['PATH']</literal>
4896 On Windows systems, searches for executable
4897 programs with any of the file extensions listed in the
4898 <parameter>pathext</parameter> keyword argument,
4899 or if <constant>None</constant> (the default)
4900 the pathname extensions listed in the &consenv;
4901 (<varname>env</varname><literal>['ENV']['PATHEXT']</literal>).
4902 The external environment's pathname extensions list
4903 (<literal>os.environ['PATHEXT']</literal>)
4904 is used as a fallback if the key
4905 <varname>env</varname><literal>['ENV']['PATHEXT']</literal>
4909 When called as a global function, uses the external
4911 <literal>os.environ['PATH']</literal>
4913 <literal>os.environ['PATHEXT']</literal>,
4915 <parameter>path</parameter> and
4916 <parameter>pathext</parameter> are
4917 <constant>None</constant>.
4923 <parameter>reject</parameter>