Skip to content

Commit 7333aa6

Browse files
lberkicopybara-github
authored andcommitted
Write a large comment explaining the build info machinery.
RELNOTES: None. PiperOrigin-RevId: 409904095
1 parent f90d939 commit 7333aa6

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

src/main/java/com/google/devtools/build/lib/analysis/WorkspaceStatusAction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
* <p>There are two of these files: volatile and stable. Changes in the volatile file do not cause
5959
* rebuilds if no other file is changed. This is useful for frequently-changing information that
6060
* does not significantly affect the build, e.g. the current time.
61+
*
62+
* <p>For more information, see {@link
63+
* com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory}.
6164
*/
6265
public abstract class WorkspaceStatusAction extends AbstractAction {
6366

src/main/java/com/google/devtools/build/lib/analysis/buildinfo/BuildInfoFactory.java

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,54 @@
1919
import com.google.devtools.build.lib.vfs.PathFragment;
2020

2121
/**
22-
* A factory for language-specific build-info files. Use this to translate the build-info into
23-
* target-independent language-specific files. The generated actions are registered into the action
24-
* graph on every build, but only executed if anything depends on them.
22+
* A factory for language-specific build-info files.
23+
*
24+
* <p>The goal of the build info system is to "stamp" non-hermetic information into output files,
25+
* for example, the time and date of the build that resulted in the output, the hostname it was run
26+
* on or the set of sources the output was built from.
27+
*
28+
* <p>This non-hermetic data gets into the action graph by calling the script specified in the
29+
* <code>--workspace_status_command</code> command line argument, which results in a text file which
30+
* containts a build info entry in each line, with its name ("key") and value separated by a space.
31+
* This script is unconditionally invoked on every build and therefore should be very fast.
32+
*
33+
* <p>Build info keys come in two kinds: volatile and non-volatile. The difference is that the
34+
* former is expected to change very frequently (e.g. current time) and therefore changes to it
35+
* should not invalidate downstream actions whereas a rebuild is required if a non-volatile build
36+
* info entry changes.
37+
*
38+
* <p>This is accomplished by splitting the build info file emitted by the workspace status command
39+
* into two files, a volatile and a non-volatile. The former kind of artifact is special-cased in
40+
* the execution phase machinery so that changes to it never trigger a rebuild. This artifact is
41+
* marked by {@link
42+
* com.google.devtools.build.lib.actions.Artifact.SpecialArtifactType#CONSTANT_METADATA}.
43+
*
44+
* <p>The invocation of the workspace status command and splitting its output into two is done in
45+
* descendants of {@link com.google.devtools.build.lib.analysis.WorkspaceStatusAction} .
46+
*
47+
* <p>However, this is not enough because the workspace status files cannot always be ingested by
48+
* the actions that need them; for example, if a C++ file wants to incorporate build info, the
49+
* compiler cannot process build info text files, therefore the data needs to be transformed into a
50+
* format that the compiler likes.
51+
*
52+
* <p>This is done for each language by an implementation of {@link BuildInfoFactory}: rules can
53+
* call {@link com.google.devtools.build.lib.analysis.AnalysisEnvironment#getBuildInfo(boolean,
54+
* BuildInfoKey, BuildConfigurationValue)} with the language-specific build info key, which then
55+
* invokes {@link com.google.devtools.build.lib.skyframe.BuildInfoCollectionFunction}, which in turn
56+
* calls the language-specific implementation of {@link BuildInfoFactory}, which creates the
57+
* language-specific actions and artifacts. These are then returned to the caller of {@code
58+
* getBuildInfo()} (This could probably be replaced by an implicit dependency on a language-specific
59+
* special rule does all this; there are only historical reasons why it works this way)
60+
*
61+
* <p>{@link com.google.devtools.build.lib.skyframe.BuildInfoCollectionValue} is a thin wrapper
62+
* around the data structure {@code BuildInfoFactory} returns (a set of artifacts and actions). Its
63+
* purpose is to allow Skyframe to look up the generating actions of build info artifacts. This is
64+
* done by implementing {@link com.google.devtools.build.lib.actions.ActionLookupValue}. It is
65+
* necessary because actions are usually generated by configured targets or aspects, but not build
66+
* info actions which are instead created by the mechanism described above.
67+
*
68+
* <p>Build info factories are registered in {@link
69+
* com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider}.
2570
*/
2671
public interface BuildInfoFactory {
2772
/**

src/main/java/com/google/devtools/build/lib/analysis/buildinfo/BuildInfoKey.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
/**
1717
* Build-info key for lookup from the {@link
1818
* com.google.devtools.build.lib.analysis.AnalysisEnvironment}.
19+
*
20+
* <p>For more information, see {@link
21+
* com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory}.
1922
*/
2023
public final class BuildInfoKey {
2124
private final String name;

src/main/java/com/google/devtools/build/lib/skyframe/BuildInfoCollectionFunction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
/**
3737
* Creates a {@link BuildInfoCollectionValue}. Only depends on the unique {@link
3838
* WorkspaceStatusValue} and the constant {@link #BUILD_INFO_FACTORIES} injected value.
39+
*
40+
* <p>For more information, see {@link
41+
* com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory}.
3942
*/
4043
public class BuildInfoCollectionFunction implements SkyFunction {
4144

0 commit comments

Comments
 (0)