Skip to content

Commit 77dd793

Browse files
authored
Merge pull request #3804 from mwichmann/variant-doc
Tweaks to variantdir documentation
2 parents 1a8ef80 + 593b725 commit 77dd793

File tree

5 files changed

+134
-213
lines changed

5 files changed

+134
-213
lines changed

SCons/Environment.xml

Lines changed: 36 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3171,8 +3171,8 @@ def create(target, source, env):
31713171
# A function that will write a 'prefix=$SOURCE'
31723172
# string into the file name specified as the
31733173
# $TARGET.
3174-
f = open(str(target[0]), 'wb')
3175-
f.write('prefix=' + source[0].get_contents())
3174+
with open(str(target[0]), 'wb') as f:
3175+
f.write('prefix=' + source[0].get_contents())
31763176

31773177
# Fetch the prefix= argument, if any, from the command
31783178
# line, and use /usr/local as the default.
@@ -3206,90 +3206,75 @@ env.UpdateValue(target = Value(output), source = Value(input))
32063206
</arguments>
32073207
<summary>
32083208
<para>
3209-
Use the
3210-
&f-VariantDir;
3211-
function to create a copy of your sources in another location:
3212-
if a name under
3213-
<parameter>variant_dir</parameter>
3214-
is not found but exists under
3215-
<parameter>src_dir</parameter>,
3216-
the file or directory is copied to
3217-
<parameter>variant_dir</parameter>.
3218-
Target files can be built in a different directory
3219-
than the original sources by simply refering to the sources (and targets)
3220-
within the variant tree.
3221-
</para>
3222-
3223-
<para>
3209+
Sets up an alternate build location.
3210+
When building in the <parameter>variant_dir</parameter>,
3211+
&SCons; backfills as needed with files from <parameter>src_dir</parameter>
3212+
to create a complete build directory.
32243213
&f-VariantDir;
32253214
can be called multiple times with the same
32263215
<parameter>src_dir</parameter>
32273216
to set up multiple builds with different options
3228-
(<parameter>variants</parameter>).
3217+
(<emphasis>variants</emphasis>).
3218+
</para>
3219+
3220+
<para>
32293221
The
3230-
<parameter>src_dir</parameter>
3231-
location must be in or underneath the SConstruct file's directory, and
3232-
<parameter>variant_dir</parameter>
3222+
<parameter>variant</parameter>
3223+
location must be in or underneath the project top directory,
3224+
and <parameter>src_dir</parameter>
32333225
may not be underneath
3234-
<parameter>src_dir</parameter>.
3235-
<!--
3236-
TODO: Can the above restrictions be clarified or relaxed?
3237-
TODO: The latter restriction is clearly not completely right;
3238-
TODO: src_dir = '.' works fine with a build dir under it.
3239-
-->
3226+
<parameter>variant_dir</parameter>.
32403227
</para>
32413228

32423229
<para>
3243-
The default behavior is for
3244-
&scons;
3245-
to physically duplicate the source files in the variant tree.
3230+
By default, &SCons;
3231+
physically duplicates the source files and SConscript files
3232+
as needed into the variant tree.
32463233
Thus, a build performed in the variant tree is guaranteed to be identical
32473234
to a build performed in the source tree even if
32483235
intermediate source files are generated during the build,
3249-
or preprocessors or other scanners search for included files
3236+
or if preprocessors or other scanners search for included files
32503237
relative to the source file,
3251-
or individual compilers or other invoked tools are hard-coded
3238+
or if individual compilers or other invoked tools are hard-coded
32523239
to put derived files in the same directory as source files.
3240+
Only the files &SCons; calculates are needed for the build are
3241+
duplicated into <parameter>variant_dir</parameter>.
32533242
</para>
32543243

32553244
<para>
32563245
If possible on the platform,
3257-
the duplication is performed by linking rather than copying;
3258-
see also the
3246+
the duplication is performed by linking rather than copying.
3247+
This behavior is affected by the
32593248
<option>--duplicate</option>
32603249
command-line option.
3261-
Moreover, only the files needed for the build are duplicated;
3262-
files and directories that are not used are not present in
3263-
<parameter>variant_dir</parameter>.
32643250
</para>
32653251

32663252
<para>
3267-
Duplicating the source tree may be disabled by setting the
3268-
<literal>duplicate</literal>
3253+
Duplicating the source files may be disabled by setting the
3254+
<parameter>duplicate</parameter>
32693255
argument to
3270-
<literal>0</literal>
3271-
(zero).
3256+
<constant>False</constant>.
32723257
This will cause
3273-
&scons;
3258+
&SCons;
32743259
to invoke Builders using the path names of source files in
32753260
<parameter>src_dir</parameter>
32763261
and the path names of derived files within
32773262
<parameter>variant_dir</parameter>.
3278-
This is always more efficient than
3279-
<literal>duplicate=1</literal>,
3280-
and is usually safe for most builds
3281-
(but see above for cases that may cause problems).
3263+
This is more efficient than
3264+
<literal>duplicate=True</literal>,
3265+
and is safe for most builds;
3266+
revert to <constant>True</constant>
3267+
if it causes problems.
32823268
</para>
32833269

32843270
<para>
3285-
Note that
32863271
&f-VariantDir;
3287-
works most naturally with a subsidiary SConscript file.
3288-
However, you would then call the subsidiary SConscript file
3289-
not in the source directory, but in the
3272+
works most naturally with used with a subsidiary SConscript file.
3273+
The subsidiary SConscript file is called as if it
3274+
were in
32903275
<parameter>variant_dir</parameter>,
32913276
regardless of the value of
3292-
<literal>duplicate</literal>.
3277+
<parameter>duplicate</parameter>.
32933278
This is how you tell
32943279
&scons;
32953280
which variant of a source tree to build:
@@ -3319,15 +3304,11 @@ Examples:
33193304
# use names in the build directory, not the source directory
33203305
VariantDir('build', 'src', duplicate=0)
33213306
Program('build/prog', 'build/source.c')
3322-
</example_commands>
33233307

3324-
<example_commands>
33253308
# this builds both the source and docs in a separate subtree
33263309
VariantDir('build', '.', duplicate=0)
33273310
SConscript(dirs=['build/src','build/doc'])
3328-
</example_commands>
33293311

3330-
<example_commands>
33313312
# same as previous example, but only uses SConscript
33323313
SConscript(dirs='src', variant_dir='build/src', duplicate=0)
33333314
SConscript(dirs='doc', variant_dir='build/doc', duplicate=0)

doc/generated/examples/separate_ex1_1.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ SConscript hello.c
33
% <userinput>scons -Q</userinput>
44
cc -o build/hello.o -c build/hello.c
55
cc -o build/hello build/hello.o
6+
% <userinput>ls src</userinput>
7+
SConscript hello.c
68
% <userinput>ls build</userinput>
79
SConscript hello hello.c hello.o
810
</screen>

doc/user/main.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,18 @@
105105
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="file-removal.xml"/>
106106
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="hierarchy.xml"/>
107107
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="separate.xml"/>
108-
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="variants.xml"/>
109-
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="gettext.xml"/>
108+
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="repositories.xml"/>
110109
<!-- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="builders-built-in.xml"/> -->
111110
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="builders-writing.xml"/>
112111
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="builders-commands.xml"/>
113112
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="add-method.xml"/>
114113
<!-- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="actions.xml"/> -->
115114
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="scanners.xml"/>
116-
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="repositories.xml"/>
117115
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="sconf.xml"/>
118116
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="caching.xml"/>
119117
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="alias.xml"/>
120118
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="java.xml"/>
119+
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="gettext.xml"/>
121120
<!-- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="run.xml"/> -->
122121
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="misc.xml"/>
123122
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="external.xml"/>

0 commit comments

Comments
 (0)