Definition
The source closure of an artifact is the complete set of inputs that can affect it: its source files and everything they depend on, directly or through other inputs. For a compiled program it includes headers, generated code with the generators and data that produced it, build scripts, configuration, libraries and the toolchain §12.2. It is found by starting at the artifact and repeatedly adding the inputs of every item found until nothing new appears. Closure is meant in the mathematical sense: a set that the adding rule no longer changes.
The idea
A team changes no C source file, yet the program behaves differently after the next build. The cause is a data table, coeffs.csv, from which a script generates a header that the program includes. Anyone who took “the source” to mean the C files in one directory would say that nothing changed. The program depends on every input that reaches it through any chain of build steps, not only on the files someone happens to look at.
The source closure settles three practical matters: which inputs must be fixed to rebuild the same program; which results must be checked again after a change, the starting point of incremental validation §10.42; and what exactly was covered when a program is said to have been reviewed or tested. A family tree is a fair picture: the closure is all the ancestors, not just the parents. The picture stops being accurate in one respect. Some ancestors of a program appear only when the build runs, such as a header found through a search path or a library downloaded during the build, so the closure cannot always be read from the files stored in a repository.
How it works
Picture the build as a dependency graph. Each node is an artifact or an input, and an arrow from to means that the build step producing reads . An item reached through one or more intermediate items is a transitive dependency §10.43 of the artifact. The source closure of an artifact is every node from which a path of arrows leads to the artifact, and it is found by a graph reachability search §14.18 run backward along the arrows.
Start with the artifact of interest.
List its direct inputs. For a program produced by linking, these are the compiled object files; the libraries and the start-up code (the code that runs before the program’s main function) that the linker §12.4 joins in; the linker script §12.5, which tells the linker where to place code and data in memory; and the linker program itself.
For every input that was itself produced by a build step, add the inputs of that step. For an object file these are the source file, every header it includes, the compiler and the compiler options §12.3. Common C compilers write the list of headers each file actually included when given the option
-MD. For a generated header they are the generator script, the interpreter §2.13 that runs it and the data it reads.Repeat step 3 for every newly added item until a round adds nothing new.
Record every item with its digest. Where the search deliberately stops, for example at a released toolchain identified by its digest, record that boundary as a stated assumption.
Some inputs never appear as files in the graph: environment variables, the current date and time, the order in which the file system lists a directory, and data fetched over a network. A trace of every file and network access the build makes reveals them. A hermetic build §13.7, which runs with only its declared inputs visible, makes them impossible instead of merely unrecorded.
Worked example
A program app is linked from the object files main.o and filter.o, compiled from main.c and filter.c. Both C files include the project header filter.h; filter.c also includes the system header math.h and the header coeffs.h. The script gen.py writes coeffs.h from the data file coeffs.csv, and a Python §12.23 interpreter runs the script. The linker joins in the mathematics library libm.a and follows the linker script app.ld. The compiler runs with the options -O2 -MD. The backward search proceeds in rounds.
Round 1, inputs of the link step:
main.o,filter.o,libm.a,app.ldand the linker. That is 5 items.Round 2, inputs of the two compile steps:
main.c,filter.c,filter.h,math.h,coeffs.h, the compiler and its options. That adds 7 items.Round 3, inputs of the step that generated
coeffs.h:gen.py,coeffs.csvand the Python interpreter. That adds 3 items.Round 4 finds nothing new inside the stated boundary, which treats the compiler, the linker,
libm.a,math.hand the Python interpreter as released components, each identified by its digest.
The closure has items; a list of “the source files” has 2. If someone edits one number in coeffs.csv, gen.py writes a different coeffs.h, the compiled filter changes, and both C files stay byte-for-byte identical. Only the closure shows that app must be rebuilt and tested again.
Stated precisely
Let be a directed graph whose nodes are artifacts and inputs, with an arrow whenever the step that produces reads . For a node , let be the set of nodes with an arrow into . The source closure of an artifact is the smallest set of nodes such that and for every in . Equivalently, is the set of nodes from which a path of one or more arrows leads to : the transitive closure of the arrow relation, read backward from . For a claim about several artifacts, such as two files generated from one table that must agree with each other, the closure is the union of their closures.
The definition yields a correct closure only if the graph is complete, meaning that every way in which an input can affect an output is an arrow. Arrows taken from the compiler’s own dependency output and from a trace of every file the build opened are evidence of completeness; a hand-written list is not. Where the search stops at a declared boundary, the closure is complete only relative to that boundary, and the boundary is an assumption that must be stated.
Limits and common mistakes
Including an item in the closure does not make it correct. The closure says what must be fixed, reviewed or tested again; it proves nothing about the items in it.
Two closures must not be confused. Reproducing the exact bytes of an artifact, the goal of a reproducible build §13.8, needs every input that affects any byte, including embedded timestamps and the order of files. Supporting one property, such as the output of one function, needs only the inputs that can affect that property, a smaller set whose boundary is harder to justify. State which closure is meant.
Dependencies can be conditional or dynamic. A configuration option can switch files in or out, a header search path can find a different file on another machine, and a build can download a library. Read the dependencies from the actual build, not from the directory layout.
A version-control commit covers only the files it tracks. Generated files, untracked files, files the version-control system is told to ignore, and the tools themselves are all outside it.
The toolchain is an input, and it was built by an earlier toolchain. Ken Thompson’s 1984 paper Reflections on Trusting Trust [239] showed that a compiler binary can be altered to insert hidden code into the programs it compiles, including new copies of the compiler, while the compiler’s source code stays clean. A practical closure therefore stops at a declared boundary, such as a released toolchain identified by its digest, and names that boundary as an assumption.
A closure that names files without their digests does not fix their versions.
Questions answered
Are generated code, headers, scripts, configuration, and libraries included?
Yes: generated code, headers, scripts, configuration and libraries all belong to the source closure of an artifact whenever they can affect it. The source closure is the complete set of inputs that can affect the artifact, directly or through other inputs. Generated code brings in the generator that wrote it, the interpreter that ran the generator and the data the generator read. Headers count whether they belong to the project or to the system. Build scripts and configuration count because they decide which files are compiled and with which options. Libraries linked into the program count, and so do the start-up code and the linker script; if the claim concerns the program’s behavior, libraries it loads while running count as well. The compiler, the linker and their versions count too.
The reliable way to find all of these is to read them from the actual build, using the compiler’s own dependency output and a trace of every file the build opened, and to follow them backward until no new input appears. Where the search stops, for example at a released toolchain identified by its digest, that boundary is stated as an assumption.
Related entries: Toolchain (§12.2), Manifest (§13.4), Hermetic build (§13.7), Incremental validation (§10.42), Transitive dependency (§10.43), Reproducible build (§13.8), Graph reachability search (§14.18). Further reading: [239].