5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
13 The above copyright notice and this permission notice shall be included
14 in all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 The experience of configuring any
29 software build tool to build a large code base
30 usually, at some point,
31 involves trying to figure out why
32 the tool is behaving a certain way,
33 and how to get it to behave the way you want.
34 &SCons; is no different.
39 <title>Why is That Target Being Rebuilt? the &debug-explain; Option</title>
43 Let's take a simple example of
45 that causes a target to be rebuilt
46 every time &SCons; is run:
51 # Intentionally misspell the output file name in the
52 # command used to create the file:
53 Command('file.out', 'file.in', 'cp $SOURCE file.oout')
58 (Note to Windows users: The POSIX &cp; command
59 copies the first file named on the command line
61 In our example, it copies the &file_in; file
62 to the &file_out; file.)
68 Now if we run &SCons; multiple on this example,
69 we see that it re-runs the &cp;
75 % <userinput>scons -Q</userinput>
77 % <userinput>scons -Q</userinput>
79 % <userinput>scons -Q</userinput>
86 the underlying cause is obvious:
87 we've intentionally misspelled the output file name
89 so the command doesn't actually
90 build the &file_out; file that we've told &SCons; to expect.
91 But if the problem weren't obvious,
93 to specify the &debug-explain; option
95 to have &SCons; tell us very specifically
96 why it's decided to rebuild the target:
101 % <userinput>scons -Q --debug=explain</userinput>
102 scons: building `file.out' because it doesn't exist
108 If this had been a more complicated example
109 involving a lot of build output,
110 having &SCons; tell us that
111 it's trying to rebuild the target file
112 because it doesn't exist
113 would be an important clue
114 that something was wrong with
115 the command that we invoked to build it.
121 The &debug-explain; option also comes in handy
122 to help figure out what input file changed.
123 Given a simple configuration that builds
124 a program from three source files,
125 changing one of the source files
126 and rebuilding with the &debug-explain;
127 option shows very specifically
128 why &SCons; rebuilds the files that it does:
135 % <userinput>scons -Q</userinput>
136 cc -o file1.o -c file1.c
137 cc -o file2.o -c file2.c
138 cc -o file3.o -c file3.c
139 cc -o prog file1.o file2.o file3.o
140 % <userinput>edit file2.c</userinput>
141 [CHANGE THE CONTENTS OF file2.c]
142 % <userinput>scons -Q --debug=explain</userinput>
143 scons: rebuilding `file2.o' because `file2.c' changed
144 cc -o file2.o -c file2.c
145 scons: rebuilding `prog' because `file2.o' changed
146 cc -o prog file1.o file2.o file3.o
151 This becomes even more helpful
152 in identifying when a file is rebuilt
153 due to a change in an implicit dependency,
154 such as an incuded <filename>.h</filename> file.
155 If the <filename>file1.c</filename>
156 and <filename>file3.c</filename> files
158 both included a &hello_h; file,
159 then changing that included file
160 and re-running &SCons; with the &debug-explain; option
161 will pinpoint that it's the change to the included file
162 that starts the chain of rebuilds:
169 % <userinput>scons -Q</userinput>
170 cc -o file1.o -c -I. file1.c
171 cc -o file2.o -c -I. file2.c
172 cc -o file3.o -c -I. file3.c
173 cc -o prog file1.o file2.o file3.o
174 % <userinput>edit hello.h</userinput>
175 [CHANGE THE CONTENTS OF hello.h]
176 % <userinput>scons -Q --debug=explain</userinput>
177 scons: rebuilding `file1.o' because `hello.h' changed
178 cc -o file1.o -c -I. file1.c
179 scons: rebuilding `file3.o' because `hello.h' changed
180 cc -o file3.o -c -I. file3.c
181 scons: rebuilding `prog' because:
184 cc -o prog file1.o file2.o file3.o
190 <title>What's in That Construction Environment? the &Dump; Method</title>
194 When you create a construction environment,
196 with construction variables that are set up
197 for various compilers, linkers and utilities
198 that it finds on your system.
199 Although this is usually helpful and what you want,
200 it might be frustrating if &SCons;
201 doesn't set certain variables that you
203 In situations like this,
204 it's sometimes helpful to use the
205 construction environment &Dump; method
206 to print all or some of
207 the construction variables.
208 Note that the &Dump; method
209 <emphasis>returns</emphasis>
210 the representation of the variables
212 for you to print (or otherwise manipulate):
220 On a POSIX system with gcc installed,
226 % <userinput>scons</userinput>
227 scons: Reading SConscript files ...
229 'CONFIGUREDIR': '#/.sconf_temp',
230 'CONFIGURELOG': '#/config.log',
231 'CPPSUFFIXES': [ '.c',
251 'Dir': <SCons.Defaults.Variable_Method_Caller instance at 0xb7c43bec>,
252 'Dirs': <SCons.Defaults.Variable_Method_Caller instance at 0xb7c43c0c>,
253 'ENV': {'PATH': '/usr/local/bin:/opt/bin:/bin:/usr/bin'},
254 'ESCAPE': <function escape at 0xb7b66c34>,
255 'File': <SCons.Defaults.Variable_Method_Caller instance at 0xb7c43c2c>,
256 'IDLSUFFIXES': ['.idl', '.IDL'],
257 'INSTALL': <function installFunc at 0xb7c41f0c>,
258 'INSTALLSTR': <function installStr at 0xb7c41f44>,
259 'LATEXSUFFIXES': ['.tex', '.ltx', '.latex'],
261 'LIBPREFIXES': '$LIBPREFIX',
263 'LIBSUFFIXES': ['$LIBSUFFIX', '$SHLIBSUFFIX'],
264 'MAXLINELENGTH': 128072,
270 'PSPAWN': <function piped_env_spawn at 0xb7b66fb4>,
271 'RDirs': <SCons.Defaults.Variable_Method_Caller instance at 0xb7c43c4c>,
274 'SHLIBPREFIX': '$LIBPREFIX',
275 'SHLIBSUFFIX': '.so',
276 'SHOBJPREFIX': '$OBJPREFIX',
277 'SHOBJSUFFIX': '$OBJSUFFIX',
278 'SPAWN': <function spawnvpe_spawn at 0xb7b66a74>,
279 'TEMPFILE': <class SCons.Platform.TempFileMunge at 0xb7bd37ac>,
280 'TEMPFILEPREFIX': '@',
282 '_CPPDEFFLAGS': '${_defines(CPPDEFPREFIX, CPPDEFINES, CPPDEFSUFFIX, __env__)}',
283 '_CPPINCFLAGS': '$( ${_concat(INCPREFIX, CPPPATH, INCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)',
284 '_LIBDIRFLAGS': '$( ${_concat(LIBDIRPREFIX, LIBPATH, LIBDIRSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)',
285 '_LIBFLAGS': '${_concat(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, __env__)}',
286 '__RPATH': '$_RPATH',
287 '_concat': <function _concat at 0xb7c41fb4>,
288 '_defines': <function _defines at 0xb7c47064>,
289 '_installStr': <function installStr at 0xb7c41f44>,
290 '_stripixes': <function _stripixes at 0xb7c4702c>}
291 scons: done reading SConscript files.
292 scons: Building targets ...
293 scons: `.' is up to date.
294 scons: done building targets.
299 On a Windows system with Visual C++
300 the output might look like:
305 C:\><userinput>scons</userinput>
306 scons: Reading SConscript files ...
307 { '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>},
309 'CCCOM': <SCons.Action.FunctionAction instance at 0xb7b6086c>,
310 'CCCOMFLAGS': '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Fo$TARGET $CCPCHFLAGS $CCPDBFLAGS',
311 'CCFLAGS': ['/nologo'],
312 'CCPCHFLAGS': ['${(PCH and "/Yu%s /Fp%s"%(PCHSTOP or "",File(PCH))) or ""}'],
313 'CCPDBFLAGS': ['${(PDB and "/Z7") or ""}'],
316 'CONFIGUREDIR': '#/.sconf_temp',
317 'CONFIGURELOG': '#/config.log',
318 'CPPDEFPREFIX': '/D',
320 'CPPSUFFIXES': [ '.c',
340 'CXXCOM': '$CXX $CXXFLAGS $CCCOMFLAGS',
341 'CXXFILESUFFIX': '.cc',
342 'CXXFLAGS': ['$CCFLAGS', '$(', '/TP', '$)'],
344 'Dir': <SCons.Defaults.Variable_Method_Caller instance at 0xb7c58bec>,
345 'Dirs': <SCons.Defaults.Variable_Method_Caller instance at 0xb7c58c0c>,
346 'ENV': { 'INCLUDE': 'C:\\Program Files\\Microsoft Visual Studio/VC98\\include',
347 'LIB': 'C:\\Program Files\\Microsoft Visual Studio/VC98\\lib',
348 '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',
349 'PATHEXT': '.COM;.EXE;.BAT;.CMD',
350 'SystemRoot': 'C:/WINDOWS'},
351 'ESCAPE': <function escape at 0xb7bc917c>,
352 'File': <SCons.Defaults.Variable_Method_Caller instance at 0xb7c58c2c>,
353 'IDLSUFFIXES': ['.idl', '.IDL'],
356 'INSTALL': <function installFunc at 0xb7c56f0c>,
357 'INSTALLSTR': <function installStr at 0xb7c56f44>,
358 'LATEXSUFFIXES': ['.tex', '.ltx', '.latex'],
360 'LIBPREFIXES': ['$LIBPREFIX'],
362 'LIBSUFFIXES': ['$LIBSUFFIX'],
363 'MAXLINELENGTH': 2048,
364 'MSVS': {'VERSION': '6.0', 'VERSIONS': ['6.0']},
365 'MSVS_VERSION': '6.0',
368 'PCHCOM': '$CXX $CXXFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Fo${TARGETS[1]} /Yc$PCHSTOP /Fp${TARGETS[0]} $CCPDBFLAGS $PCHPDBFLAGS',
369 'PCHPDBFLAGS': ['${(PDB and "/Yd") or ""}'],
372 'PROGSUFFIX': '.exe',
373 'PSPAWN': <function piped_spawn at 0xb7bc90d4>,
375 'RCCOM': '$RC $_CPPDEFFLAGS $_CPPINCFLAGS $RCFLAGS /fo$TARGET $SOURCES',
377 'RDirs': <SCons.Defaults.Variable_Method_Caller instance at 0xb7c58c4c>,
380 'SHCCCOM': <SCons.Action.FunctionAction instance at 0xb7b608cc>,
381 'SHCCFLAGS': ['$CCFLAGS'],
382 'SHCFLAGS': ['$CFLAGS'],
384 'SHCXXCOM': '$SHCXX $SHCXXFLAGS $CCCOMFLAGS',
385 'SHCXXFLAGS': ['$CXXFLAGS'],
388 'SHLIBSUFFIX': '.dll',
389 'SHOBJPREFIX': '$OBJPREFIX',
390 'SHOBJSUFFIX': '$OBJSUFFIX',
391 'SPAWN': <function spawn at 0xb7bc9144>,
392 'STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME': 1,
393 'TEMPFILE': <class SCons.Platform.TempFileMunge at 0xb7be87ac>,
394 'TEMPFILEPREFIX': '@',
396 '_CPPDEFFLAGS': '${_defines(CPPDEFPREFIX, CPPDEFINES, CPPDEFSUFFIX, __env__)}',
397 '_CPPINCFLAGS': '$( ${_concat(INCPREFIX, CPPPATH, INCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)',
398 '_LIBDIRFLAGS': '$( ${_concat(LIBDIRPREFIX, LIBPATH, LIBDIRSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)',
399 '_LIBFLAGS': '${_concat(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, __env__)}',
400 '_concat': <function _concat at 0xb7c56fb4>,
401 '_defines': <function _defines at 0xb7c5c064>,
402 '_installStr': <function installStr at 0xb7c56f44>,
403 '_stripixes': <function _stripixes at 0xb7c5c02c>}
404 scons: done reading SConscript files.
405 scons: Building targets ...
406 scons: `.' is up to date.
407 scons: done building targets.
412 The construction environments in these examples have
413 actually been restricted to just gcc and Visual C++,
415 In a real-life situation,
416 the construction environments will
417 likely contain a great many more variables.
423 To make it easier to see just what you're
425 the &Dump; method allows you to
426 specify a specific constrcution variable
427 that you want to disply.
429 it's not unusual to want to verify
430 the external environment used to execute build commands,
431 to make sure that the PATH and other
432 environment variables are set up the way they should be.
433 You can do this as follows:
441 Which might display the following when executed on a POSIX system:
446 % <userinput>scons</userinput>
447 scons: Reading SConscript files ...
448 {'PATH': '/usr/local/bin:/opt/bin:/bin:/usr/bin'}
449 scons: done reading SConscript files.
450 scons: Building targets ...
451 scons: `.' is up to date.
452 scons: done building targets.
457 And the following when executed on a Windows system:
462 C:\><userinput>scons</userinput>
463 scons: Reading SConscript files ...
464 { 'INCLUDE': 'C:\\Program Files\\Microsoft Visual Studio/VC98\\include',
465 'LIB': 'C:\\Program Files\\Microsoft Visual Studio/VC98\\lib',
466 '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',
467 'PATHEXT': '.COM;.EXE;.BAT;.CMD',
468 'SystemRoot': 'C:/WINDOWS'}
469 scons: done reading SConscript files.
470 scons: Building targets ...
471 scons: `.' is up to date.
472 scons: done building targets.