Debian Codegraph @

doc/source/developing/workspaces.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 .. _developing_workspaces:
17
18 Workspaces
19 ==========
20 In this section we will cover the use of BuildStream's workspaces feature when
21 devloping a BuildStream project.
22
23 .. note::
24
25 This example is distributed with BuildStream
26 in the `doc/examples/developing
27 <https://github.com/apache/buildstream/tree/master/doc/examples/developing>`_
28 subdirectory.
29
30 We will start with the project used in the :ref:`running commands <tutorial_running_commands>`
31 tutorial. Recall the element hello.bst, which builds the bellow C file:
32
33 .. literalinclude:: ../../examples/developing/files/src/hello.c
34 :language: c
35
36 Suppose we now want to alter the functionality of the *hello* command. We can
37 make changes to the source code of Buildstream elements by making use of
38 BuildStream's workspace command.
39
40
41 Opening a workspace
42 -------------------
43 First we need to open a workspace, we can do this by running
44
45 .. raw:: html
46 :file: ../sessions/developing-workspace-open.html
47
48 This command has created the workspace_hello directory in which you can see
49 the source for the hello.bst element, i.e. hello.c and the corresponding
50 makefile.
51
52 You can view existing workspaces using
53
54 .. raw:: html
55 :file: ../sessions/developing-workspace-list.html
56
57
58 Making code changes
59 -------------------
60 Let's say we want to alter the message printed when the hello command is run.
61 We can open workspace_hello/hello.c and make the following change:
62
63 .. literalinclude:: ../../examples/developing/update.patch
64 :language: diff
65
66 Now, rebuild the hello.bst element.
67
68 .. raw:: html
69 :file: ../sessions/developing-build-after-changes.html
70
71 Note that if you run the command from inside the workspace, the element name is optional.
72
73 .. raw:: html
74 :file: ../sessions/developing-build-after-changes-workspace.html
75
76 Now running the hello command using bst shell:
77
78 .. raw:: html
79 :file: ../sessions/developing-shell-after-changes.html
80
81 This gives us the new message we changed in hello.c.
82
83 From this point we have several options. If the source is under version control
84 we can commit our changes and push them to the remote repository.
85
86
87 Incremental builds
88 ------------------
89 Once you have opened up your workspace, the workspace build directory will be
90 reused for subsequent builds, which should improve your edit/compile/test cycle
91 time when working with an open workspace.
92
93 In order to optimize incremental builds, BuildStream treats build configure steps
94 separately from the main build steps, and will only call the
95 :func:`Element.prepare() <buildstream.element.Element.prepare>` method on
96 an element plugin the first time it gets built. This avoids needlessly rebuilding
97 objects due to header files and such being unconditionally recreated by configuration
98 scripts (such as the typical ``./configure`` script which is called for ``autotools``
99 elements for instance).
100
101 A caveat of this optimization however is that changes you might make to the
102 configuration scripts will not be taken into account by default on the next
103 incremental build. A forced reconfiguration can also be required in some cases
104 where build scripts automatically detect sources in it's configuration phase,
105 so newly added sources you add might be ignored.
106
107 In order to force the configuration step to be called again on the next build,
108 you can use :ref:`bst workspace reset --soft <invoking_workspace_reset>`, like so:
109
110 In these cases, you can perform a hard reset on the workspace using
111 :ref:`bst workspace reset <invoking_workspace_reset>`, like so:
112
113 .. raw:: html
114 :file: ../sessions/developing-soft-reset.html
115
116 This will ensure that the next time you run the build, BuildStream will forcefully
117 rerun the :func:`Element.prepare() <buildstream.element.Element.prepare>` method
118 and cause the configuration step to occur again.
119
120
121 Closing your workspace
122 ----------------------
123 If we want to close the workspace and come back to our changes later, we can
124
125 .. raw:: html
126 :file: ../sessions/developing-close-workspace.html
127
128 We can then reopen the workspace later using:
129
130 .. raw:: html
131 :file: ../sessions/developing-reopen-workspace.html
132
133 The --no-checkout option tells BuildStream not to check the source out but to
134 instead hard-link to the workspace_hello directory.
135
136 Alternatively, if we wish to discard the changes we can use
137
138 .. raw:: html
139 :file: ../sessions/developing-reset-workspace.html
140
141 This resets the workspace to its original state.
142
143 To discard the workspace completely we can do:
144
145 .. raw:: html
146 :file: ../sessions/developing-discard-workspace.html
147
148 This will close the workspace and completely remove the workspace_hello
149 directory.
150