external-dependency-solver-protocol.txt 15 KB

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