1 SCons - a software construction tool
2 ####################################
4 Welcome to the SCons development tree. The real purpose of this tree is to
5 package SCons for production distribution in a variety of formats, not just to
8 If all you want to do is install and run SCons, it will be easier for you to
9 download and install the scons-{version}.tar.gz or scons-{version}.zip package
10 rather than to work with the packaging logic in this tree.
12 To the extent that this tree is about building SCons packages, the *full*
13 development cycle is not just to test the code directly, but to package SCons,
14 unpack the package, "install" SCons in a test subdirectory, and then to run
15 the tests against the unpacked and installed software. This helps eliminate
16 problems caused by, for example, failure to update the list of files to be
19 For just working on making an individual change to the SCons source, however,
20 you don't actually need to build or install SCons; you *can* actually edit and
21 execute SCons in-place. See the following sections below for more
25 How to edit and execute SCons in-place.
28 Tips for debugging problems in SCons.
31 How to use the automated regression tests.
33 `Development Workflow`_
34 An example of how to put the edit/execute/test pieces
35 together in a reasonable development workflow.
41 Before going further, you can check that the package you have is the latest
42 version at the SCons download page:
44 http://www.scons.org/pages/download.html
47 Execution Requirements
48 ======================
50 Running SCons requires Python 3.6 or higher. There should be no other
51 dependencies or requirements to run standard SCons.
52 The last release to support Python 3.5 was 4.2.0.
54 The default SCons configuration assumes use of the Microsoft Visual C++
55 compiler suite on Win32 systems, and assumes a C compiler named 'cc', a C++
56 compiler named 'c++', and a Fortran compiler named 'gfortran' (such as found
57 in the GNU C compiler suite) on any other type of system. You may, of course,
58 override these default values by appropriate configuration of Environment
59 construction variables.
61 By default, SCons knows how to search for available programming tools on
62 various systems--see the SCons man page for details. You may, of course,
63 override the default SCons choices made by appropriate configuration of
64 Environment construction variables.
67 Installation Requirements
68 =========================
73 Executing SCons Without Installing
74 ==================================
76 You can execute the local SCons directly from the SCons subdirectory by first
77 setting the SCONS_LIB_DIR environment variable to the local SCons
78 subdirectory, and then executing the local scripts/scons.py script to
79 populate the build/scons/ subdirectory. You would do this as follows on a
80 Linux or UNIX system (using sh or a derivative like bash or ksh)::
82 $ setenv MYSCONS=`pwd`
83 $ python $MYSCONS/scripts/scons.py [arguments]
87 C:\scons>set MYSCONS=%cd%
88 C:\scons>python %MYSCONS%\scripts\scons.py [arguments]
90 An alternative approach is to skip the above and use::
92 $ python scripts/scons.py [arguments]
95 You can use the -C option to have SCons change directory to another location
96 where you already have a build configuration set up::
98 $ python scripts/scons.py -C /some/other/location [arguments]
100 For simplicity in the following examples, we will only show the bootstrap.py
107 Note: You don't need to build SCons packages or install SCons if you just
108 want to work on developing a patch. See the sections about `Making
109 Changes`_ and `Testing`_ below if you just want to submit a bug fix or
110 some new functionality.
112 Assuming your system satisfies the installation requirements in the previous
113 section, install SCons from this package by first populating the build/scons/
114 subdirectory. (For an easier way to install SCons, without having to populate
115 this directory, use the scons-{version}.tar.gz or scons-{version}.zip
119 Install the built SCons files
120 -----------------------------
122 Any of the above commands will populate the build/scons/ directory with the
123 necessary files and directory structure to use the Python-standard setup
124 script as follows on Linux or UNIX::
126 # python setup.py install
130 C:\scons>python setup.py install
132 By default, the above commands will do the following:
134 - Install scripts named "scons" and "sconsign" scripts in the default system
135 script directory (/usr/bin or C:\\Python\*\\Scripts, for example).
137 - Install "scons-4.7.0.exe" and "scons.exe" executables in the Python
138 prefix directory on Windows (C:\\Python\*, for example).
140 - Install the SCons build engine (a Python module) in the standard Python library directory
141 (/usr/lib/python\*/site-packages or C:\\Python*\\Lib\\site-packages).
146 Because SCons is implemented in a scripting language, you don't need to build
147 it in order to make changes and test them.
149 Virtually all of the SCons functionality exists in the "build engine," the
150 SCons subdirectory hierarchy that contains all of the modules that
151 make up SCons. The scripts/scons.py wrapper script exists mainly to find
152 the appropriate build engine library and then execute it.
154 In order to make your own changes locally and test them by hand, simply edit
155 modules in the local SCons subdirectory tree and then running
156 (see the section above about `Executing SCons Without Installing`_)::
158 $ python scripts/scons.py [arguments]
160 If you want to be able to just execute your modified version of SCons from the
161 command line, you can make it executable and add its directory to your $PATH
164 $ chmod 755 scripts/scons.py
165 $ export PATH=$PATH:`pwd`/scripts
167 You should then be able to run this version of SCons by just typing "scons.py"
168 at your UNIX or Linux command line.
170 Note that the regular SCons development process makes heavy use of automated
171 testing. See the `Testing`_ and `Development Workflow`_ sections below for more
172 information about the automated regression tests and how they can be used in a
173 development cycle to validate that your changes don't break existing
180 Python comes with a good interactive debugger. When debugging changes by hand
181 (i.e., when not using the automated tests), you can invoke SCons under control
182 of the Python debugger by specifying the --debug=pdb option::
184 $ scons --debug=pdb [arguments]
185 > /home/knight/scons/SCons/Script/Main.py(927)_main()
186 -> default_warnings = [ SCons.Warnings.CorruptSConsignWarning,
189 Once in the debugger, you can set breakpoints at lines in files in the build
190 engine modules by providing the path name of the file relative to the
191 top directory (that is, including the SCons/ as the first directory
194 (Pdb) b SCons/Tool/msvc.py:158
196 The debugger also supports single stepping, stepping into functions, printing
199 Trying to debug problems found by running the automated tests (see the
200 `Testing`_ section, below) is more difficult, because the test automation
201 harness re-invokes SCons and captures output. Consequently, there isn't an
202 easy way to invoke the Python debugger in a useful way on any particular SCons
203 call within a test script.
205 The most effective technique for debugging problems that occur during an
206 automated test is to use the good old tried-and-true technique of adding
207 statements to print tracing information. But note that you can't just use
208 the "print" function, or even "sys.stdout.write()" because those change the
209 SCons output, and the automated tests usually look for matches of specific
210 output strings to decide if a given SCons invocation passes the test -
211 so these additions may cause apparent failures different than the one you
214 To deal with this, SCons supports a Trace() function that (by default) will
215 print messages to your console screen ("/dev/tty" on UNIX or Linux, "con" on
216 Windows). By adding Trace() calls to the SCons source code::
218 def sample_method(self, value):
219 from SCons.Debug import Trace
220 Trace('called sample_method(%s, %s)\n' % (self, value))
222 You can then run automated tests that print any arbitrary information you wish
223 about what's going on inside SCons, without interfering with the test
226 The Trace() function can also redirect its output to a file, rather than the
229 def sample_method(self, value):
230 from SCons.Debug import Trace
231 Trace('called sample_method(%s, %s)\n' % (self, value),
234 Where the Trace() function sends its output is stateful: once you use the
235 "file=" argument, all subsequent calls to Trace() send their output to the
236 same file, until another call with a "file=" argument is reached.
242 Tests are run by the runtest.py script in this directory.
244 There are two types of tests in this package:
246 1. Unit tests for individual SCons modules live underneath the SCons
247 subdirectory and have the same base name as the module with "Tests.py"
248 appended--for example, the unit test for the Builder.py module is the
249 BuilderTests.py script.
251 2. End-to-end tests of SCons live in the test/ subdirectory.
253 You may specifically list one or more tests to be run::
255 $ python runtest.py SCons/BuilderTests.py
257 $ python runtest.py test/option-j.py test/Program.py
259 You also use the -f option to execute just the tests listed in a specified
265 $ python runtest.py -f testlist.txt
267 One test must be listed per line, and any lines that begin with '#' will be
268 ignored (allowing you, for example, to comment out tests that are currently
269 passing and then uncomment all of the tests in the file for a final validation
272 The runtest.py script also takes a -a option that searches the tree for all of
273 the tests and runs them::
275 $ python runtest.py -a
277 If more than one test is run, the runtest.py script prints a summary of how
278 many tests passed, failed, or yielded no result, and lists any unsuccessful
281 The above invocations all test directly the files underneath the SCons/
282 subdirectory, and do not require that a build be performed first.
287 Caveat: The point of this section isn't to describe one dogmatic workflow.
288 Just running the test suite can be time-consuming, and getting a patch to
289 pass all of the tests can be more so. If you're genuinely blocked, it may
290 make more sense to submit a patch with a note about which tests still
291 fail, and how. Someone else may be able to take your "initial draft" and
292 figure out how to improve it to fix the rest of the tests. So there's
293 plenty of room for use of good judgement.
295 The various techniques described in the above sections can be combined to
296 create simple and effective workflows that allow you to validate that patches
297 you submit to SCons don't break existing functionality and have adequate
298 testing, thereby increasing the speed with which they can be integrated.
300 For example, suppose your project's SCons configuration is blocked by an SCons
301 bug, and you decide you want to fix it and submit the patch. Here's one
302 possible way to go about doing that (using UNIX/Linux as the development
303 platform, Windows users can translate as appropriate)):
305 - Change to the top of your checked-out SCons tree.
307 - Confirm that the bug still exists in this version of SCons by using the -C
308 option to run the broken build::
310 $ python scripts/scons.py -C /home/me/broken_project .
312 - Fix the bug in SCons by editing appropriate module files underneath
315 - Confirm that you've fixed the bug affecting your project::
317 $ python scripts/scons.py -C /home/me/broken_project .
319 - Test to see if your fix had any unintended side effects that break existing
322 $ python runtest.py -a -o test.log
324 Be patient, there are more than 1100 test scripts in the whole suite. If you
325 are on UNIX/Linux, you can use::
327 $ python runtest.py -a | tee test.log
329 instead so you can monitor progress from your terminal.
331 If any test scripts fail, they will be listed in a summary at the end of the
332 log file. Some test scripts may also report NO RESULT because (for example)
333 your local system is the wrong type or doesn't have some installed utilities
334 necessary to run the script. In general, you can ignore the NO RESULT list,
335 beyond having checked once that the tests that matter to your change are
336 actually being executed on your test system!
338 - Cut-and-paste the list of failed tests into a file::
341 test/failed-test-1.py
342 test/failed-test-2.py
343 test/failed-test-3.py
347 - Now debug the test failures and fix them, either by changing SCons, or by
348 making necessary changes to the tests (if, for example, you have a strong
349 reason to change functionality, or if you find that the bug really is in the
350 test script itself). After each change, use the runtest.py -f option to
351 examine the effects of the change on the subset of tests that originally
355 $ python runtest.py -f failed.txt
357 Repeat this until all of the tests that originally failed now pass.
359 - Now you need to go back and validate that any changes you made while getting
360 the tests to pass didn't break the fix you originally put in, and didn't
361 introduce any *additional* unintended side effects that broke other tests::
363 $ python scripts/scons.py -C /home/me/broken_project .
364 $ python runtest.py -a -o test.log
366 If you find any newly-broken tests, add them to your "failed.txt" file and
367 go back to the previous step.
369 Of course, the above is only one suggested workflow. In practice, there is a
370 lot of room for judgment and experience to make things go quicker. For
371 example, if you're making a change to just the Java support, you might start
372 looking for regressions by just running the test/Java/\*.py tests instead of
373 running all of "runtest.py -a".
379 We use SCons to build its own packages. If you
380 already have an appropriate version of SCons installed on your system, you can
381 build everything by simply running it::
385 If you don't have SCons already installed on your
386 system, you can use the supplied bootstrap.py script (see the section above
387 about `Executing SCons Without Installing`_)::
389 $ python scripts/scons.py build/scons
391 Depending on the utilities installed on your system, any or all of the
392 following packages will be built::
394 SCons-4.7.0-py3-none-any.whl
395 SCons-4.7.0ayyyymmdd.tar.gz
396 SCons-4.7.0ayyyymmdd.zip
397 scons-doc-4.7.0ayyyymmdd.tar.gz
398 scons-local-4.7.0ayyyymmdd.tar.gz
399 scons-local-4.7.0ayyyymmdd.zip
400 scons-local-4.7.0ayyyymmdd.pyz
402 The SConstruct file is supposed to be smart enough to avoid trying to build
403 packages for which you don't have the proper utilities installed.
405 If you receive a build error, please report it to the scons-users mailing list
406 and open a bug report on the SCons issue tracker on GitHub.
408 Note that in addition to creating the above packages, the default build will
409 also unpack one or more of the packages for testing.
412 Contents of this Package
413 ========================
415 Not guaranteed to be up-to-date (but better than nothing):
418 A subdirectory for benchmarking scripts, used to perform timing tests
419 to decide what specific idioms are most efficient for various parts of
420 the code base. We check these in so they're available in case we have
421 to revisit any of these decisions in the future.
424 Miscellaneous utilities used in SCons development. Right now,
425 some of the stuff here includes:
427 - a script that runs pychecker on our source tree;
429 - a script that counts source and test files and numbers of lines in each;
431 - a prototype script for capturing sample SCons output in xml files;
433 - a script that can profile and time a packaging build of SCons itself;
435 - a copy of xml_export, which can retrieve project data from SourceForge;
438 - scripts and a Python module for translating the SCons home-brew XML
439 documentation tags into DocBook and man page format
443 Obsolete packaging logic.
447 Files needed to construct a Debian package. The contents of this directory
448 are dictated by the Debian Policy Manual
449 (http://www.debian.org/doc/debian-policy). The package will not be
450 accepted into the Debian distribution unless the contents of this
451 directory satisfy the relevant Debian policies.
454 SCons documentation. A variety of things here, in various stages of
458 A copy of the copyright and terms under which SCons is distributed (the
459 Open Source Initiative-approved MIT license).
462 A copy of the copyright and terms under which SCons is distributed for
463 inclusion in the scons-local-{version} packages. This is the same as
464 LICENSE with a preamble that specifies the licensing terms are for SCons
465 itself, not any other package that includes SCons.
468 What you're looking at right now.
471 A README file for inclusion in the scons-local-{version} packages.
472 Similar to this file, but stripped down and modified for people looking at
473 including SCons in their shipped software.
476 Script for running SCons tests. By default, this will run a test against
477 the code in the local SCons tree, so you don't have to do a build before
478 testing your changes.
481 The file describing to SCons how to build the SCons distribution.
483 (It has been pointed out that it's hard to find the SCons API in this
484 SConstruct file, and that it looks a lot more like a pure Python script
485 than a build configuration file. That's mainly because all of the magick
486 we have to perform to deal with all of the different packaging formats
487 requires a lot of pure Python manipulation. In other words, don't look at
488 this file for an example of how easy it is to use SCons to build "normal"
492 Where the actual source code is kept, of course.
495 End-to-end tests of the SCons utility itself. These are separate from the
496 individual module unit tests, which live side-by-side with the modules
500 SCons testing framework.
505 See the RELEASE.txt file for notes about this specific release, including
506 known problems. See the CHANGES.txt file for a list of changes since the
509 The doc/man/scons.1 man page is included in this package, and contains a
510 section of small examples for getting started using SCons.
512 Additional documentation for SCons is available at:
514 http://www.scons.org/documentation.html
520 SCons is distributed under the MIT license, a full copy of which is available
527 The SCons project welcomes bug reports and feature requests.
529 Please make sure you send email with the problem or feature request to
530 the SCons users mailing list, which you can join via the link below:
532 http://two.pairlist.net/mailman/listinfo/scons-users
534 Once you have discussed your issue on the users mailing list and the
535 community has confirmed that it is either a new bug or a duplicate of an
536 existing bug, then please follow the instructions the community provides
537 to file a new bug or to add yourself to the CC list for an existing bug
539 You can explore the list of existing bugs, which may include workarounds
540 for the problem you've run into on GitHub Issues:
542 https://github.com/SCons/scons/issues
548 In addition to the scons-users list which is appropriate for almost any
549 question, there is a mailing list specifically for developers of SCons
550 You may send questions or comments to the list at:
554 You may subscribe to the developer's mailing list using form on this page:
556 http://two.pairlist.net/mailman/listinfo/scons-dev
558 Subscription to the developer's mailing list is by approval. In practice, no
559 one is refused list membership, but we reserve the right to limit membership
560 in the future and/or weed out lurkers.
562 Note that while this list still exists, the number of different places you
563 can talk about SCons means it is no longer very active. GitHub has
564 support for discussions as well as for issues, and there is usually more
565 immediacy on the Discord chat, so these are probably now considered the
566 preferred places for "development" topics.
572 If you find SCons helpful, please consider making a donation (of cash,
573 software, or hardware) to support continued work on the project. Information
576 http://www.scons.org/donate.html
580 GitHub Sponsors button on https://github.com/scons/scons
586 Check the SCons web site at:
588 http://www.scons.org/
594 SCons was originally written by Steven Knight, knight at baldmt dot com.
595 Since around 2010 it has been maintained by the SCons
596 development team, co-managed by Bill Deegan and Gary Oberbrunner, with
597 many contributors, including but not at all limited to:
611 - Christoph Wiedemann
615 \... and many others.
617 Copyright (c) 2001 - 2023 The SCons Foundation