Skip to content

Commit cfb272b

Browse files
committed
A few more Variables doc tweaks
Signed-off-by: Mats Wichmann <[email protected]>
1 parent edab5fe commit cfb272b

File tree

2 files changed

+69
-43
lines changed

2 files changed

+69
-43
lines changed

doc/man/scons.xml

Lines changed: 68 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4716,22 +4716,26 @@ call the &Variables; factory function:</para>
47164716
<varlistentry id="v-Variables">
47174717
<term><function>Variables</function>([<parameter>files, [args]]</parameter>)</term>
47184718
<listitem>
4719-
<para>If <parameter>files</parameter> is a file or list of files,
4719+
<para>If <parameter>files</parameter> is a filename or list of filenames,
47204720
they are considered to be &Python; scripts which will
4721-
be executed when the
4721+
be executed to set variables when the
47224722
<link linkend='v-Update'><function>Update</function></link>
47234723
method is called -
47244724
this allows the use of &Python; syntax in the assignments.
4725+
A file can be the result of an earlier call to the
4726+
<link linkend='v-Save'>&Save;</link> method.
47254727
If <parameter>files</parameter> is not specified,
47264728
or the
47274729
<parameter>files</parameter>
47284730
argument is
47294731
<constant>None</constant>,
4730-
then no files will be read
4731-
(supplying <constant>None</constant> is required
4732+
then no files will be read.
4733+
Supplying <constant>None</constant> is required
47324734
if there are no files but you want to specify
47334735
<parameter>args</parameter> as a positional argument;
4734-
this can be omitted if using the keyword argument style).
4736+
this can be omitted if using the keyword argument style.
4737+
If any of <parameter>files</parameter> is missing,
4738+
it is silently skipped.
47354739
</para>
47364740

47374741
<para>
@@ -4751,10 +4755,11 @@ will be added to those obtained from
47514755
<parameter>files</parameter>, if any.
47524756
Keys from <parameter>args</parameter>
47534757
take precendence over same-named keys from <parameter>files</parameter>.
4754-
The most common usage is to pass the
4755-
&ARGUMENTS; dictionary that holds variables
4756-
specified on the command line,
4757-
allowing you to indicate that if a setting appears
4758+
If omittted, the default is the
4759+
<link linkend="v-ARGUMENTS">&ARGUMENTS;</link>
4760+
dictionary that holds build variables
4761+
specified on the command line.
4762+
Using &ARGUMENTS; allows you to indicate that if a setting appears
47584763
on both the command line and in the file(s),
47594764
the command line setting is preferred.
47604765
However, any dictionary can be passed.
@@ -4827,20 +4832,25 @@ not to any stored-values files.
48274832
<para>Add a customizable &consvar; to the &Variables; object.
48284833
<parameter>key</parameter>
48294834
is either the name of the variable,
4830-
or a tuple (or list), in which case
4831-
the first item in the tuple is taken as the variable name,
4835+
or a sequence of strings, in which case
4836+
the first item in the sequence is taken as the variable name,
48324837
and any remaining values are considered aliases for the variable.
4838+
<parameter>key</parameter> is mandatory,
4839+
there is no default.
48334840
<parameter>help</parameter>
48344841
is the help text for the variable
4835-
(default empty string).
4842+
(defaults to an empty string).
48364843
<parameter>default</parameter>
48374844
is the default value of the variable
4838-
(default <constant>None</constant>).
4845+
(defaults to <constant>None</constant>).
48394846
</para>
48404847

48414848
<para>
48424849
If the optional <parameter>validator</parameter> argument is supplied,
4843-
it is a callback function to validate the value of the variable.
4850+
it is a callback function to validate the value of the variable
4851+
when the variables are processed
4852+
(that is, when the <link linkend='v-Update'>&Update;</link>
4853+
method runs).
48444854
A validator function must accept three arguments:
48454855
<parameter>key</parameter>,
48464856
<parameter>value</parameter>
@@ -4853,23 +4863,34 @@ No return value is expected from the validator.
48534863
<para>
48544864
If the optional <parameter>converter</parameter> argument is supplied,
48554865
it is a callback function to convert the value into
4856-
one suitable for adding to the environment,
4857-
and should accept either a value
4858-
or a value and &consenv; as parameters.
4866+
one suitable for adding to the &consenv;.
4867+
A converter function must accept the
4868+
<parameter>value</parameter> argument,
4869+
and may declare <parameter>env</parameter>
4870+
as a second argument if it needs access to the
4871+
&consenv; while validating - the function will be called appropriately.
48594872
The converter is called before the validator;
48604873
it must return a value, which is then passed to the
4861-
<parameter>validator</parameter> (if any)
4862-
and finally added to the &consenv; -
4863-
it is recommended to avoid performing validation
4864-
checks in the converter.
4874+
<parameter>validator</parameter> (if any) for checking.
4875+
In general, the converter should not fail,
4876+
leaving validation checks to the validator,
4877+
although if an operation is impossible to complete
4878+
or there is no separate validator
4879+
it can raise a <exceptionname>ValueError</exceptionname>.
48654880
</para>
48664881

48674882
<para>
48684883
As a special case, if <parameter>key</parameter>
4869-
is a tuple (or list) and is the <emphasis>only</emphasis>
4870-
argument, the tuple is unpacked into the five parameters
4871-
listed above left to right, with any missing members filled with
4872-
the respective default values. This form allows &Add;
4884+
is a sequence and is the <emphasis>only</emphasis>
4885+
argument to &Add;, it is unpacked into the five parameters
4886+
<parameter>key</parameter>,
4887+
<parameter>help</parameter>,
4888+
<parameter>default</parameter>,
4889+
<parameter>validator</parameter> and
4890+
<parameter>converter</parameter>,
4891+
with any missing members from the right filled in with
4892+
the respective default values.
4893+
This form allows it
48734894
to consume a tuple emitted by the convenience functions
48744895
<link linkend='v-BoolVariable'>&BoolVariable;</link>,
48754896
<link linkend='v-EnumVariable'>&EnumVariable;</link>,
@@ -4902,15 +4923,12 @@ to a &Variables; object in one call;
49024923
equivalent to calling
49034924
<link linkend='v-Add'><function>Add</function></link>
49044925
multiple times.
4905-
The <parameter>args</parameter>
4906-
are tuples (or lists)
4907-
that contain the arguments
4908-
for an individual call to the &Add; method.
4909-
Since tuples are not &Python; mappings,
4910-
the arguments cannot use the keyword form,
4911-
but rather are positional arguments as documented for &Add;:
4912-
a required name, the other four optional,
4913-
but must be in the specified order if used.
4926+
Each <parameter>args</parameter> member
4927+
must be a tuple that contains the arguments
4928+
for an individual call to the &Add; method
4929+
using the "special case" form;
4930+
the other calling styles (individual positional
4931+
arguments and/or keyword arguments) are not supported.
49144932
</para>
49154933

49164934
<programlisting language="python">
@@ -4927,19 +4945,26 @@ opt.AddVariables(
49274945
<varlistentry id="v-Update">
49284946
<term><replaceable>vars</replaceable>.<function>Update</function>(<parameter>env, [args]</parameter>)</term>
49294947
<listitem>
4930-
<para>Process the arguments given as
4931-
<parameter>files</parameter> and/or
4932-
<parameter>args</parameter>
4933-
when the &Variables; object was created,
4948+
<para>Process the input sources recorded
4949+
when the &Variables; object was initialized
49344950
and update
49354951
<parameter>env</parameter>
49364952
with the customized &consvars;.
4937-
Any specified variables that are not
4953+
The names of any variables in the input sources that are not
49384954
configured in the &Variables; object
4939-
will be saved and may be retrieved using the
4955+
are recorded and may be retrieved using the
49404956
<link linkend='v-UnknownVariables'>&UnknownVariables;</link>
49414957
method.</para>
49424958

4959+
<para>
4960+
If the optional
4961+
<parameter>args</parameter>
4962+
argument is provided, it is a dictionary of variables
4963+
to use in place of the one saved when
4964+
<link linkend='v-Variables'>&Variables;</link>
4965+
was called.
4966+
</para>
4967+
49434968
<para>Normally, &Update; is not called directly,
49444969
but rather invoked indirectly by passing the &Variables; object to
49454970
the &f-link-Environment; function:</para>
@@ -5177,9 +5202,9 @@ Any value that is not in
51775202
will raise an error.
51785203
More than one value may be specified,
51795204
separated by commas.
5180-
The default may be a string of
5181-
comma-separated default values,
5182-
or a list of the default values.
5205+
<parameter>default</parameter> may be specified
5206+
either as a string of comma-separated value,
5207+
or as a list of values.
51835208
The optional
51845209
<parameter>map</parameter>
51855210
argument is a dictionary

doc/scons.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@
279279
<!ENTITY Return "<function xmlns='http://www.scons.org/dbxsd/v1.0'>Return</function>">
280280
<!ENTITY RuleSet "<function xmlns='http://www.scons.org/dbxsd/v1.0'>RuleSet</function>">
281281
<!ENTITY Salt "<function xmlns='http://www.scons.org/dbxsd/v1.0'>Salt</function>">
282+
<!ENTITY Save "<function xmlns='http://www.scons.org/dbxsd/v1.0'>Save</function>">
282283
<!ENTITY SetBuildSignatureType "<function xmlns='http://www.scons.org/dbxsd/v1.0'>SetBuildSignatureType</function>">
283284
<!ENTITY SetContentSignatureType "<function xmlns='http://www.scons.org/dbxsd/v1.0'>SetContentSignatureType</function>">
284285
<!ENTITY SetDefault "<function xmlns='http://www.scons.org/dbxsd/v1.0'>SetDefault</function>">

0 commit comments

Comments
 (0)