Introduction


  • SCons allows us to specify what depends on what and how to update things that are out of date.

SConscript files


  • SConstruct is the default name of the root SCons configuration file
  • SCons configuration files are collectively called SConscript files
  • SConscript files are Python files.
  • SCons tasks are attached to a construction environment, which can be inherited from the shell’s active environment.
  • Use # for comments in SConscript files.
  • Write tasks as lists of targets, sources, and actions with the Command class
  • Use an Alias to collect targets in a convenient alias for shorter build commands.
  • Use the Default function to limit the number of default targets to a subset of all targets.

Special Substitution Variables


  • Use ${TARGET} to refer to the target of the current task.
  • Use ${SOURCES} to refer to the dependencies of the current task.
  • Use ${SOURCES[0]} to refer to the first dependency of the current task.

Dependencies on Data and Code


  • SCons results depend on processing scripts as well as data files.
  • Dependencies are transitive: if A depends on B and B depends on C, a change to C will indirectly trigger the pipeline to update to A.
  • SCons content signatures help prevent recomputing work if intermediate targets’ contents do not change after recreation.

Builders and Pseudo-builders


  • Use the Builder function and Append the construction environment BUILDERS dictionary to define common actions.
  • Use the AddMethod function and Python functions to define pseudo-builders with custom tailored task handling.
  • Use the special SCons variable COMMAND_LINE_TARGETS to perform dynamic handling that depends on command line target requests.

Variables


  • Define variables by assigning values to names with Python syntax
  • Reference variables in action strings using SCons substitution syntax ${...}.

Functions


  • SCons uses the Python programming language with acces to all of Python’s many built-in functions.
  • SCons provides many functions that work natively with the internal node objects required to manage the SCons directed graph.
  • Use the SCons Glob function to get lists of SCons nodes from file names matching a pattern.
  • Use Python built-in and standard library modules to manage file names and paths.

Self-Documenting SConstruct files


  • Document SConstruct options, targets, and aliases with the SCons default_ans and DEFAULT_TARGETS variables and the Help function.

Conclusion


  • SCons and SConscript files save time by automating repetitive work, and save thinking by documenting how to reproduce results.