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