|
19 | 19 | import com.google.devtools.build.lib.vfs.PathFragment;
|
20 | 20 |
|
21 | 21 | /**
|
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}. |
25 | 70 | */
|
26 | 71 | public interface BuildInfoFactory {
|
27 | 72 | /**
|
|
0 commit comments