Skip to content

Commit ff93377

Browse files
committed
docs: Add 'Execution of BuildStream Elements' page
WIP!
1 parent 1a7651a commit ff93377

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
Execution of BuildStream Elements
2+
=================================
3+
4+
This page provides a guide on how BuildStream elements are converted
5+
into executable build steps, including how element types may affect
6+
this.
7+
8+
When a BuildStream element is being built, it can roughly be broken down
9+
into these individual stages:
10+
11+
- Sources are fetched
12+
- The sandbox is prepared
13+
- Configure and Run commands
14+
- Install Commands and Caching Artifacts
15+
16+
Sources are fetched
17+
-------------------
18+
19+
The hidden first step is actually validating the ``yaml``. This includes
20+
resolving includes, options, appends, which are denoted by ``(@)``,
21+
``(?)`` and ``(>)`` respectively.
22+
23+
The first step once the ``yaml`` has been validated is that BuildStream
24+
will fetch the sources. This is dependent on the source ``kind`` as to
25+
how these are fetched. After the sources are fetched they may need to
26+
checked. For example a ``kind: tar`` would need to check the ``sha256``
27+
matches, and a ``git_repo`` source would need to switch to the specified
28+
commit sha.
29+
30+
The Sandbox is prepared
31+
-----------------------
32+
33+
The Sandbox is prepared as a temporary filesystem, where build
34+
dependencies (``build-depends:``) and general dependencies (``depends``)
35+
are staged, along with their own runtime dependencies. This happens in
36+
an abstract state, which can quickly spot repeated files and overlaps.
37+
38+
In general when a dependency is being staged, the produced artifact is
39+
added from the root (``/``). This can sometimes be changed using the
40+
``location:`` attribute. In most cases dependencies are marked by
41+
BuildStream as immutable.
42+
43+
After the dependencies are staged BuildStream stages the sources in the
44+
``build-root`` location. The actual location of this differs slightly
45+
depending on the project file structure, which is why it is common to
46+
see elements use the variable ``%{build-root}`` which resolves to the
47+
correct location.
48+
49+
Configure and Build commands
50+
----------------------------
51+
52+
Now that all dependencies and sources are staged in a temporary
53+
filesystem, this filesystem is started up by BuildBox in a sandbox.
54+
55+
The first commands to be run are configure commands and it is
56+
recommended to include things like moving the sources about, generating
57+
config files and other “configure” related actions into this section.
58+
These should be the commands that can only be run once (for example a
59+
folder can only be moved once), this is due to `BuildStream
60+
workspaces <https://docs.buildstream.build/2.4/developing/workspaces.html>`__.
61+
62+
!!! tip “BuildStream Workspaces and Configure Commands”
63+
64+
::
65+
66+
When a [workspace](https://docs.buildstream.build/2.4/developing/workspaces.html)
67+
is opened, it stages all the sources for the indicated element locally, then
68+
when doing a build of that element it uses these local sources instead of
69+
pulling in fresh sources. Builds using workspaces only run configure
70+
commands once, and any subsequent builds using the same workspace will skip
71+
the configure commands step, therefore steps of the build that aren't
72+
repeatable (without re-staging sources) should be added to configure
73+
commands.
74+
75+
After Configure commands are run, then Build commands are next. Build
76+
commands are intended to contain the actual build process, for example
77+
if the build uses ``make`` then this stage should run the
78+
``make target`` command.
79+
80+
Install Commands and Caching Artifacts
81+
--------------------------------------
82+
83+
Install commands are the final commands that are run before BuildStream
84+
collects the artifacts and closes the build sandbox. Install commands
85+
should mainly be comprised of moving the built artifacts from the
86+
``${build-root}`` to the ``${install-root}``.
87+
88+
There is no need for Install commands to clean up any of the sources
89+
that aren’t going to moved, as the BuildStream handles this when the
90+
sandbox is closed.
91+
92+
Directories can be created under the install location, for example
93+
``%{install-root}/example/``, and these will be maintained when another
94+
element depends on this one, for example this will become
95+
``./example/``.
96+
97+
The contents of the install root are cached. BuildStream caches the
98+
produced artifact to reduce the need to rebuild elements, instead it can
99+
pull from this artifact cache. It will only rebuild an element if the
100+
element file changes, or if the dependencies for an element changes.
101+
102+
!!! tip “Caching Errors”
103+
104+
::
105+
106+
BuildStream will also cache build errors, and if no file has changed
107+
(including the dependencies) then BuildStream will display this cached error,
108+
without attempting a rebuild. This is sometimes not the desired behaviour,
109+
especially if the error was caused by a remote issue, like a source site
110+
being temporarily unavailable. To force an attempted build use the
111+
`-r`/`--retry-failed` option, documented
112+
[here](https://docs.buildstream.build/2.4/using_commands.html#cmdoption-bst-build-r)

0 commit comments

Comments
 (0)