1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
<!--
Copyright (c) 2001, 2002, 2003 Steven Knight
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<para>
On multi-developer software projects,
you can sometimes speed up every developer's builds a lot by
allowing them to share the derived files that they build.
&SCons; makes this easy, as well as reliable.
</para>
<section>
<title>Specifying the Shared Cache Directory</title>
<para>
To enable sharing of derived files,
use the &CacheDir; function
in any &SConscript; file:
</para>
<scons_example name="ex1">
<file name="SConstruct">
env = Environment()
env.Program('hello.c')
CacheDir('cache')
</file>
<file name="hello.c">
hello.c
</file>
<directory name="cache">
</directory>
<file name="not_used" printme="1">
CacheDir('/usr/local/build_cache')
</file>
</scons_example>
<para>
Note that the directory you specify must already exist
and be readable and writable by all developers
who will be sharing derived files.
It should also be in some central location
that all builds will be able to access.
In environments where developers are using separate systems
(like individual workstations) for builds,
this directory would typically be
on a shared or NFS-mounted file system.
</para>
<para>
Here's what happens:
When a build has a &CacheDir; specified,
every time a file is built,
it is stored in the shared cache directory
along with its MD5 build signature.
On subsequent builds,
before an action is invoked to build a file,
&SCons; will check the shared cache directory
to see if a file with the exact same build
signature already exists.
If so, the derived file will not be built locally,
but will be copied into the local build directory
from the shared cache directory,
like so:
</para>
<scons_output example="ex1">
<command>scons -Q</command>
<command>scons -Q -c</command>
<command>scons -Q</command>
</scons_output>
</section>
<section>
<title>Keeping Build Output Consistent</title>
<para>
One potential drawback to using a shared cache
is that your build output can be inconsistent
from invocation to invocation,
because any given file may be rebuilt one time
and retrieved from the shared cache the next time.
This can make analyzing build output more difficult,
especially for automated scripts that
expect consistent output each time.
</para>
<para>
If, however, you use the <literal>--cache-show</literal> option,
&SCons; will print the command line that it
<emphasis>would</emphasis> have executed
to build the file,
even when it is retrieving the file from the shared cache.
This makes the build output consistent
every time the build is run:
</para>
<scons_output example="ex1">
<command>scons -Q</command>
<command>scons -Q -c</command>
<command>scons -Q --cache-show</command>
</scons_output>
<para>
The trade-off, of course, is that you no longer
know whether or not &SCons;
has retrieved a derived file from cache
or has rebuilt it locally.
</para>
</section>
<section>
<title>Not Retrieving Files From a Shared Cache</title>
<para>
Retrieving an already-built file
from the shared cache
is usually a significant time-savings
over rebuilding the file,
but how much of a savings
(or even whether it saves time at all)
can depend a great deal on your
system or network configuration.
For example, retrieving cached files
from a busy server over a busy network
might end up being slower than
rebuilding the files locally.
</para>
<para>
In these cases, you can specify
the <literal>--cache-disable</literal>
command-line option to tell &SCons;
to not retrieve already-built files from the
shared cache directory:
</para>
<scons_output example="ex1">
<command>scons -Q</command>
<command>scons -Q -c</command>
<command>scons -Q</command>
<command>scons -Q -c</command>
<command>scons -Q --cache-disable</command>
</scons_output>
</section>
<section>
<title>Populating a Shared Cache With Already-Built Files</title>
<para>
Sometimes, you may have one or more derived files
already built in your local build tree
that you wish to make available to other people doing builds.
For example, you may find it more effective to perform
integration builds with the cache disabled
(per the previous section)
and only populate the shared cache directory
with the built files after the integration build
has completed successfully.
This way, the cache will only get filled up
with derived files that are part of a complete, successful build
not with files that might be later overwritten
while you debug integration problems.
</para>
<para>
In this case, you can use the
the <literal>--cache-force</literal> option
to tell &SCons; to put all derived files in the cache,
even if the files had already been built
by a previous invocation:
</para>
<scons_output example="ex1">
<command>scons -Q --cache-disable</command>
<command>scons -Q -c</command>
<command>scons -Q --cache-disable</command>
<command>scons -Q --cache-force</command>
<command>scons -Q -c</command>
<command>scons -Q</command>
</scons_output>
<para>
Notice how the above sample run
demonstrates that the <literal>--cache-disable</literal>
option avoids putting the built
<filename>hello.o</filename>
and
<filename>hello</filename> files in the cache,
but after using the <literal>--cache-force</literal> option,
the files have been put in the cache
for the next invocation to retrieve.
</para>
</section>
|