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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
|
<!--
__COPYRIGHT__
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>
The experience of configuring any
software build tool to build a large code base
usually, at some point,
involves trying to figure out why
the tool is behaving a certain way,
and how to get it to behave the way you want.
&SCons; is no different.
</para>
<section>
<title>Why is That Target Being Rebuilt? the &debug-explain; Option</title>
<para>
Let's take a simple example of
a misconfigured build
that causes a target to be rebuilt
every time &SCons; is run:
</para>
<programlisting>
# Intentionally misspell the output file name in the
# command used to create the file:
Command('file.out', 'file.in', 'cp $SOURCE file.oout')
</programlisting>
<para>
(Note to Windows users: The POSIX &cp; command
copies the first file named on the command line
to the second file.
In our example, it copies the &file_in; file
to the &file_out; file.)
</para>
<para>
Now if we run &SCons; multiple on this example,
we see that it re-runs the &cp;
command every time:
</para>
<screen>
% <userinput>scons -Q</userinput>
cp file.in file.oout
% <userinput>scons -Q</userinput>
cp file.in file.oout
% <userinput>scons -Q</userinput>
cp file.in file.oout
</screen>
<para>
In this example,
the underlying cause is obvious:
we've intentionally misspelled the output file name
in the &cp; command,
so the command doesn't actually
build the &file_out; file that we've told &SCons; to expect.
But if the problem weren't obvious,
it would be helpful
to specify the &debug-explain; option
on the command line
to have &SCons; tell us very specifically
why it's decided to rebuild the target:
</para>
<screen>
% <userinput>scons -Q --debug=explain</userinput>
scons: building `file.out' because it doesn't exist
cp file.in file.oout
</screen>
<para>
If this had been a more complicated example
involving a lot of build output,
having &SCons; tell us that
it's trying to rebuild the target file
because it doesn't exist
would be an important clue
that something was wrong with
the command that we invoked to build it.
</para>
<para>
The &debug-explain; option also comes in handy
to help figure out what input file changed.
Given a simple configuration that builds
a program from three source files,
changing one of the source files
and rebuilding with the &debug-explain;
option shows very specifically
why &SCons; rebuilds the files that it does:
</para>
<screen>
% <userinput>scons -Q</userinput>
cc -o file1.o -c file1.c
cc -o file2.o -c file2.c
cc -o file3.o -c file3.c
cc -o prog file1.o file2.o file3.o
% <userinput>edit file2.c</userinput>
[CHANGE THE CONTENTS OF file2.c]
% <userinput>scons -Q --debug=explain</userinput>
scons: rebuilding `file2.o' because `file2.c' changed
cc -o file2.o -c file2.c
scons: rebuilding `prog' because `file2.o' changed
cc -o prog file1.o file2.o file3.o
</screen>
<para>
This becomes even more helpful
in identifying when a file is rebuilt
due to a change in an implicit dependency,
such as an incuded <filename>.h</filename> file.
If the <filename>file1.c</filename>
and <filename>file3.c</filename> files
in our example
both included a &hello_h; file,
then changing that included file
and re-running &SCons; with the &debug-explain; option
will pinpoint that it's the change to the included file
that starts the chain of rebuilds:
</para>
<screen>
% <userinput>scons -Q</userinput>
cc -o file1.o -c -I. file1.c
cc -o file2.o -c -I. file2.c
cc -o file3.o -c -I. file3.c
cc -o prog file1.o file2.o file3.o
% <userinput>edit hello.h</userinput>
[CHANGE THE CONTENTS OF hello.h]
% <userinput>scons -Q --debug=explain</userinput>
scons: rebuilding `file1.o' because `hello.h' changed
cc -o file1.o -c -I. file1.c
scons: rebuilding `file3.o' because `hello.h' changed
cc -o file3.o -c -I. file3.c
scons: rebuilding `prog' because:
`file1.o' changed
`file3.o' changed
cc -o prog file1.o file2.o file3.o
</screen>
</section>
<section>
<title>What's in That Construction Environment? the &Dump; Method</title>
<para>
When you create a construction environment,
&SCons; populates it
with construction variables that are set up
for various compilers, linkers and utilities
that it finds on your system.
Although this is usually helpful and what you want,
it might be frustrating if &SCons;
doesn't set certain variables that you
expect to be sit.
In situations like this,
it's sometimes helpful to use the
construction environment &Dump; method
to print all or some of
the construction variables.
Note that the &Dump; method
<emphasis>returns</emphasis>
the representation of the variables
in the environment
for you to print (or otherwise manipulate):
</para>
<para>
On a POSIX system with gcc installed,
this might generate:
</para>
<screen>
% <userinput>scons</userinput>
scons: Reading SConscript files ...
{ 'BUILDERS': {},
'CONFIGUREDIR': '#/.sconf_temp',
'CONFIGURELOG': '#/config.log',
'CPPSUFFIXES': [ '.c',
'.C',
'.cxx',
'.cpp',
'.c++',
'.cc',
'.h',
'.H',
'.hxx',
'.hpp',
'.hh',
'.F',
'.fpp',
'.FPP',
'.m',
'.mm',
'.S',
'.spp',
'.SPP'],
'DSUFFIXES': ['.d'],
'Dir': <SCons.Defaults.Variable_Method_Caller instance at 0xb7c43bec>,
'Dirs': <SCons.Defaults.Variable_Method_Caller instance at 0xb7c43c0c>,
'ENV': {'PATH': '/usr/local/bin:/opt/bin:/bin:/usr/bin'},
'ESCAPE': <function escape at 0xb7b66c34>,
'File': <SCons.Defaults.Variable_Method_Caller instance at 0xb7c43c2c>,
'IDLSUFFIXES': ['.idl', '.IDL'],
'INSTALL': <function installFunc at 0xb7c41f0c>,
'INSTALLSTR': <function installStr at 0xb7c41f44>,
'LATEXSUFFIXES': ['.tex', '.ltx', '.latex'],
'LIBPREFIX': 'lib',
'LIBPREFIXES': '$LIBPREFIX',
'LIBSUFFIX': '.a',
'LIBSUFFIXES': ['$LIBSUFFIX', '$SHLIBSUFFIX'],
'MAXLINELENGTH': 128072,
'OBJPREFIX': '',
'OBJSUFFIX': '.o',
'PLATFORM': 'posix',
'PROGPREFIX': '',
'PROGSUFFIX': '',
'PSPAWN': <function piped_env_spawn at 0xb7b66fb4>,
'RDirs': <SCons.Defaults.Variable_Method_Caller instance at 0xb7c43c4c>,
'SCANNERS': [],
'SHELL': 'sh',
'SHLIBPREFIX': '$LIBPREFIX',
'SHLIBSUFFIX': '.so',
'SHOBJPREFIX': '$OBJPREFIX',
'SHOBJSUFFIX': '$OBJSUFFIX',
'SPAWN': <function spawnvpe_spawn at 0xb7b66a74>,
'TEMPFILE': <class SCons.Platform.TempFileMunge at 0xb7bd37ac>,
'TEMPFILEPREFIX': '@',
'TOOLS': [],
'_CPPDEFFLAGS': '${_defines(CPPDEFPREFIX, CPPDEFINES, CPPDEFSUFFIX, __env__)}',
'_CPPINCFLAGS': '$( ${_concat(INCPREFIX, CPPPATH, INCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)',
'_LIBDIRFLAGS': '$( ${_concat(LIBDIRPREFIX, LIBPATH, LIBDIRSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)',
'_LIBFLAGS': '${_concat(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, __env__)}',
'__RPATH': '$_RPATH',
'_concat': <function _concat at 0xb7c41fb4>,
'_defines': <function _defines at 0xb7c47064>,
'_installStr': <function installStr at 0xb7c41f44>,
'_stripixes': <function _stripixes at 0xb7c4702c>}
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.
</screen>
<para>
On a Windows system with Visual C++
the output might look like:
</para>
<screen>
C:\><userinput>scons</userinput>
scons: Reading SConscript files ...
{ 'BUILDERS': {'Object': <SCons.Builder.CompositeBuilder instance at 0xb7b6024c>, 'SharedObject': <SCons.Builder.CompositeBuilder instance at 0xb7b603cc>, 'StaticObject': <SCons.Builder.CompositeBuilder instance at 0xb7b6024c>, 'PCH': <SCons.Builder.BuilderBase instance at 0xb7bd2eac>, 'RES': <SCons.Builder.BuilderBase instance at 0xb7b596ec>},
'CC': 'cl',
'CCCOM': <SCons.Action.FunctionAction instance at 0xb7b6086c>,
'CCCOMFLAGS': '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Fo$TARGET $CCPCHFLAGS $CCPDBFLAGS',
'CCFLAGS': ['/nologo'],
'CCPCHFLAGS': ['${(PCH and "/Yu%s /Fp%s"%(PCHSTOP or "",File(PCH))) or ""}'],
'CCPDBFLAGS': ['${(PDB and "/Z7") or ""}'],
'CFILESUFFIX': '.c',
'CFLAGS': [],
'CONFIGUREDIR': '#/.sconf_temp',
'CONFIGURELOG': '#/config.log',
'CPPDEFPREFIX': '/D',
'CPPDEFSUFFIX': '',
'CPPSUFFIXES': [ '.c',
'.C',
'.cxx',
'.cpp',
'.c++',
'.cc',
'.h',
'.H',
'.hxx',
'.hpp',
'.hh',
'.F',
'.fpp',
'.FPP',
'.m',
'.mm',
'.S',
'.spp',
'.SPP'],
'CXX': '$CC',
'CXXCOM': '$CXX $CXXFLAGS $CCCOMFLAGS',
'CXXFILESUFFIX': '.cc',
'CXXFLAGS': ['$CCFLAGS', '$(', '/TP', '$)'],
'DSUFFIXES': ['.d'],
'Dir': <SCons.Defaults.Variable_Method_Caller instance at 0xb7c58bec>,
'Dirs': <SCons.Defaults.Variable_Method_Caller instance at 0xb7c58c0c>,
'ENV': { 'INCLUDE': 'C:\\Program Files\\Microsoft Visual Studio/VC98\\include',
'LIB': 'C:\\Program Files\\Microsoft Visual Studio/VC98\\lib',
'PATH': 'C:\\Program Files\\Microsoft Visual Studio\\Common\\tools\\WIN95;C:\\Program Files\\Microsoft Visual Studio\\Common\\MSDev98\\bin;C:\\Program Files\\Microsoft Visual Studio\\Common\\tools;C:\\Program Files\\Microsoft Visual Studio/VC98\\bin',
'PATHEXT': '.COM;.EXE;.BAT;.CMD',
'SystemRoot': 'C:/WINDOWS'},
'ESCAPE': <function escape at 0xb7bc917c>,
'File': <SCons.Defaults.Variable_Method_Caller instance at 0xb7c58c2c>,
'IDLSUFFIXES': ['.idl', '.IDL'],
'INCPREFIX': '/I',
'INCSUFFIX': '',
'INSTALL': <function installFunc at 0xb7c56f0c>,
'INSTALLSTR': <function installStr at 0xb7c56f44>,
'LATEXSUFFIXES': ['.tex', '.ltx', '.latex'],
'LIBPREFIX': '',
'LIBPREFIXES': ['$LIBPREFIX'],
'LIBSUFFIX': '.lib',
'LIBSUFFIXES': ['$LIBSUFFIX'],
'MAXLINELENGTH': 2048,
'MSVS': {'VERSION': '6.0', 'VERSIONS': ['6.0']},
'MSVS_VERSION': '6.0',
'OBJPREFIX': '',
'OBJSUFFIX': '.obj',
'PCHCOM': '$CXX $CXXFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Fo${TARGETS[1]} /Yc$PCHSTOP /Fp${TARGETS[0]} $CCPDBFLAGS $PCHPDBFLAGS',
'PCHPDBFLAGS': ['${(PDB and "/Yd") or ""}'],
'PLATFORM': 'win32',
'PROGPREFIX': '',
'PROGSUFFIX': '.exe',
'PSPAWN': <function piped_spawn at 0xb7bc90d4>,
'RC': 'rc',
'RCCOM': '$RC $_CPPDEFFLAGS $_CPPINCFLAGS $RCFLAGS /fo$TARGET $SOURCES',
'RCFLAGS': [],
'RDirs': <SCons.Defaults.Variable_Method_Caller instance at 0xb7c58c4c>,
'SCANNERS': [],
'SHCC': '$CC',
'SHCCCOM': <SCons.Action.FunctionAction instance at 0xb7b608cc>,
'SHCCFLAGS': ['$CCFLAGS'],
'SHCFLAGS': ['$CFLAGS'],
'SHCXX': '$CXX',
'SHCXXCOM': '$SHCXX $SHCXXFLAGS $CCCOMFLAGS',
'SHCXXFLAGS': ['$CXXFLAGS'],
'SHELL': None,
'SHLIBPREFIX': '',
'SHLIBSUFFIX': '.dll',
'SHOBJPREFIX': '$OBJPREFIX',
'SHOBJSUFFIX': '$OBJSUFFIX',
'SPAWN': <function spawn at 0xb7bc9144>,
'STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME': 1,
'TEMPFILE': <class SCons.Platform.TempFileMunge at 0xb7be87ac>,
'TEMPFILEPREFIX': '@',
'TOOLS': ['msvc'],
'_CPPDEFFLAGS': '${_defines(CPPDEFPREFIX, CPPDEFINES, CPPDEFSUFFIX, __env__)}',
'_CPPINCFLAGS': '$( ${_concat(INCPREFIX, CPPPATH, INCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)',
'_LIBDIRFLAGS': '$( ${_concat(LIBDIRPREFIX, LIBPATH, LIBDIRSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)',
'_LIBFLAGS': '${_concat(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, __env__)}',
'_concat': <function _concat at 0xb7c56fb4>,
'_defines': <function _defines at 0xb7c5c064>,
'_installStr': <function installStr at 0xb7c56f44>,
'_stripixes': <function _stripixes at 0xb7c5c02c>}
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.
</screen>
<para>
The construction environments in these examples have
actually been restricted to just gcc and Visual C++,
respectively.
In a real-life situation,
the construction environments will
likely contain a great many more variables.
</para>
<para>
To make it easier to see just what you're
interested in,
the &Dump; method allows you to
specify a specific constrcution variable
that you want to disply.
For example,
it's not unusual to want to verify
the external environment used to execute build commands,
to make sure that the PATH and other
environment variables are set up the way they should be.
You can do this as follows:
</para>
<para>
Which might display the following when executed on a POSIX system:
</para>
<screen>
% <userinput>scons</userinput>
scons: Reading SConscript files ...
{'PATH': '/usr/local/bin:/opt/bin:/bin:/usr/bin'}
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.
</screen>
<para>
And the following when executed on a Windows system:
</para>
<screen>
C:\><userinput>scons</userinput>
scons: Reading SConscript files ...
{ 'INCLUDE': 'C:\\Program Files\\Microsoft Visual Studio/VC98\\include',
'LIB': 'C:\\Program Files\\Microsoft Visual Studio/VC98\\lib',
'PATH': 'C:\\Program Files\\Microsoft Visual Studio\\Common\\tools\\WIN95;C:\\Program Files\\Microsoft Visual Studio\\Common\\MSDev98\\bin;C:\\Program Files\\Microsoft Visual Studio\\Common\\tools;C:\\Program Files\\Microsoft Visual Studio/VC98\\bin',
'PATHEXT': '.COM;.EXE;.BAT;.CMD',
'SystemRoot': 'C:/WINDOWS'}
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.
</screen>
</section>
|