Debian Codegraph @

doc/source/tutorial/integration-commands.rst

raw
1 ..
2 Licensed under the Apache License, Version 2.0 (the "License");
3 you may not use this file except in compliance with the License.
4 You may obtain a copy of the License at
5
6 http://www.apache.org/licenses/LICENSE-2.0
7
8 Unless required by applicable law or agreed to in writing, software
9 distributed under the License is distributed on an "AS IS" BASIS,
10 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 See the License for the specific language governing permissions and
12 limitations under the License.
13
14
15
16 .. _tutorial_integration_commands:
17
18 Integration commands
19 ====================
20 Sometimes a software requires more configuration or processing than what is
21 performed at installation time, otherwise it will not run properly.
22
23 This is especially true in cases where a daemon or library interoperates
24 with third party extensions and needs to maintain a system wide cache whenever
25 its extensions are installed or removed; system wide font caches are an example
26 of this.
27
28 In these cases we use :ref:`integration commands <public_integration>` to
29 ensure that a runtime is ready to run after all of its components have been *staged*.
30
31 .. note::
32
33 This example is distributed with BuildStream
34 in the `doc/examples/integration-commands
35 <https://github.com/apache/buildstream/tree/master/doc/examples/integration-commands>`_
36 subdirectory.
37
38
39 Overview
40 --------
41 In this chapter, we'll be exploring :ref:`integration commands <public_integration>`,
42 which will be our first look at :ref:`public data <format_public>`.
43
44
45 Project structure
46 -----------------
47
48
49 ``project.conf`` and ``elements/base.bst``
50 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51 The project.conf and base stack :mod:`stack <elements.stack>` element are configured in the
52 same way as in the previous chapter: :ref:`tutorial_running_commands`.
53
54
55 ``elements/base/alpine.bst``
56 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57
58 .. literalinclude:: ../../examples/integration-commands/elements/base/alpine.bst
59 :language: yaml
60
61 This is the same ``base/alpine.bst`` we've seen in previous chapters,
62 except that we've added an :ref:`integration command <public_integration>`.
63
64 This informs BuildStream that whenever the output of this element is
65 expected to *run*, this command should be run first. In this case we
66 are simply running ``ldconfig`` as a precautionary measure, to ensure
67 that the runtime linker is ready to find any shared libraries we may
68 have added to ``%{libdir}``.
69
70
71 Looking at public data
72 ''''''''''''''''''''''
73 The :ref:`integration commands <public_integration>` used here is the first time
74 we've used any :ref:`builtin public data <public_builtin>`.
75
76 Public data is a free form portion of an element's configuration and
77 is not necessarily understood by the element on which it is declared, public
78 data is intended to be read by its reverse dependency elements.
79
80 This allows annotations on some elements to inform elements later in
81 the dependency chain about details of its artifact, or to suggest how
82 it should be processed.
83
84
85 ``elements/libhello.bst`` and ``elements/hello.bst``
86 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87 These are basically manual elements very similar to the ones we've
88 seen in the previous chapter: :ref:`tutorial_running_commands`.
89
90 These produce a library and a hello program which uses the library,
91 we will consider these irrelevant to the topic and leave examination
92 of `their sources
93 <https://github.com/apache/buildstream/tree/master/doc/examples/integration-commands/files>`_
94 as an exercise for the reader.
95
96
97 Using the project
98 -----------------
99
100
101 Build the hello.bst element
102 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
103 To build the project, run :ref:`bst build <invoking_build>` in the
104 following way:
105
106 .. raw:: html
107 :file: ../sessions/integration-commands-build.html
108
109 Observe in the build process above, the integration command declared on the
110 ``base/alpine.bst`` element is run after staging the dependency artifacts
111 into the build sandbox and before running any of the build commands, for
112 both of the ``libhello.bst`` and ``hello.bst`` elements.
113
114 BuildStream assumes that commands which are to be run in the build sandbox
115 need to be run in an *integrated* sandbox.
116
117 .. tip::
118
119 Integration commands can be taxing on your overall build process,
120 because they need to run at the beginning of every build which
121 :ref:`runtime depends <format_dependencies_types>` on the element
122 declaring them.
123
124 For this reason, it is better to leave out more onerous tasks
125 if they are not needed at software build time, and handle those
126 specific tasks differently later in the pipeline, before deployment.
127
128
129 Run the hello world program
130 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
131 Unlike the previous chapters, this hello world program takes an argument,
132 we can invoke the program using :ref:`bst shell <invoking_shell>`:
133
134 .. raw:: html
135 :file: ../sessions/integration-commands-shell.html
136
137 Here we see again, the integration commands are also used when preparing
138 the shell to launch a command.
139
140
141 Summary
142 -------
143 In this chapter we've observed how :ref:`integration commands <public_integration>`
144 work, and we now know about :ref:`public data <format_public>`, which plugins
145 can read from their dependencies in order to influence their build process.