Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

287 rindas
11KB

  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. The ``dds catalog import`` supports a ``--json`` flag that specifies a JSON5
  15. file from which catalog entries will be generated.
  16. .. note::
  17. The ``--json`` flag can be passed more than once to import multiple JSON
  18. files at once.
  19. The JSON file has the following structure:
  20. .. code-block:: javascript
  21. {
  22. // Import version spec.
  23. version: 1,
  24. // Packages section
  25. packages: {
  26. // Subkeys are package names
  27. "acme-gadgets": {
  28. // Keys within the package names are the versions that are
  29. // available for each package.
  30. "0.4.2": {
  31. // `depends` is an array of dependency statements for this
  32. // particular version of the package. (Optional)
  33. depends: [
  34. "acme-widgets^1.4.1"
  35. ],
  36. // `description` is an attribute to give a string to describe
  37. // the package. (Optional)
  38. description: "A collection of useful gadgets.",
  39. // Specify the Git remote information
  40. git: {
  41. // `url` and `ref` are required.
  42. url: "http://example.com/git/repo/acme-gadgets.git",
  43. ref: "v0.4.2-stable",
  44. // The `auto-lib` is optional, to specify an automatic
  45. // library name/namespace pair to generate for the
  46. // root library
  47. "auto-lib": "Acme/Gadgets",
  48. // List of filesystem transformations to apply to the repository
  49. // (optional)
  50. transform: [
  51. // ... (see below) ...
  52. ]
  53. }
  54. }
  55. }
  56. }
  57. }
  58. .. _catalog.fs-transform:
  59. Filesystem Transformations
  60. **************************
  61. .. note::
  62. Filesystem transformations is a transitional feature that is likely to be
  63. removed in a future release, and replaced with a more robust system when
  64. ``dds`` has a better way to download packages. Its aim is to allow ``dds``
  65. projects to use existing libraries that might not meet the layout
  66. requirements that ``dds`` imposes, but can otherwise be consumed by ``dds``
  67. with a few tweaks.
  68. A catalog entry can have a set of filesystem transformations attached to its
  69. remote information (e.g. the ``git`` property). When ``dds`` is obtaining a
  70. copy of the code for the package, it will apply the associated transformations
  71. to the filesystem based in the directory of the downloaded/cloned directory. In
  72. this way, ``dds`` can effectively "patch" the filesystem structure of a project
  73. arbitrarily. This allows many software projects to be imported into ``dds``
  74. without needing to patch/fork the original project to support the required
  75. filesystem structure.
  76. .. important::
  77. While ``dds`` allows you to patch directories downloaded via the catalog, a
  78. native ``dds`` project must still follow the layout rules.
  79. The intention of filesystem transformations is to act as a "bridge" that will allow ``dds`` projects to more easily utilize existing libraries.
  80. Available Transformations
  81. =========================
  82. At time of writing, there are five transformations available to catalog entries:
  83. ``copy`` and ``move``
  84. Copies or moves a set of files/directories from one location to another. Allows the following options:
  85. - ``from`` - The path from which to copy/move. **Required**
  86. - ``to`` - The destination path for the copy/move. **Required**
  87. - ``include`` - A list of globbing expressions for files to copy/move. If
  88. omitted, then all files will be included.
  89. - ``exclude`` - A list of globbing expressions of files to exclude from the
  90. copy/move. If omitted, then no files will be excluded. **If both** ``include`` and ``exclude`` are provided, ``include`` will be checked *before* ``exclude``.
  91. - ``strip-components`` - A positive integer (or zero, the default). When the
  92. ``from`` path identifies a directory, its contents will be copied/moved
  93. 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.
  94. ``remove``
  95. Delete files and directories from the package source. Has the following options:
  96. - ``path`` - The path of the file/directory to remove. **Required**
  97. - ``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.
  98. ``write``
  99. Write the contents of a string to a file in the package source. Has the following options:
  100. - ``path`` - The path of the file to write. **Required**
  101. - ``content`` - A string that will be written to the file. **Required**
  102. If the file exists and is not a directory, the file will be replaced. If the
  103. path names an existing directory, an error will be generated.
  104. ``edit``
  105. Modifies the contents of the files in the package.
  106. - ``path`` - Path to the file to edit. **Required**
  107. - ``edits`` - An array of edit objects, applied in order, with the following
  108. keys:
  109. - ``kind`` - One of ``insert`` or ``delete`` to insert/delete lines,
  110. respectively. **Required**
  111. - ``line`` - The line at which to perform the insert/delete. The first line
  112. of the file is line one, *not* line zero. **Required**
  113. - ``content`` - For ``insert``, the string content to insert into the file.
  114. A newline will be appended after the content has been inserted.
  115. Transformations are added as a JSON array to the JSON object that specifies
  116. the remote information for the package. Each element of the array is an
  117. object, with one or more of the keys listed above. If an object features more
  118. than one of the above keys, they are applied in the same order as they have
  119. been listed.
  120. Example: Crypto++
  121. =================
  122. The following catalog entry will build and import `Crypto++`_ for use by a
  123. ``dds`` project. This uses the unmodified Crypto++ repository, which ``dds``
  124. doesn't know how to build immediately. With some simple moving of files, we
  125. end up with something ``dds`` can build directly:
  126. .. code-block:: javascript
  127. "cryptopp": {
  128. "8.2.0": {
  129. "git": {
  130. "url": "https://github.com/weidai11/cryptopp.git",
  131. "ref": "CRYPTOPP_8_2_0",
  132. "auto-lib": "cryptopp/cryptopp",
  133. "transform": [
  134. {
  135. // Crypto++ has no source directories at all, and everything lives
  136. // at the top level. No good for dds.
  137. //
  138. // Clients are expected to #include files with a `cryptopp/` prefix,
  139. // so we need to move the files around so that they match the
  140. // expected layout:
  141. "move": {
  142. // Move from the root of the repo:
  143. "from": ".",
  144. // Move files *into* `src/cryptopp`
  145. "to": "src/cryptopp",
  146. // Only move the C++ sources and headers:
  147. "include": [
  148. "*.c",
  149. "*.cpp",
  150. "*.h"
  151. ]
  152. }
  153. }
  154. ]
  155. }
  156. }
  157. }
  158. Example: libsodium
  159. ==================
  160. For example, this catalog entry will build and import `libsodium`_ for use in
  161. a ``dds`` project. This uses the upstream libsodium repository, which does not
  162. meet the layout requirements needed by ``dds``. With a few simple
  163. transformations, we can allow ``dds`` to build and consume libsodium
  164. successfully:
  165. .. code-block:: javascript
  166. "libsodium": {
  167. "1.0.18": {
  168. "git": {
  169. "url": "https://github.com/jedisct1/libsodium.git",
  170. "ref": "1.0.18",
  171. "auto-lib": "sodium/sodium",
  172. /// Make libsodium look as dds expects of a project.
  173. "transform": [
  174. // libsodium has a `src` directory, but it does not look how dds
  175. // expects it to. The public `#include` root of libsodium lives in
  176. // a nested subdirectory of `src/`
  177. {
  178. "move": {
  179. // Move the public header root out from that nested subdirectory
  180. "from": "src/libsodium/include",
  181. // Put it at `include/` in the top-level
  182. "to": "include/"
  183. }
  184. },
  185. // libsodium has some files whose contents are generated by a
  186. // configure script. For demonstration purposes, we don't need most
  187. // of them, and we can just swipe an existing pre-configured file
  188. // that is already in the source repository and put it into the
  189. // public header root.
  190. {
  191. "copy": {
  192. // Generated version header committed to the repository:
  193. "from": "builds/msvc/version.h",
  194. // Put it where the configure script would put it:
  195. "to": "include/sodium/version.h"
  196. }
  197. },
  198. // The subdirectory `src/libsodium/` is no good. It now acts as an
  199. // unnecessary layer of indirection. We want `src/` to be the root.
  200. // We can just "lift" the subdirectory:
  201. {
  202. // Up we go:
  203. "move": {
  204. "from": "src/libsodium",
  205. "to": "src/"
  206. },
  207. // Delete the now-unused subdirectory:
  208. "remove": {
  209. "path": "src/libsodium"
  210. }
  211. },
  212. // Lastly, libsodium's source files expect to resolve their header
  213. // paths differently than they expect of their clients (Bad!!!).
  214. // Fortunately, we can do a hack to allow the files in `src/` to
  215. // resolve its headers. The source files use #include as if the
  216. // header root was `include/sodium/`, rather than `include/`.
  217. // To work around this, generate a copy of each header file in the
  218. // source root, but remove the leading path element.
  219. // Because we have a separate `include/` and `src/` directory, dds
  220. // will only expose the `include/` directory to clients, and the
  221. // header copies in `src/` are not externally visible.
  222. //
  223. // For example, the `include/sodium/version.h` file is visible to
  224. // clients as `sodium/version.h`, but libsodium itself tries to
  225. // include it as `version.h` within its source files. When we copy
  226. // from `include/`, we grab the relative path to `sodium/version.h`,
  227. // strip the leading components to get `version.h`, and then join that
  228. // path with the `to` path to generate the full destination at
  229. // `src/version.h`
  230. {
  231. "copy": {
  232. "from": "include/",
  233. "to": "src/",
  234. "strip-components": 1
  235. }
  236. }
  237. ]
  238. }
  239. }
  240. }
  241. .. _libsodium: https://doc.libsodium.org/
  242. .. _Crypto++: https://cryptopp.com/