merge documentation of the EDSP protocol
[ntk/apt.git] / doc / external-dependency-solver-protocol.txt
1 # APT External Dependency Solver Protocol (EDSP) - version 0.3
2
3 This document describes the communication protocol between APT and
4 external dependency solvers. The protocol is called APT EDSP, for "APT
5 External Dependency Solver Protocol".
6
7
8 ## Components
9
10 - **APT**: we know this one.
11 - APT is equipped with its own **internal solver** for dependencies,
12 which is identified by the string `internal`.
13 - **External solver**: an *external* software component able to resolve
14 dependencies on behalf of APT.
15
16 At each interaction with APT, a single solver is in use. When there is
17 a total of 2 or more solvers, internals or externals, the user can
18 choose which one to use.
19
20 Each solver is identified by an unique string, the **solver
21 name**. Solver names must be formed using only alphanumeric ASCII
22 characters, dashes, and underscores; solver names must start with a
23 lowercase ASCII letter. The special name `internal` denotes APT's
24 internal solver, is reserved, and cannot be used by external solvers.
25
26
27 ## Installation
28
29 Each external solver is installed as a file under
30 `/usr/lib/apt/solvers`. The naming scheme is
31 `/usr/lib/apt/solvers/NAME`, where `NAME` is the name of the external
32 solver.
33
34 Each file under `/usr/lib/apt/solvers` corresponding to an external
35 solver must be executable.
36
37 No non-solver files must be installed under `/usr/lib/apt/solvers`, so
38 that an index of available external solvers can be obtained by listing
39 the content of that directory.
40
41
42 ## Configuration
43
44 Several APT options can be used to affect dependency solving in APT. An
45 overview of them is given below. Please refer to proper APT
46 configuration documentation for more, and more up to date, information.
47
48 - **APT::Solver::Name**: the name of the solver to be used for
49 dependency solving. Defaults to `internal`
50
51 - **APT::Solver::Strict-Pinning**: whether pinning must be strictly
52 respected (as the internal solver does) or can be slightly deviated
53 from. Defaults to `yes`.
54
55 - **APT::Solver::NAME::Preferences** (where NAME is a solver name):
56 solver-specific user preference string used during dependency solving,
57 when the solver NAME is in use. Check solver-specific documentation
58 for what is supported here. Defaults to the empty string.
59
60
61 ## Protocol
62
63 When configured to use an external solver, APT will resort to it to
64 decide which packages should be installed or removed.
65
66 The interaction happens **in batch**: APT will invoke the external
67 solver passing the current status of installed and available packages,
68 as well as the user request to alter the set of installed packages. The
69 external solver will compute a new complete set of installed packages
70 and gives APT a "diff" listing of which *additional* packages should be
71 installed and of which currently installed packages should be
72 *removed*. (Note: the order in which those actions have to be performed
73 will be up to APT to decide.)
74
75 External solvers are invoked by executing them. Communications happens
76 via the file descriptors: **stdin** (standard input) and **stdout**
77 (standard output). stderr is not used by the EDSP protocol. Solvers can
78 therefore use stderr to dump debugging information that could be
79 inspected separately.
80
81 After invocation, the protocol passes through a sequence of phases:
82
83 1. APT invokes the external solver
84 2. APT send to the solver a dependency solving **scenario**
85 3. The solver solves dependencies. During this phase the solver may
86 send, repeatedly, **progress** information to APT.
87 4. The solver sends back to APT an **answer**, i.e. either a *solution*
88 or an *error* report.
89 5. The external solver exits
90
91
92 ### Scenario
93
94 A scenario is a text file encoded in a format very similar to the "Deb
95 822" format (AKA "the format used by Debian `Packages` files"). A
96 scenario consists of two distinct parts: a **request** and a **package
97 universe**, occurring in that order. The request consists of a single
98 Deb 822 stanza, while the package universe consists of several such
99 stanzas. All stanzas occurring in a scenario are separated by an empty
100 line.
101
102
103 #### Request
104
105 Within a dependency solving scenario, a request represents the action on
106 installed packages requested by the user.
107
108 A request is a single Deb 822 stanza opened by a mandatory Request field
109 and followed by a mixture of action and preference fields.
110
111 The value of the **Request:** field is a string describing the EDSP
112 protocol which will be used to communicate. At present, the string must
113 be `EDSP 0.3`.
114
115 a unique request identifier, such as an
116 UUID. Request fields are mainly used to identify the beginning of a
117 request stanza; their actual values are otherwise not used by the EDSP
118 protocol.
119
120 The following **action fields** are supported in request stanzas:
121
122 - **Install:** (optional, defaults to the empty string) A space
123 separated list of package names, with *no version attached*, to
124 install. This field denotes a list of packages that the user wants to
125 install, usually via an APT `install` request.
126
127 - **Remove:** (optional, defaults to the empty string) Same syntax of
128 Install. This field denotes a list of packages that the user wants to
129 remove, usually via APT `remove` or `purge` requests.
130
131 - **Upgrade:** (optional, defaults to `no`). Allowed values: `yes`,
132 `no`. When set to `yes`, an upgrade of all installed packages has been
133 requested, usually via an APT `upgrade` request.
134
135 - **Dist-Upgrade:** (optional, defaults to `no`). Allowed values: `yes`,
136 `no`. Same as Upgrade, but for APT `dist-upgrade` requests.
137
138 - **Autoremove:** (optional, defaults to `no`). Allowed values: `yes`,
139 `no`. When set to `yes`, a clean up of unused automatically installed
140 packages has been requested, usually via an APT `autoremove` request.
141
142 The following **preference fields** are supported in request stanzas:
143
144 - **Strict-Pinning:** (optional, defaults to `yes`). Allowed values:
145 `yes`, `no`. When set to `yes`, APT pinning is strict, in the sense
146 that the solver must not propose to install packages which are not APT
147 candidates (see the `APT-Pin` and `APT-Candidate` fields in the
148 package universe). When set to `no`, the solver does only a best
149 effort attempt to install APT candidates. Usually, the value of this
150 field comes from the `APT::Solver::Strict-Pinning` configuration
151 option.
152
153 - **Preferences:** a solver-specific optimization string, usually coming
154 from the `APT::Solver::Preferences` configuration option.
155
156
157 #### Package universe
158
159 A package universe is a list of Deb 822 stanzas, one per package, called
160 **package stanzas**. Each package stanzas starts with a Package
161 field. The following fields are supported in package stanzas:
162
163 - All fields contained in the dpkg database, with the exception of
164 fields marked as "internal" (see the manpage `dpkg-query (1)`). Among
165 those fields, the following are mandatory for all package stanzas:
166 Package, Version, Architecture.
167
168 It is recommended not to pass the Description field to external
169 solvers or, alternatively, to trim it to the short description only.
170
171 - **Installed:** (optional, defaults to `no`). Allowed values: `yes`,
172 `no`. When set to `yes`, the corresponding package is currently
173 installed.
174
175 Note: the Status field present in the dpkg database must not be passed
176 to the external solver, as it's an internal dpkg field. Installed and
177 other fields permit to encode the most relevant aspects of Status in
178 communications with solvers.
179
180 - **Hold:** (optional, defaults to `no`). Allowed values: `yes`,
181 `no`. When set to `yes`, the corresponding package is marked as "on
182 hold" by dpkg.
183
184 - **APT-ID:** (mandatory). Unique package identifier, according to APT.
185
186 - **APT-Pin:** (mandatory). Must be an integer. Package pin value,
187 according to APT policy.
188
189 - **APT-Candidate:** (optional, defaults to `no`). Allowed values:
190 `yes`, `no`. When set to `yes`, the corresponding package is the APT
191 candidate for installation among all available packages with the same
192 name.
193
194 - **APT-Automatic:** (optional, defaults to `no`). Allowed values:
195 `yes`, `no`. When set to `yes`, the corresponding package is marked by
196 APT as automatic installed. Note that automatic installed packages
197 should be removed by the solver only when the Autoremove action is
198 requested (see Request section).
199
200 ### Answer
201
202 An answer from the external solver to APT is either a *solution* or an
203 *error*.
204
205 The following invariant on **exit codes** must hold true. When the
206 external solver is *able to find a solution*, it will write the solution
207 to standard output and then exit with an exit code of 0. When the
208 external solver is *unable to find a solution* (and s aware of that), it
209 will write an error to standard output and then exit with an exit code
210 of 0. An exit code other than 0 will be interpreted as a solver crash
211 with no meaningful error about dependency resolution to convey to the
212 user.
213
214
215 #### Solution
216
217 A solution is a list of Deb 822 stanzas. Each of them could be an
218 install stanza (telling APT to install a specific package), a remove
219 stanza (telling APT to remove one), or an autoremove stanza (telling APT
220 about the *future* possibility of removing a package using the
221 Autoremove action).
222
223 An **install stanza** starts with an Install field and supports the
224 following fields:
225
226 - **Install:** (mandatory). The value is a package identifier,
227 referencing one of the package stanzas of the package universe via its
228 APT-ID field.
229
230 - All fields supported by package stanzas.
231
232 **Remove stanzas** are similar to install stanzas, but have **Remove**
233 fields instead of Install fields.
234
235 **Autoremove stanzas** are similar to install stanzas, but have
236 **Autoremove** fields instead of Install fields. Autoremove stanzas
237 should be output so that APT can inform the user of which packages they
238 can now autoremove, as a consequence of the executed action. However,
239 this protocol makes no assumption on the fact that a subsequent
240 invocation of an Autoremove action will actually remove the very same
241 packages indicated by Autoremove stanzas in the former solution.
242
243 In terms of expressivity, install and remove stanzas can carry one
244 single field each, as APT-IDs are enough to pinpoint packages to be
245 installed/removed. Nonetheless, for protocol readability, it is
246 recommended that solvers either add unconditionally the fields Package,
247 Version, and Architecture to all install/remove stanzas or,
248 alternatively, that they support a `--verbose` command line flag that
249 explicitly enables the output of those fields in solutions.
250
251
252 #### Error
253
254 An error is a single Deb 822 stanza, starting the field Error. The
255 following fields are supported in error stanzas:
256
257 - **Error:** (mandatory). The value of this field is ignored, although
258 it should be a unique error identifier, such as a UUID.
259
260 - **Message:** (mandatory). The value of this field is a text string,
261 meant to be read by humans, that explains the cause of the solver
262 error. Message fields might be multi-line, like the Description field
263 in the dpkg database. The first line conveys a short message, which
264 can be explained in more details using subsequent lines.
265
266
267 ### Progress
268
269 During dependency solving, an external solver may send progress
270 information to APT using **progress stanzas**. A progress stanza starts
271 with the Progress field and might contain the following fields:
272
273 - **Progress:** (mandatory). The value of this field is a date and time
274 timestamp, in RFC 2822 format. The timestamp provides a time
275 annotation for the progress report.
276
277 - **Percentage:** (optional). An integer from 0 to 100, representing the
278 completion of the dependency solving process, as declared by the
279 solver.
280
281 - **Message:** (optional). A textual message, meant to be read by the
282 APT user, telling what is going on within the dependency solving
283 (e.g. the current phase of dependency solving, as declared by the
284 solver).
285
286
287 # Future extensions
288
289 Potential future extensions to this protocol, listed in no specific
290 order, include:
291
292 - fixed error types to identify common failures across solvers and
293 enable APT to translate error messages
294 - structured error data to explain failures in terms of packages and
295 dependencies