external-dependency-solver-protocol.txt 16 KB

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