3 <!ENTITY % scons SYSTEM "../scons.mod">
7 <chapter id="chap-overview"
8 xmlns="http://www.scons.org/dbxsd/v1.0"
9 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10 xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">
11 <title>Overview</title>
17 Permission is hereby granted, free of charge, to any person obtaining
18 a copy of this software and associated documentation files (the
19 "Software"), to deal in the Software without restriction, including
20 without limitation the rights to use, copy, modify, merge, publish,
21 distribute, sublicense, and/or sell copies of the Software, and to
22 permit persons to whom the Software is furnished to do so, subject to
23 the following conditions:
25 The above copyright notice and this permission notice shall be included
26 in all copies or substantial portions of the Software.
28 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
29 KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
30 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 <section id="sect-architecture">
39 <title>Architecture</title>
43 The heart of &SCons; is its <emphasis>Build Engine</emphasis>.
44 The &SCons; Build Engine is a Python module
45 that manages dependencies between
47 such as files or database records.
48 The Build Engine is designed to
50 and easily embeddable in any
51 software system that needs dependency
52 analysis between updatable objects.
58 The key parts of the Build Engine architecture
59 are captured in the following quasi-UML diagram:
64 <title>&SCons; Architecture</title>
67 <imagedata fileref="engine.svg" align="center" scale="50"/>
70 <imagedata fileref="engine.jpg" align="center"/>
77 The point of &SCons; is to manage
78 dependencies between arbitrary external objects.
79 Consequently, the Build Engine does not restrict or specify
80 the nature of the external objects it manages,
81 but instead relies on subclass of the &Node;
82 class to interact with the external system or systems
83 (file systems, database management systems)
84 that maintain the objects being examined or updated.
90 The Build Engine presents to the software system in
92 a Python API for specifying source (input) and target (output) objects,
93 rules for building/updating objects,
94 rules for scanning objects for dependencies, etc.
96 the Build Engine is completely
97 interface-independent,
98 and can be encapsulated by any other software
99 that supports embedded Python.
105 Software that chooses to use the Build Engine
106 for dependency management
108 through <emphasis>Construction Environments</emphasis>.
109 A Construction Environment consists
110 of a dictionary of environment variables,
111 and one or more associated
113 and &Builder; objects.
114 The Python API is used to
115 form these associations.
121 A &Scanner; object specifies
122 how to examine a type of source object
123 (C source file, database record)
124 for dependency information.
125 A &Scanner; object may use
126 variables from the associated
127 Construction Environment
128 to modify how it scans an object:
129 specifying a search path for included files,
130 which field in a database record to consult,
137 A &Builder; object specifies
138 how to update a type of target object:
139 executable program, object file, database field, etc.
140 Like a &Scanner; object,
141 a &Builder; object may use
142 variables from the associated
143 Construction Environment
144 to modify how it builds an object:
145 specifying flags to a compiler,
146 using a different update function,
153 &Scanner; and &Builder; objects will return one or more
154 &Node; objects that represent external objects.
155 &Node; objects are the means by which the
156 Build Engine tracks dependencies:
157 A &Node; may represent a source (input) object that
158 should already exist,
159 or a target (output) object which may be built,
161 The &Node; class is sub-classed to
162 represent external objects of specific type:
163 files, directories, database fields or records, etc.
164 Because dependency information, however,
165 is tracked by the top-level &Node; methods and attributes,
166 dependencies can exist
167 between nodes representing different external object types.
169 building a file could be made
170 dependent on the value of a given
171 field in a database record,
172 or a database table could depend
173 on the contents of an external file.
179 The Build Engine uses a &Job; class (not displayed)
180 to manage the actual work of updating external target objects:
181 spawning commands to build files,
182 submitting the necessary commands to update a database record,
184 The &Job; class has sub-classes
185 to handle differences between spawning
186 jobs in parallel and serially.
192 The Build Engine also uses a
193 &Signature; class (not displayed)
194 to maintain information about whether
195 an external object is up-to-date.
196 Target objects with out-of-date signatures
197 are updated using the appropriate
205 Details on the composition, methods,
206 and attributes of these classes
207 are available in the A HREF="internals.html" Internals /A page.
216 <section id="sect-engine">
217 <title>Build Engine</title>
221 More detailed discussion of some of the
222 Build Engine's characteristics:
227 <title>Python API</title>
231 The Build Engine can be embedded in any other software
232 that supports embedding Python:
234 in a wrapper script that
235 interprets classic <filename>Makefile</filename> syntax,
236 or in any other software that
237 can translate its dependency representation
238 into the appropriate calls to the Build Engine API.
239 <!--<xref linkend="chap-native">--> describes in detail
240 the specification for a "Native Python" interface
241 that will drive the &SCons; implementation effort.
248 <title>Single-image execution</title>
252 When building/updating the objects,
253 the Build Engine operates as a single executable
254 with a complete Directed Acyclic Graph (DAG)
255 of the dependencies in the entire build tree.
256 This is in stark contrast to the
257 commonplace recursive use of Make
258 to handle hierarchical directory-tree builds.
265 <title>Dependency analysis</title>
269 Dependency analysis is carried out via digital signatures
270 (a.k.a. "fingerprints").
271 Contents of object are examined and reduced
272 to a number that can be stored and compared to
273 see if the object has changed.
274 Additionally, &SCons; uses the same
275 signature technique on the command-lines that
276 are executed to update an object.
277 If the command-line has changed since the last time,
278 then the object must be rebuilt.
285 <title>Customized output</title>
289 The output of Build Engine is customizable
290 through user-defined functions.
291 This could be used to print additional desired
292 information about what &SCons; is doing,
293 or tailor output to a specific build analyzer,
301 <title>Build failures</title>
305 &SCons; detects build failures via the exit status from the tools
306 used to build the target files. By default, a failed exit status
307 (non-zero on UNIX systems) terminates the build with an appropriate
308 error message. An appropriate class from the Python library will
309 interpret build-tool failures via an OS-independent API.
315 If multiple tasks are executing in a parallel build, and one tool
316 returns failure, &SCons; will not initiate any further build tasks,
317 but allow the other build tasks to complete before terminating.
323 A <option>-k</option> command-line option may be used to ignore
324 errors and continue building other targets. In no case will a target
325 that depends on a failed build be rebuilt.
335 <section id="sect-interfaces">
336 <title>Interfaces</title>
340 As previously described,
341 the &SCons; Build Engine
342 is interface-independent above its Python API,
343 and can be embedded in any software system
344 that can translate its dependency requirements
345 into the necessary Python calls.
351 The "main" &SCons; interface
352 for implementation purposes,
353 uses Python scripts as configuration files.
354 Because this exposes the Build Engine's Python API to the user,
355 it is current called the "Native Python" interface.
361 This section will also discuss
362 how &SCons; will function in the context
363 of two other interfaces:
364 the &Makefile; interface of the classic &Make; utility,
365 and a hypothetical graphical user interface (GUI).
370 <title>Native Python interface</title>
374 The Native Python interface is intended to be the primary interface
375 by which users will know &SCons;--that is,
376 it is the interface they will use
377 if they actually type &SCons; at a command-line prompt.
383 In the Native Python interface, &SCons; configuration files are simply
384 Python scripts that directly invoke methods from the Build Engine's
385 Python API to specify target files to be built, rules for building
386 the target files, and dependencies. Additional methods, specific to
387 this interface, are added to handle functionality that is specific to
388 the Native Python interface: reading a subsidiary configuration file;
389 copying target files to an installation directory; etc.
395 Because configuration files are Python scripts, Python flow control
396 can be used to provide very flexible manipulation of objects and
397 dependencies. For example, a function could be used to invoke a common
398 set of methods on a file, and called iteratively over an array of
405 As an additional advantage, syntax errors in &SCons; Native Python
406 configuration files will be caught by the Python parser. Target-building
407 does not begin until after all configuration files are read, so a syntax
408 error will not cause a build to fail half-way.
415 <title>Makefile interface</title>
419 An alternate &SCons; interface would provide backwards
420 compatibility with the classic &Make; utility.
421 This would be done by embedding the &SCons; Build Engine
422 in a Python script that can translate existing
423 &Makefile;s into the underlying calls to the
424 Build Engine's Python API
425 for building and tracking dependencies.
426 Here are approaches to solving some of the issues
427 that arise from marrying these two pieces:
435 &Makefile; suffix rules can be translated
436 into an appropriate &Builder; object
437 with suffix maps from the Construction Environment.
443 Long lists of static dependences
444 appended to a &Makefile; by
445 various <command>"make depend"</command> schemes
448 the more accurate dependency information
449 provided by &Scanner; objects.
455 Recursive invocations of &Make;
456 can be avoided by reading up
457 the subsidiary &Makefile; instead.
465 Lest this seem like too outlandish an undertaking,
466 there is a working example of this approach:
467 Gary Holt's &Makepp; utility
468 is a Perl script that provides
469 admirably complete parsing of complicated &Makefile;s
470 around an internal build engine inspired,
471 in part, by the classic <application>Cons</application> utility.
478 <title>Graphical interfaces</title>
482 The &SCons; Build Engine
483 is designed from the ground up to be embedded
484 into multiple interfaces.
485 Consequently, embedding the dependency capabilities
486 of &SCons; into graphical interface
487 would be a matter of mapping the
488 GUI's dependency representation
489 (either implicit or explicit)
490 into corresponding calls to the Python API
491 of the &SCons; Build Engine.
497 Note, however, that this proposal leaves the problem of
498 designed a good graphical interface
499 for representing software build dependencies
500 to people with actual GUI design experience...