Debian Codegraph @

doc/source/handling-files/overlaps.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 .. _handling_files_overlaps:
17
18 Overlapping files
19 =================
20 In this chapter, we will discuss what happens when files from multiple
21 element artifacts conflict with eachother, and what strategies we can
22 use to resolve these situations.
23
24 .. note::
25
26 This example is distributed with BuildStream
27 in the `doc/examples/overlaps
28 <https://github.com/apache/buildstream/tree/master/doc/examples/overlaps>`_
29 subdirectory.
30
31
32 Overview
33 --------
34 This project builds on the previous chapter on :ref:`composition <handling_files_composition>`,
35 and as such we'll only go over what has changed from there, which is not much.
36
37
38 Project structure
39 -----------------
40 In this example we've just extended the ``libhello.bst`` and the ``hello.bst``
41 elements such that they both install an additional file: ``%{docdir}/hello.txt``.
42
43 We've updated the following Makefiles:
44
45
46 files/libhello/Makefile
47 ~~~~~~~~~~~~~~~~~~~~~~~
48
49 .. literalinclude:: ../../examples/overlaps/files/libhello/Makefile
50 :language: Makefile
51
52
53 files/hello/Makefile
54 ~~~~~~~~~~~~~~~~~~~~
55
56 .. literalinclude:: ../../examples/overlaps/files/hello/Makefile
57 :language: Makefile
58
59
60 As you can see, this now presents a conflict of sorts, where multiple
61 elements in the pipeline want to install the *same file*.
62
63
64 Using the project
65 -----------------
66 In this chapter, we're only going to present the warning and then
67 discuss how to mitigate this situation.
68
69 See what happens when we try to build the ``runtime-only.bst``
70 :mod:`compose <elements.compose>` element:
71
72 .. raw:: html
73 :file: ../sessions/overlaps-build.html
74
75 Notice the warning message about the conflicting file, it is there to
76 inform the user about which files are *overlapping*, and also which
77 elements are being staged in which order.
78
79 Note also that BuildStream does not discover the overlap until the
80 moment that you build a reverse dependency which will require staging
81 of both artifacts.
82
83 .. tip::
84
85 The ``overlaps`` warning discussed here can be configured to be
86 a :ref:`fatal warning <configurable_warnings>`. This is useful
87 in the case that you want to be strict about avoiding overlapping
88 files in your project.
89
90
91 Mitigating overlapping files
92 ----------------------------
93 Since we recently discussed :ref:`filtering of artifacts <handling_files_filtering>`,
94 we should note that it is of course possible to handle this case by
95 having ``hello.bst`` depend on a *filtered* version of ``libhello.bst`` with the
96 offending file excluded.
97
98 However, working with :mod:`filter <elements.filter>` elements just for the
99 sake of handling a conflicting artifact would be quite inconvenient, so we
100 have other means.
101
102
103 Whitelisting overlapping files
104 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
105 BuildStream allows explicitly ignoring such errors by adding the files
106 to an :ref:`overlap whitelist <public_overlap_whitelist>`, you could achieve
107 this in the given example by adding the following to the ``hello.bst`` element:
108
109 .. code:: yaml
110
111 public:
112 bst:
113 overlap-whitelist:
114 - |
115 %{docdir}/hello.txt
116
117 .. note::
118
119 Note that :func:`glob patterns <buildstream.utils.glob>` are also
120 supported in the whitelist.
121
122
123 Artifact munging
124 ~~~~~~~~~~~~~~~~
125 Another way around this situation is the *munge* the artifacts at install
126 time such that there is no conflict.
127
128 This is the easiest approach in the case that you might want to keep the
129 underlying ``%{docdir}/hello.txt`` from ``libhello.bst`` and discard the
130 same file from ``hello.bst``.
131
132 In this case, we might modify the ``hello.bst`` file so that it's install
133 command contain an ``rm`` statement, as such:
134
135 .. code:: yaml
136
137 install-commands:
138 - make -j1 PREFIX="%{prefix}" DESTDIR="%{install-root}" install
139
140 - |
141 # Rid ourselves of the unwanted file at install time
142 rm -f %{install-root}%{docdir}/hello.txt
143
144 This would cause later builds of ``runtime-only.bst`` to no longer
145 conflict on the given file.
146
147
148 Summary
149 -------
150 In this chapter we've presented a situation where an artifact
151 can *conflict* with another artifact by way of providing the
152 same files.
153
154 We've presented the :ref:`overlap whitelist <public_overlap_whitelist>`
155 public data which is the typical solution for silencing the
156 error when the outcome is desired, and also presented a strategy
157 to deal with cases where you want to keep files from the
158 *overlapped* artifact instead.