external-dependency-solver-protocol.txt 12 KB

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