apt-solver-protocol.mdwn 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. ** TENTATIVE PROPOSAL, VERY VERY VERY DRAFT **
  2. # APT External Dependency Solver Protocol (EDSP) - version 0.1
  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. ## Components
  7. - **APT**: we know this one.
  8. - APT is equipped with its own **internal solver** for dependencies,
  9. which is identified by the string `internal`.
  10. - **External solver**: an *external* software component able to resolve
  11. dependencies on behalf of APT. Each external solver is identified by
  12. an unique string (other than `internal`) called the solver **name**.
  13. At each interaction with APT, a single solver is in use. When there is
  14. a total of 2 or more solvers, internals or externals, the user can
  15. choose which one to use.
  16. ## Installation
  17. Each external solver is installed as a file under
  18. `/usr/lib/apt/solvers`. The naming scheme is
  19. `/usr/lib/apt/solvers/NAME`, where `NAME` is the name of the external
  20. solver.
  21. Each file under `/usr/lib/apt/solvers` corresponding to an external
  22. solver must be executable.
  23. No non-solver files must be installed under `/usr/lib/apt/solvers`, so
  24. that an index of available external solvers can be obtained by simply
  25. looking at the content of that directory.
  26. ## Configuration
  27. Several APT options can be used to affect dependency solving in APT. An
  28. overview of them is given below. Please refer to proper APT
  29. configuration documentation for more, and more up to date, information.
  30. - **APT::Solver::Name**: the name of the solver to be used for
  31. dependency solving. Defaults to `internal`
  32. - **APT::Solver::Strict-Pinning**: whether pinning must be strictly
  33. respected (as the internal solver does) or can be slightly deviated
  34. from. Defaults to `yes`.
  35. - **APT::Solver::Preferences**: solver-specific user preferences used
  36. during dependency solving. Check your solver documentation for what is
  37. supported here. Default to empty.
  38. ## Protocol
  39. When configured to use an external solver, APT will resort to it to
  40. decide which packages should be installed or removed.
  41. The interaction happens **in batch**: APT will invoke the external
  42. solver passing the current status of installed and available packages,
  43. as well as the user request to alter the set of installed packages. The
  44. external solver will compute a new complete set of installed packages
  45. and gives APT a "diff" listing of which *additional* packages should be
  46. installed and of which currently installed packages should be
  47. *removed*. (Note: the order in which those actions have to be performed
  48. will be up to APT to decide.)
  49. External solvers are invoked by executing them. Communications happens
  50. via the file descriptors: **stdin** (standard input) and **stdout**
  51. (standard output). stderr is not used by the EDSP protocol. Solvers can
  52. therefore use stderr to dump debugging information that could be
  53. inspected separately.
  54. After invocation, the protocol passes through 3 separate phases:
  55. 1. APT send to the solver a dependency solving **scenario**
  56. 2. The solver solves dependencies. No communication with APT happens
  57. during this phase.
  58. 3. The solver sends back to APT an **answer**, i.e. either a *solution*
  59. or an *error* report.
  60. ### Scenario
  61. A scenario is a text file encoded in a format very similar to the "Deb
  62. 822" format (AKA "the format used by Debian `Packages` files"). A
  63. scenario consists of two distinct parts: a **request** and a **package
  64. universe**, occurring in that order. The request consists of a single
  65. Deb 822 stanza, while the package universe consists of several such
  66. stanzas. All stanzas occurring in a scenario are separated by an empty
  67. line.
  68. #### Request
  69. Within a dependency solving scenario, a request represents the action on
  70. installed packages requested by the user.
  71. A request is a single Deb 822 stanza opened by a mandatory Request field
  72. and followed by a mixture of action and preference fields.
  73. The value of the **Request:** field is a string describing the EDSP
  74. protocol which will be used to communicate. At present, the string must
  75. be `EDSP 0.1`.
  76. a unique request identifier, such as an
  77. UUID. Request fields are mainly used to identify the beginning of a
  78. request stanza; their actual values are otherwise not used by the EDSP
  79. protocol.
  80. The following **action fields** are supported in request stanzas:
  81. - **Install:** (optional, defaults to the empty string) A space
  82. separated list of package names, with *no version attached*, to
  83. install. This field denotes a list of packages that the user wants to
  84. install, usually via an APT `install` request.
  85. - **Remove:** (optional, defaults to the empty string) Same syntax of
  86. Install. This field denotes a list of packages that the user wants to
  87. remove, usually via APT `remove` or `purge` requests.
  88. - **Upgrade:** (optional, defaults to `no`). Allowed values: `yes`,
  89. `no`. When set to `yes`, an upgrade of all installed packages has been
  90. requested, usually via an APT `upgrade` request.
  91. - **Dist-Upgrade:** (optional, defaults to `no`). Allowed values: `yes`,
  92. `no`. Same as Upgrade, but for APT `dist-upgrade` requests.
  93. - **Autoremove:** (optional, defaults to `no`). Allowed values: `yes`,
  94. `no`. When set to `yes`, a clean up of unused automatically installed
  95. packages has been requested, usually via an APT `autoremove` request.
  96. The following **preference fields** are supported in request stanzas:
  97. - **Strict-Pinning:** (optional, defaults to `yes`). Allowed values:
  98. `yes`, `no`. When set to `yes`, APT pinning is strict, in the sense
  99. that the solver must not propose to install packages which are not APT
  100. candidates (see the `APT-Pin` and `APT-Candidate` fields in the
  101. package universe). When set to `no`, the solver does only a best
  102. effort attempt to install APT candidates. Usually, the value of this
  103. field comes from the `APT::Solver::Strict-Pinning` configuration
  104. option.
  105. - **Preferences:** a solver-specific optimization string, usually coming
  106. from the `APT::Solver::Preferences` configuration option.
  107. #### Package universe
  108. A package universe is a list of Deb 822 stanzas, one per package, called
  109. **package stanzas**. Each package stanzas starts with a Package
  110. field. The following fields are supported in package stanzas:
  111. - All fields supported by Debian Packages file (see one of the
  112. `/var/lib/apt/lists/*Packages` file for an example), *with the
  113. exception of the Description field* that is not allowed.
  114. Among those fields, the following are mandatory: Package, Version,
  115. Architecture.
  116. - **Installed:** (optional, default value `no`). Allowed values: `yes`,
  117. `no`. When set to `yes`, the corresponding package is currently
  118. installed.
  119. ##TODO## changed with respect to current prototype, which uses Status
  120. - **APT-ID:** (mandatory). Unique package identifier, according to APT.
  121. - **APT-Pin:** (mandatory). Must be a non-negative integer. Package pin
  122. value, according to current APT policy.
  123. - **APT-Candidate:** (optional, default value `no`). Allowed values:
  124. `yes`, `no`. When set to `yes`, the corresponding package is granted
  125. to have the highest pinning value among all the packages having the
  126. same name.
  127. ##TODO## what about multi-arch? is the pin value granted to be the
  128. higest also across different architectures?
  129. ### Answer
  130. An answer from the external solver to APT is either a *solution* or an
  131. *error*.
  132. The following invariant on **exit codes** must hold true. When the
  133. external solver is *able to find a solution*, it will write the solution
  134. to standard output and then exit with an exit code of 0. When the
  135. external solver is *unable to find a solution* (and aware of that), it
  136. will write an error to standard output and then exit with an exit code
  137. of 0. An exit code other than 0 will be interpreted as a solver crash
  138. with no meaningful error about dependency resolution to convey to the
  139. user.
  140. #### Solution
  141. A solution is a single Deb 822 stanza, starting with the field
  142. Solution. The following fields are supported in solution stanzas:
  143. - **Solution:** (mandatory). The value of this field is ignored,
  144. although it should be a unique solution identifier, such as a UUID.
  145. - **Install:** (optional, defaults to the empty string). A space
  146. separated list of strings of the form `PACKAGE=VERSION` where
  147. `PACKAGE` is a package name and `VERSION` is an available version of
  148. that package. The list denotes a set of packages that must be
  149. installed to satisfy user request.
  150. - **Remove:** (optional, defaults to the empty string). Same as Install,
  151. but denoting a set of packages that must be removed to satisfy user
  152. request.
  153. #### Error
  154. An error is a single Deb 822 stanza, starting the field Error. The
  155. following fields are supported in error stanzas:
  156. - **Error:** (mandatory). The value of this field is ignored, although
  157. it should be a unique error identifier, such as a UUID.
  158. - **Message:** (mandatory). The value of this field is a text string,
  159. meant to be read by humans, that explains the cause of the solver
  160. error.
  161. ##TODO## can we support line continuations throughout this format? If
  162. yes, they might come handy both for error stanzas and for solution
  163. stanzas (which might have very long install/remove lines)
  164. ** TENTATIVE PROPOSAL, VERY VERY VERY DRAFT **