external-dependency-solver-protocol.txt 14 KB

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