You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

catalog.rst 13KB

5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. The Package Catalog
  2. ###################
  3. ``dds`` stores a catalog of available packages, along with their dependency
  4. statements and information about how a source distribution thereof may be
  5. maintained.
  6. Viewing Catalog Contents
  7. ************************
  8. The default catalog database is stored in a user-local location, and the
  9. package IDs available can be listed with ``dds catalog list``. This will only
  10. list the IDs of the packages, but none of the additional metadata about them.
  11. .. _catalog.adding:
  12. Adding Packages to the Catalog
  13. ******************************
  14. There are two primary ways to add entries to the package catalog.
  15. Adding Individual Packages
  16. ==========================
  17. A single package can be added to the catalog with the ``dds catalog add``
  18. command:
  19. .. code-block:: text
  20. dds catalog add <package-id>
  21. [--depends <requirement> [--depends <requirement> [...]]]
  22. [--git-url <url> --git-ref <ref>]
  23. [--auto-lib <namespace>/<name>]
  24. The ``<package-id>`` positional arguments is the ``name@version`` package ID
  25. that will be added to the catalog. The following options are supported:
  26. ``--depends <requirement>``
  27. This argument, which can be specified multiple times to represent multiple
  28. dependencies, sets the dependencies of the package within the catalog. If
  29. the obtained package root contains a ``package.json5``, then the
  30. dependencies listed here must be identical to those listed in
  31. ``package.json5``, or dependency resolution may yield unexpected results.
  32. ``--git-url <url>``
  33. Specify a Git URL to clone from to obtain the package. The root of the
  34. cloned repository must be a package root, but does not necessarily need to
  35. have the ``package.json5`` and ``library.json5`` files if relying on the
  36. ``--auto-lib`` parameter.
  37. ``--git-ref`` **must** be passed with ``--git-url``.
  38. ``--git-ref <ref>``
  39. Specify a Git ref to clone. The remote must support cloning by the ref that
  40. is specified here. Most usually this should be a Git tag.
  41. ``dds`` will perform a shallow clone of the package at the specified
  42. Git reference.
  43. ``--auto-lib``
  44. This option must be provided if the upstream does not already contain the
  45. ``dds`` files that are necessary to export the library information. This
  46. can only be specified for packages that contain a single library root at
  47. the package root.
  48. The form of the argument is that of ``<namespace>/<name>``, where
  49. ``namespace`` and ``name`` are the usage requirement keys that should be
  50. generated for the library.
  51. .. _catalog.adding.json:
  52. Bulk Imports via JSON
  53. =====================
  54. The ``dds catalog import`` supports a ``--json`` flag that specifies a JSON
  55. file from which catalog entries will be generated.
  56. .. note::
  57. The ``--json`` flag can be passed more than once to import multiple JSON
  58. files at once.
  59. The JSON file has the following structure:
  60. .. code-block:: javascript
  61. {
  62. // Import version spec.
  63. "version": 1,
  64. // Packages section
  65. "packages": {
  66. // Subkeys are package names
  67. "acme-gadgets": {
  68. // Keys within the package names are the versions that are
  69. // available for each package.
  70. "0.4.2": {
  71. // `depends` is an object of dependencies for this
  72. // particular version of the package. (Optional)
  73. "depends": {
  74. // A mapping of package names to version ranges
  75. "acme-widgets": "^1.4.1"
  76. },
  77. // `description` is an attribute to give a string to describe
  78. // the package. (Optional)
  79. "description": "A collection of useful gadgets.",
  80. // Specify the Git remote information
  81. "git": {
  82. // `url` and `ref` are required.
  83. "url": "http://example.com/git/repo/acme-gadgets.git",
  84. "ref": "v0.4.2-stable",
  85. // The `auto-lib` is optional, to specify an automatic
  86. // library name/namespace pair to generate for the
  87. // root library
  88. "auto-lib": "Acme/Gadgets",
  89. // List of filesystem transformations to apply to the repository
  90. // (optional)
  91. "transform": [
  92. // ... (see below) ...
  93. ]
  94. }
  95. }
  96. }
  97. }
  98. }
  99. .. _catalog.fs-transform:
  100. Filesystem Transformations
  101. **************************
  102. A catalog entry can have a set of filesystem transformations attached to its remote information (e.g. the ``git`` property). When ``dds`` is obtaining a copy of the code for the package, it will apply the associated transformations to the filesystem based in the directory of the downloaded/cloned directory. In this was, ``dds`` can effectively "patch" the filesystem structure of a project arbitrarily. This allows many software projects to be imported into ``dds`` without needing to patch/fork the original project to support the required filesystem structure.
  103. .. important::
  104. While ``dds`` allows you to patch directories downloaded via the catalog, a
  105. native ``dds`` project must still follow the layout rules.
  106. The intention of filesystem transformations is to act as a "bridge" that will allow ``dds`` projects to more easily utilize existing libraries.
  107. .. note::
  108. Filesystem transformations can only be added to catalog entries using the
  109. :ref:`JSON import method <catalog.adding.json>`. It is not available in the
  110. command-line import method.
  111. Available Transformations
  112. =========================
  113. At time of writing, there are four main transformations available to catalog entries:
  114. ``copy`` and ``move``
  115. Copies or moves a set of files/directories from one location to another. Allows the following options:
  116. - ``from`` - The path from which to copy/move. **Required**
  117. - ``to`` - The destination path for the copy/move. **Required**
  118. - ``include`` - A list of globbing expressions for files to copy/move. If
  119. omitted, then all files will be included.
  120. - ``exclude`` - A list of globbing expressions of files to exclude from the
  121. copy/move. If omitted, then no files will be excluded. **If both** ``include`` and ``exclude`` are provided, ``include`` will be checked *before* ``exclude``.
  122. - ``strip-components`` - A positive integer (or zero, the default). When the
  123. ``from`` path identifies a directory, its contents will be copied/moved
  124. into the destination and maintain their relative path from the source path as their relative path within the destination. If ``strip-components`` is set to an integer ``N``, then the first ``N`` path components of that relative path will be removed when copying/moving the files in a directory. If a file's relative path has less than ``N`` components, then that file will be excluded from the ``copy/move`` operation.
  125. ``remove``
  126. Delete files and directories from the package source. Has the following options:
  127. - ``path`` - The path of the file/directory to remove. **Required**
  128. - ``only-matching`` - A list of globbing expressions for files to remove. If omitted and the path is a directory, then the entire directory will be deleted. If at least one pattern is provided, then directories will be left intact and only non-directory files will be removed. If ``path`` names a non-directory file, then this option has no effect.
  129. ``write``
  130. Write the contents of a string to a file in the package source. Has the following options:
  131. - ``path`` - The path of the file to write. **Required**
  132. - ``content`` - A string that will be written to the file. **Required**
  133. If the file exists and is not a directory, the file will be replaced. If the path names an existing directory, an error will be generated.
  134. Transformations are added as a JSON array to the JSON object that specifies the remote information for the package. Each element of the array is an object, with one or more of the four keys listed above. If an object features more than one of the above keys, they are applied in the same order as they have been listed.
  135. Example: Crypto++
  136. =================
  137. The following catalog entry will build and import `Crypto++`_ for use by a ``dds`` project. This uses the unmodified Crypto++ repository, which ``dds`` doesn't know how to build immediately. With some simple moving of files, we end up with something ``dds`` can build directly:
  138. .. code-block:: javascript
  139. "cryptopp": {
  140. "8.2.0": {
  141. "git": {
  142. "url": "https://github.com/weidai11/cryptopp.git",
  143. "ref": "CRYPTOPP_8_2_0",
  144. "auto-lib": "cryptopp/cryptopp",
  145. "transform": [
  146. {
  147. // Crypto++ has no source directories at all, and everything lives
  148. // at the top level. No good for dds.
  149. //
  150. // Clients are expected to #include files with a `cryptopp/` prefix,
  151. // so we need to move the files around so that they match the
  152. // expected layout:
  153. "move": {
  154. // Move from the root of the repo:
  155. "from": ".",
  156. // Move files *into* `src/cryptopp`
  157. "to": "src/cryptopp",
  158. // Only move the C++ sources and headers:
  159. "include": [
  160. "*.c",
  161. "*.cpp",
  162. "*.h"
  163. ]
  164. }
  165. }
  166. ]
  167. }
  168. }
  169. }
  170. Example: libsodium
  171. ==================
  172. For example, this catalog entry will build and import `libsodium`_ for use in a ``dds`` project. This uses the upstream libsodium repository, which does not meet the layout requirements needed by ``dds``. With a few simple transformations, we can allow ``dds`` to build and consume libsodium successfully:
  173. .. code-block:: javascript
  174. "libsodium": {
  175. "1.0.18": {
  176. "git": {
  177. "url": "https://github.com/jedisct1/libsodium.git",
  178. "ref": "1.0.18",
  179. "auto-lib": "sodium/sodium",
  180. /// Make libsodium look as dds expects of a project.
  181. "transform": [
  182. // libsodium has a `src` directory, but it does not look how dds
  183. // expects it to. The public `#include` root of libsodium lives in
  184. // a nested subdirectory of `src/`
  185. {
  186. "move": {
  187. // Move the public header root out from that nested subdirectory
  188. "from": "src/libsodium/include",
  189. // Put it at `include/` in the top-level
  190. "to": "include/"
  191. }
  192. },
  193. // libsodium has some files whose contents are generated by a
  194. // configure script. For demonstration purposes, we don't need most
  195. // of them, and we can just swipe an existing pre-configured file
  196. // that is already in the source repository and put it into the
  197. // public header root.
  198. {
  199. "copy": {
  200. // Generated version header committed to the repository:
  201. "from": "builds/msvc/version.h",
  202. // Put it where the configure script would put it:
  203. "to": "include/sodium/version.h"
  204. }
  205. },
  206. // The subdirectory `src/libsodium/` is no good. It now acts as an
  207. // unnecessary layer of indirection. We want `src/` to be the root.
  208. // We can just "lift" the subdirectory:
  209. {
  210. // Up we go:
  211. "move": {
  212. "from": "src/libsodium",
  213. "to": "src/"
  214. },
  215. // Delete the now-unused subdirectory:
  216. "remove": {
  217. "path": "src/libsodium"
  218. }
  219. },
  220. // Lastly, libsodium's source files expect to resolve their header
  221. // paths differently than they expect of their clients (Bad!!!).
  222. // Fortunately, we can do a hack to allow the files in `src/` to
  223. // resolve its headers. The source files use #include as if the
  224. // header root was `include/sodium/`, rather than `include/`.
  225. // To work around this, generate a copy of each header file in the
  226. // source root, but remove the leading path element.
  227. // Because we have a separate `include/` and `src/` directory, dds
  228. // will only expose the `include/` directory to clients, and the
  229. // header copies in `src/` are not externally visible.
  230. //
  231. // For example, the `include/sodium/version.h` file is visible to
  232. // clients as `sodium/version.h`, but libsodium itself tries to
  233. // include it as `version.h` within its source files. When we copy
  234. // from `include/`, we grab the relative path to `sodium/version.h`,
  235. // strip the leading components to get `version.h`, and then join that
  236. // path with the `to` path to generate the full destination at
  237. // `src/version.h`
  238. {
  239. "copy": {
  240. "from": "include/",
  241. "to": "src/",
  242. "strip-components": 1
  243. }
  244. }
  245. ]
  246. }
  247. }
  248. }
  249. .. _libsodium: https://doc.libsodium.org/
  250. .. _Crypto++: https://cryptopp.com/