Scons



SCons: A software construction tool. SCons - a software construction tool Welcome to the SCons development tree. The real purpose of this tree is to package SCons for production distribution in a variety of formats, not just to hack SCons code.

SCons
Original author(s)Steven Knight
Stable release
Repositorygithub.com/SConsProject/scons
Written inPython
Operating systemCross-platform
TypeSoftware development tools
LicenseMIT License
Websitescons.org

SCons is a computer software build tool that automatically analyzes source code file dependencies and operating system adaptation requirements from a software project description and generates final binary executables for installation on the target operating system platform. Its function is analogous to the traditional GNU build system based on the make utility and the autoconf tools.

SCons generates project configurations and build process implementations in the form of Python scripts.

Major features[edit]

Major SCons features include the following:

  • Configuration files are Python scripts, which means that user-written builds have access to a complete general-purpose programming language.
  • Automatic dependency analysis built-in for C, C++ and Fortran. Dependency analysis is extensible through user-defined dependency scanners for other languages or file types. Unlike the GNU Compiler Collection's (GCC) built-in dependency analysis, it uses a regular expression scan for included source files.
  • Built-in support for C, C++, D, Java, Fortran, Objective-C, Yacc, Lex, Qt and SWIG, as well as TeX and LaTeX documents. SCons can also handle other languages or file types through user-defined builders.
  • Building from central repositories of source code and pre-built targets.
  • Built-in ability to use Microsoft Visual Studio, including the generation of .dsp, .dsw, .sln and .vcproj files.
  • Detection of file content changes using MD5 signatures; optional, configurable ability to use traditional timestamps.
  • Ability to do parallel builds, maintaining a specified number of jobs running simultaneously regardless of directory hierarchy.
  • Integrated Autoconf-like support for finding #include files, libraries, functions and typedefs.
  • Global view of all dependencies, so multiple build passes or reordering targets is not required.
  • Ability to share built files in a cache to speed up multiple builds - like ccache but for any type of target file, not just C/C++ compilation.
  • Designed from the ground up for cross-platform builds, and known to work on POSIX systems (including Linux, IBM AIX and OS/2, *BSD Unices, HP-UX, SGIIRIX, Solaris, illumos), MSWindows NT, AppleOS X.

History and related projects[edit]

SCons software history started with the Cons software construction utility created by Bob Sidebotham in 1999.[2] Cons was written in the Perl language. It served as a base for the ScCons build tool, a design which won the Software Carpentry project SC Build competition in August 2000.[3] ScCons was the foundation for SCons.

SCons inspired the creation of Waf, formerly known as SCons/BKsys, which emerged in the KDE community. For some time, there were plans to use it as the build tool for KDE 4 and beyond, but that effort was abandoned in favor of CMake.[4]

Notable applications that use SCons include the following: The Battle for Wesnoth,[5]Battlefield 1942,[citation needed]Doom 3,[6]FCEUX,[7] gem5,[8]gpsd,[9]GtkRadiant,[10]Madagascar,[11]Mixxx,[12]MongoDB,[13]Nullsoft Scriptable Install System,[14]OpenNebula,[15]VMware,[citation needed], Wolfenstein: Enemy Territory,[16]XORP and MCA2,[17] and Godot.[18]

Examples[edit]

The following example is a very simple SConstruct file that compiles the C program file hello-world.c using the default platform compiler:

The following is a more complex example that creates an environment used to build the program hello:

See also[edit]

References[edit]

  1. ^https://scons.org/archives.html
  2. ^Cons (web site), DSMit, archived from the original on 2000-08-15.
  3. ^Samuel, Alex (2000-08-04). 'Software Carpentry Design Competition Second Round Results Config, Build, and Track categories'. Retrieved 2012-10-29.
  4. ^Neundorf, Alexander (21 June 2006). 'Why the KDE project switched to CMake – and how (continued)'. LWN. Retrieved 21 July 2009.
  5. ^'CompilingWesnoth'. Wiki. Wesnoth. Retrieved 2011-04-11.
  6. ^'README.txt'. id Software. Retrieved 2015-05-13.
  7. ^'Downloads'. FCEUX. Retrieved 2017-04-25.
  8. ^Gem5.
  9. ^'SCons is full of win today'. ESR. iBiblio. 2011-04-05. Retrieved 2011-04-11.
  10. ^'Developer documentation for GtkRadiant 1.6.0 (Zeroradiant)'(Trac). QE radiant. 2008-06-30. Retrieved 2009-12-28.
  11. ^'Installation'. Wiki. Ahay. 2011-02-26. Retrieved 2011-04-11.
  12. ^'Mixxx/Compiling'. 2014-08-26.
  13. ^'Building for Linux'. MongoDB. 10gen. January 30, 2009. Archived from the original on February 21, 2009. Retrieved February 8, 2011.
  14. ^'INSTALL'. NSIS (source code). Source forge. 2011-05-28. Archived from the original on 2012-07-11. Retrieved 2011-04-11.
  15. ^'/SConstruct - OpenNebula - OpenNebula Development pages'. OpenNebula Project. Retrieved 2016-01-09.
  16. ^'README.txt'. id Software. Retrieved 2017-04-25.
  17. ^'Modular Controller Architecture'. Research Center for Information Technology (FZI), Karlsruhe Institute of Technology (KIT).
  18. ^'Introduction to the buildsystem — Godot Engine latest documentation'. docs.godotengine.org. Retrieved 2019-08-19.
Scon

External links[edit]

  • Neagu, Adrian (9 July 2005), 'Make Alternatives', Freecode (Freshmeat), retrieved 21 September 2014
  • Hähne, Ludwig (August 21, 2008), Empirical Comparison of SCons and GNU Make(PDF), Technical University Dresden: Genode labs
Retrieved from 'https://en.wikipedia.org/w/index.php?title=SCons&oldid=1018042206'

SCons (from Software Construction) is a superior alternative to the classic make utility.

SCons is implemented as a Python script, its 'configuration files' (SConstruct files) are also Python scripts. Madagascar uses SCons to compile software, to manage data processing flowing, and to assemble reproducible documents.

  • 3Data processing flows with rsf.proj
    • 3.1SConstruct commands
  • 5Document creation with rsf.tex
  • 6Book and report creation with rsf.book
  • 7Errors and Debugging

Useful SCons options

  • scons -h (help) displays a help message.

Sconsis

  • scons -Q (quiet) suppresses progress messages.
  • scons -n (no exec) outputs the commands required for building the specified target (or the default targets if no target is specified) without actually executing them. It can be used to generate a shell script out of SConstruct script, as follows:

Compilation

SCons was designed primarily for compiling software code. An SConstruct file for compilation may look like

and produce something like

to compile the hello program from the source files hello.c and main.c.

Madagascar uses SCons to compile its programs from the source. The more frequent usage, however, comes from adopting SCons to manage data processing flows.

Data processing flows with rsf.proj

The rsf.proj module provides SCons rules for Madagascar data processing workflows. An example SConstruct file is shown below and can be found in bei/sg/denmark

Note that SConstruct by itself does not do any job other than setting rules for building different targets. The targets get built when one executes scons on the command line. Running scons produces

Obviously, one could also run similar commands with a shell script. What makes SCons convenient is the way it behaves when we make changes in the input files or in the script. Let us change, for example, the mute velocity parameter in the second Flow command. You can do that with an editor or on the command line as

Now let us run scons again

We can see that scons executes only the parts of the data processing flow that were affected by the change. By keeping track of dependencies, SCons makes it easier to modify existing workflows without the need to rerun everything after each change.

SConstruct commands

Fetch(<file[s]>,<directory>,[options])

defines a rule for downloading data files from the specified directory on an external data server (by default) or from another directory on disk. The optional parameters that control its behavior are summarized below.

Fetch options
NameDefaultMeaning
privateNoneif the data file is private
server$RSF_DATASERVER or http://www.reproducibility.orgremote data server (or local for local files)
topdataname of the top data directory on the data server
dirNonename of directory after top
usedatapath1usedatapath=1 - download to $DATAPATH with symbolic link.

usedatapath=0 - download to pwd

In the example above, Fetch specifies the rule for getting the file wz.35.H: connect to the default data sever and download the file from the data/wz directory.

An example to Fetch with more parameters is:


Flow(<target[s]>,<source[s]>,<command>,[options])

defines a rule for creating targets from sources by running the specified command through Unix shell. The optional parameters that control its behavior are summarized below.

Flow options
NameDefaultMeaning
stdout1if output to standard out (0 for output to /dev/null, -1 for no output)
stdin1if take input from standard in (0 for no input)
rsfflow1if using Madagascar commands
suffix'.rsf'default suffix for output files
prefix'sf'default prefix for programs
src_suffix'.rsf'default suffix for input files
split[]split the flow for data parallel processing
reduce'cat'how to reduce the output from data parallel processing
local0if execute on the local node when using data parallel processing on a cluster

In the example above, there are two Flow commands. The first one involves a Unix pipe in the command definition.

On the use of parallel computing options, see Parallel Computing.

Plot(<target>,[<source[s]>],<command>,[options])

is similar to Flow but generates a graphics file (Vplot file) instead of an RSF file. If the source file is not specified, it is assumed that the name of the output file (without the .vpl suffix) is the same as the name of the input file (without the .rsf suffix).

Plot options
NameDefaultMeaning
suffix'.vpl'default suffix for the output file
vppenNoneadditional options to pass to vppen
viewNoneif set, show the output on the screen instead of saving it in a file

In the example above, there are two Plot commands.

Scones

Result(<target>,[<source[s]>],<command>,[options])

is similar to Plot, only the output graphics file is put not in the current directory but in a separate directory (./Fig by default). The output is intended for inclusion in papers and reports.

Result options
NameDefaultMeaning
suffix'.vpl'default suffix for the output file

In the example above, Result defines a rule that combines the results of two Plot rules into one plot by arranging them side by side. The rules for combining different figures together (which apply to both Plot and Result commands) include:

  • SideBySideAniso
  • OverUnderAniso
  • SideBySideIso
  • OverUnderIso
  • TwoRows
  • TwoColumns
  • Overlay
  • Movie

End()

takes no arguments and signals the end of data processing rules. It provides the following targets, which operate on all previously specified Result figures:

  • scons view displays the resuts on the screen.
  • scons print sends the results to the printer (specified with PSPRINTER environmental variable).
  • scons lock copies the results to a location inside the DATAPATH tree.
  • scons test compares the previously 'locked' results with the current results and aborts with an error in case of mismatch.

The default target is set to be the collection of all Result figures.

Command-line options

Command-line options
NameMeaning
TIMERWhether to time execution
CHECKPARWhether to check parameters
ENVIRONAdditional environment settings
CLUSTERNodes available on a cluster
MPIRUNmpirun command

Running the example above with TIMER=y produces

In other words, every shell command is preceded by the Unix time utility to measure the CPU time of the process.

Scones Recipe

Running the example above with CHECKPAR=y, we will not see any difference. Suppose, however, that we made a typo in specifying one of the parameters, for example, by using v1= instead of v0= in the arguments to sfmutter.

The parameter error gets detected by scons before anything is executed.

Seismic Unix data processing flows with rsf.suproj

If you process data with Seismic Unix instead of Madagascar, you can still take advantage of SCons-based processing flows by using the rsf.suproj module. See book/rsf/su for examples.

Note that, with rsf.suproj, the scons command generates hard copies (eps files) of Result figures, while the scons view command displays figures on the screen using the corresponding X-window plotting commands.

Document creation with rsf.tex

SConstruct commands

  • Paper
  • End([options]) signals the end of book processing rules. It provides the following targets:
    • scons pdf (equivalent to scons paper.pdf)
    • scons wiki (equivalent to scons paper.wiki)
    • scons read (equivalent to scons paper.read)
    • scons print (equivalent to scons paper.print)
    • scons html (equivalent to scons paper.html)
    • scons install (equivalent to scons paper.install)
    • scons figs (equivalent to scons paper.figs)

The default target is set to pdf.

Book and report creation with rsf.book

SConstruct commands

  • Book
  • Papers

Scons How To Export Dependency Graph

  • End([options]) signals the end of book processing rules. It provides the following targets:
    • scons pdf
    • scons read
    • scons print
    • scons html
    • scons www

The default targret is set to be scons pdf.

Errors and Debugging

DBPageNotFoundError

The scons database contains the information required so that scons executes only the parts of the data processing flow that were affected by changes in data, programs, and flows. Sometimes the database become corrupted. For example, when I ran out of disk space my scons stopped leaving a corrupted database. After deleting some files to create enough disk space running scons quickly fails with the message:

I was working in the directory $RSFSRC/book/data/alaska/line31-81. Scons keeps the database in the file $DATAPATH/data/alaska/line31-81/.sconsign.dbhash. It's a little tricky to find this file since it is hidden file in a directory below $DATAPATH. Removing $DATAPATH/data/alaska/line31-81/.sconsign.dbhash fixed this problem.

Retrieved from 'http://www.ahay.org/wiki2020/index.php?title=SCons&oldid=3745'