Debian Codegraph @

doc/source/tutorial/autotools.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_autotools:
17
18 Using the autotools element
19 ===========================
20 In :ref:`the last chapter <tutorial_running_commands>` we observed how the
21 :mod:`manual <elements.manual>` element works, allowing one to specify and
22 run commands manually in the process of constructing an *artifact*.
23
24 In this chapter, we'll go over a mostly automated build of a similar
25 hello world example. We will observe how our configurations of the
26 :mod:`autotools <elements.autotools>` element translate to configurations
27 on the :mod:`manual <elements.manual>` element, and observe how
28 :ref:`variable substitution <format_variables>` works.
29
30 .. note::
31
32 This example is distributed with BuildStream
33 in the `doc/examples/autotools
34 <https://github.com/apache/buildstream/tree/master/doc/examples/autotools>`_
35 subdirectory.
36
37
38 Overview
39 --------
40 Instead of using the :mod:`local <sources.local>` source as we have been using
41 in the previous examples, we're going to use a :mod:`tar <sources.tar>` source
42 this time to obtain the ``automake`` release tarball directly from the upstream
43 hosting.
44
45 In this example we're going to build the example program included in the
46 upstream ``automake`` tarball itself, and we're going to use the automated
47 :mod:`autotools <elements.autotools>` build element to do so.
48
49
50 Project structure
51 -----------------
52
53
54 ``project.conf``
55 ~~~~~~~~~~~~~~~~
56
57 .. literalinclude:: ../../examples/autotools/project.conf
58 :language: yaml
59
60 Like the :ref:`last project.conf <tutorial_running_commands_project_conf>`, we've
61 added another :ref:`source alias <project_source_aliases>` for ``gnu``, the location
62 from which we're going to download the ``automake`` tarball.
63
64
65 ``elements/base/alpine.bst`` and ``elements/base.bst``
66 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67 The alpine base and base stack element are defined in the
68 same way as in the last chapter: :ref:`tutorial_running_commands`.
69
70
71 ``elements/hello.bst``
72 ~~~~~~~~~~~~~~~~~~~~~~
73
74 .. literalinclude:: ../../examples/autotools/elements/hello.bst
75 :language: yaml
76
77 In this case, we haven't touched the element's ``config`` section
78 at all, instead we just slightly override the bahavior of the
79 :mod:`autotools <elements.autotools>` build element by overriding
80 the :ref:`command-subdir variable <format_variables>`
81
82
83 Looking at variables
84 ''''''''''''''''''''
85 Let's take a moment and observe how :ref:`element composition
86 <format_composition>` works with variables.
87
88 As :ref:`the documentation <format_composition>` mentions:
89
90 * The initial settings of the ``project.conf`` variables are setup
91 using BuildStream's :ref:`builtin defaults <project_builtin_defaults>`.
92
93 * After this, your local ``project.conf`` may override some variables
94 on a project wide basis. Those will in turn be overridden by any
95 defaults provided by element classes, such as the variables set in the
96 documentation of the :mod:`autotools <elements.autotools>` build element.
97 The variables you set in your final ``<element.bst>`` *element declarations*,
98 will have the final say on the value of a particular variable.
99
100 * Finally, the variables, which may be composed of other variables,
101 are resolved after all composition has taken place.
102
103 The variable we needed to override was ``command-subdir``, which is an
104 automatic variable provided by the :mod:`BuildElement <buildstream.buildelement>`
105 abstract class. This variable simply instructs the :mod:`BuildElement <buildstream.buildelement>`
106 in which subdirectory of the ``%{build-root}`` to run its commands in.
107
108 One can always display the resolved set of variables for a given
109 element's configuration using :ref:`bst show <invoking_show>`:
110
111 .. raw:: html
112 :file: ../sessions/autotools-show-variables.html
113
114 As an exercise, we suggest that you modify the ``hello.bst``
115 element to set the prefix like so:
116
117 .. code:: yaml
118
119 variables:
120 prefix: "/opt"
121
122 And rerun the above :ref:`bst show <invoking_show>` command to observe how this
123 changes the output.
124
125 Observe where the variables are declared in the :ref:`builtin defaults
126 <project_builtin_defaults>` and :mod:`autotools <elements.autotools>` element
127 documentation, and how overriding these effects the resolved set of variables.
128
129
130 Using the project
131 -----------------
132
133
134 Build the hello.bst element
135 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
136 To build the project, run :ref:`bst build <invoking_build>` in the
137 following way:
138
139 .. raw:: html
140 :file: ../sessions/autotools-build.html
141
142
143 Run the hello world program
144 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
145 We probably know by now what's going to happen, but let's run
146 the program we've compiled anyway using :ref:`bst shell <invoking_shell>`:
147
148 .. raw:: html
149 :file: ../sessions/autotools-shell.html
150
151
152 Summary
153 -------
154 Now we've used an external :ref:`build element <core_buildelement_builtins>`,
155 from the ``buildstream-plugins`` package and we've taken a look into
156 :ref:`how variables work <format_variables>`.
157
158 When browsing the :ref:`build elements <core_buildelement_builtins>` in their
159 respective documentation, we are now equipped with a good idea of what an element
160 is going to do, based on their default YAML configuration and any configurations
161 we have in our project. We can also now observe what variables are in effect
162 for the build of a given element, using :ref:`bst show <invoking_show>`.