| 1 |
# KDE Doxygen Tools |
| 2 |
|
| 3 |
## Introduction |
| 4 |
|
| 5 |
This framework contains scripts and data for building API documentation (dox) in |
| 6 |
a standard format and style. |
| 7 |
|
| 8 |
https://api.kde.org holds the result, and this very page is handled by KApiDox too: https://api.kde.org/frameworks/kapidox/html/index.html. |
| 9 |
|
| 10 |
The [Doxygen](https://www.doxygen.nl) tool performs the actual documentation extraction and |
| 11 |
formatting. This framework provides a wrapper script to make generating the |
| 12 |
documentation more convenient (including reading settings from the target |
| 13 |
framework or other module) and a standard template for the generated |
| 14 |
documentation. |
| 15 |
|
| 16 |
## Installation |
| 17 |
Python 3 is required to run the scripts, as well as the `jinja`, `pyyaml`, `requests`, `doxypypy` and `doxyqml` python modules. |
| 18 |
|
| 19 |
The following command creates a venv and installs the tool alongside all its modules: |
| 20 |
|
| 21 |
``` |
| 22 |
bash ./bootstrap-devenv.sh |
| 23 |
``` |
| 24 |
|
| 25 |
To generate the dependency diagrams, you need the Graphviz Python bindings. |
| 26 |
They are currently not available from pip, but most distributions provide them. |
| 27 |
You can get binaries and source archives from |
| 28 |
<https://www.graphviz.org/download/>. |
| 29 |
|
| 30 |
## (For maintainers) updating the package dependencies |
| 31 |
|
| 32 |
Run ./requirements-update.sh in this folder, review and test the updated requirements file and commit the changed file. |
| 33 |
|
| 34 |
## Workflow |
| 35 |
|
| 36 |
This document describes two ways to use KApiDox to generate documentation for KDE software: the manual way, and the container way. Both can apply to standalone repositories or to projects built using [kdesrc-build](https://community.kde.org/Get_Involved/development), but the main role of the manual method is mostly to learn how the tool works, whereas the container method should be the cleaner, more convenient way. |
| 37 |
|
| 38 |
### The manual way |
| 39 |
|
| 40 |
With this method, we will be using three directories (kirigami, kapidox and kirigamidocs). |
| 41 |
|
| 42 |
First, clone the desired repository as well as the KApiDox repository. In this example we will use Kirigami: |
| 43 |
|
| 44 |
```bash |
| 45 |
git clone https://invent.kde.org/frameworks/kirigami.git |
| 46 |
git clone https://invent.kde.org/frameworks/kapidox.git |
| 47 |
``` |
| 48 |
|
| 49 |
You may use the ssh:// version instead if you have a developer account. |
| 50 |
|
| 51 |
You should now have a `kirigami` and a `kapidox` folder. Make a new folder to store the local test HTML documentation, then switch to the kapidox directory: |
| 52 |
|
| 53 |
```bash |
| 54 |
mkdir kirigamidocs |
| 55 |
cd kapidox |
| 56 |
``` |
| 57 |
|
| 58 |
Run the script provided by the KApiDox repository. This only needs to be done once, and it will download and install the needed Python3 modules and generate a proper Python virtual environment: |
| 59 |
|
| 60 |
```bash |
| 61 |
bash bootstrap-devenv.sh |
| 62 |
``` |
| 63 |
|
| 64 |
After the script is done, you should have a hidden folder called `.kapidox_venv/`, inside of which is a `bin/` folder containing the files we will be using. |
| 65 |
|
| 66 |
If the shell you are using is bash or zsh, you can run `source .kapidox_venv/bin/activate` to activate the Python virtual venv. If you are using csh or fish, you may use `source .kapidox_venv/bin/activate.csh` or `source .kapidox_venv/bin/activate.fish`, respectively. |
| 67 |
|
| 68 |
After activating the Python venv, your terminal prompt should change to that of a venv. Switch to the folder we created earlier and run kapidox-generate by pointing to the folder containing the target project repository (in this case, Kirigami): |
| 69 |
|
| 70 |
```bash |
| 71 |
cd ../kirigamidocs |
| 72 |
kapidox-generate ../kirigami |
| 73 |
``` |
| 74 |
|
| 75 |
It can take a while. After it is done, for convenience, do not close this venv shell yet. |
| 76 |
|
| 77 |
You should have an `index.html` file which should be the entrypoint of the new documentation. You can open a new instance of your terminal or another tab, then open it directly from your terminal by using `xdg-open index.html` or `kioclient exec index.html`, or whichever other method you'd like. |
| 78 |
|
| 79 |
After that, you may edit the Doxygen-formatted documentation in *.qml or *.h files using Kate or your favorite editor. |
| 80 |
|
| 81 |
After you're finished editing, you can switch back to the venv in the `kirigamidocs/` folder, check that you are in the correct folder with `pwd`, and run the following to regenerate the locally edited documentation: |
| 82 |
|
| 83 |
```bash |
| 84 |
pwd # Outputs e.g. ~/kirigamidocs |
| 85 |
rm -rf * && kapidox-generate ../kirigami |
| 86 |
``` |
| 87 |
|
| 88 |
Now that you understand how to generate the venv and how to use `kapidox-generate`, you can easily apply this knowledge to projects built using kdesrc-build. Assuming you're using bash: |
| 89 |
|
| 90 |
```bash |
| 91 |
kdesrc-build kapidox |
| 92 |
// ...building... |
| 93 |
kdesrc-build kirigami |
| 94 |
// ...building... |
| 95 |
mkdir ~/kirigamidocs |
| 96 |
cd ~/kde/src/kapidox |
| 97 |
bash bootstrap-devenv.sh |
| 98 |
source .kapidox_venv/bin/activate |
| 99 |
cd ~/kirigamidocs |
| 100 |
kapidox-generate ~/kde/src/kirigami |
| 101 |
// ...edit files... |
| 102 |
rm -rf * && kapidox-generate ~/kde/src/kirigami |
| 103 |
``` |
| 104 |
|
| 105 |
### The container way |
| 106 |
|
| 107 |
Although it is possible to use KApiDox directly, using it in a container can be much more convenient once it is set up. |
| 108 |
|
| 109 |
You can build a new image with docker or podman: |
| 110 |
|
| 111 |
```bash |
| 112 |
docker build . -t kapidox_generate:latest |
| 113 |
// OR |
| 114 |
podman build . -t kapidox_generate:latest |
| 115 |
``` |
| 116 |
|
| 117 |
By running `docker images` or `podman images` you should now see an image called `localhost/kapidox_generate`. |
| 118 |
|
| 119 |
To run `kapidox-generate` with a project that you want to generate the docs from you need an empty folder for the results (`/path/to/build/folder`). The build directory inside the container is set as `BUILD_DIR` in `Dockerfile`, and must stay in sync with what is used as `CONTAINER_BUILD_DIR` in the volume mapping. |
| 120 |
|
| 121 |
For this example we use `libksane` checked out to `/path/to/libksane`: |
| 122 |
|
| 123 |
```bash |
| 124 |
export HOST_PROJECT_SRC=/path/to/libksane/folder |
| 125 |
export HOST_BUILD_DIR=/path/to/libksane/build/folder |
| 126 |
export CONTAINER_PROJECT_SRC=/home/kapidox/libksane |
| 127 |
export CONTAINER_BUILD_DIR=/home/kapidox/apidox-build |
| 128 |
mkdir $HOST_BUILD_DIR |
| 129 |
docker run \ |
| 130 |
--volume $HOST_PROJECT_SRC:$CONTAINER_PROJECT_SRC \ |
| 131 |
--volume $HOST_BUILD_DIR:$CONTAINER_BUILD_DIR \ |
| 132 |
kapidox_generate:latest \ |
| 133 |
kapidox-generate $CONTAINER_PROJECT_SRC |
| 134 |
``` |
| 135 |
|
| 136 |
## Writing documentation |
| 137 |
|
| 138 |
Writing dox is beyond the scope of this documentation -- see the notes at |
| 139 |
<https://community.kde.org/Frameworks/Frameworks_Documentation_Policy> and the [doxygen |
| 140 |
manual](https://doxygen.nl/manual/docblocks.html). |
| 141 |
|
| 142 |
To allow code to handle the case of being processed by kapidox a C/C++ preprocessor macro |
| 143 |
is set as defined when run: `K_DOXYGEN` (since v5.67.0). |
| 144 |
For backward-compatibility the definition `DOXYGEN_SHOULD_SKIP_THIS` is also set, but |
| 145 |
its usage is deprecated. |
| 146 |
|
| 147 |
The kapidox scripts expects certain things to be present in the directory it is |
| 148 |
run on: |
| 149 |
|
| 150 |
### README.md |
| 151 |
Most importantly, there should be a `README.md` file that works as the main page, like one where this documentation is written in (backward compatibility also authorize `Mainpage.dox` files). The first line of this file |
| 152 |
is particularly important, as it will be used as the title of the documentation. |
| 153 |
|
| 154 |
### metainfo.yaml |
| 155 |
A `metainfo.yaml` file is needed for the library to be generated. It should |
| 156 |
contain some meta information about the library itself, its maintainers, where |
| 157 |
the sources are, etc. |
| 158 |
|
| 159 |
A very simple example can be: |
| 160 |
|
| 161 |
```yaml |
| 162 |
# metainfo.yaml |
| 163 |
description: Library doing X |
| 164 |
maintainer: gwashington |
| 165 |
public_lib: true |
| 166 |
logo: libX.png |
| 167 |
``` |
| 168 |
|
| 169 |
A comprehensive list of the available keys can be found on |
| 170 |
[this page](@ref metainfo_syntax). |
| 171 |
|
| 172 |
By default, the source of the public library must be in `src`, if the |
| 173 |
documentation refers to any dot files, these should be in `docs/dot`. |
| 174 |
Images should be in `docs/pics`, and snippets of example code should be in |
| 175 |
`examples`. See the [Doxygen documentation](https://doxygen.nl/manual/index.html) for help on how to refer to these |
| 176 |
files from the dox comments in the source files. |
| 177 |
|
| 178 |
If you need to override any Doxygen settings, put them in a `docs/Doxyfile.local` in your project. |
| 179 |
Global settings are defined in `src/kapidox/data/Doxyfile.global`. |
| 180 |
|
| 181 |
## Generating the documentation |
| 182 |
|
| 183 |
The tool for generating dox is `src/kapidox_generate`. |
| 184 |
Change to an empty directory, then simply point it at the |
| 185 |
folder you want to generate dox for (such as a frameworks checkout). |
| 186 |
|
| 187 |
For example, if you have a checkout of KCoreAddons at |
| 188 |
~/kde/src/frameworks/kcoreaddons, you could run |
| 189 |
|
| 190 |
~/kde/src/frameworks/kapidox/src/kapidox_generate ~/kde/src/frameworks/kcoreaddons |
| 191 |
|
| 192 |
and it would create a documentation in the current directory, which needs to be empty before executing the command. |
| 193 |
|
| 194 |
kapidox recursively walks through folders, so you can also run it on |
| 195 |
`~/kde/src/frameworks` or `~/src`. For a lot of libraries, the generation can last |
| 196 |
15-30 minutes and use several hundreds of MB, so be prepared! |
| 197 |
|
| 198 |
Pass the --help argument to see options that control the behaviour of the |
| 199 |
script. |
| 200 |
|
| 201 |
Note that on Windows, you will need to run something like |
| 202 |
|
| 203 |
c:\python\python.exe c:\frameworks\kapidox\src\kapidox_generate c:\frameworks\kcoreaddons |
| 204 |
|
| 205 |
## Specific to frameworks (for now) |
| 206 |
|
| 207 |
You can ask `kgenframeworksapidox` to generate dependency diagrams for all the |
| 208 |
frameworks. To do so, you must first generate Graphviz .dot files for all |
| 209 |
frameworks with the `depdiagram-prepare` tool, like this: |
| 210 |
|
| 211 |
mkdir dot |
| 212 |
~/kde/src/frameworks/kapidox/src/depdiagram-prepare --all ~/kde/src/frameworks dot |
| 213 |
|
| 214 |
Then call `kgenframeworksapidox` with the `--depdiagram-dot-dir` option, like |
| 215 |
this: |
| 216 |
|
| 217 |
mkdir frameworks-apidocs |
| 218 |
cd frameworks-apidocs |
| 219 |
~/kde/src/frameworks/kapidox/src/kapidox_generate --depdiagram-dot-dir ../dot ~/kde/src/frameworks |
| 220 |
|
| 221 |
More fine-grained tools are available for dependency diagrams. You can learn |
| 222 |
about them in [depdiagrams](@ref depdiagrams). |
| 223 |
|
| 224 |
|
| 225 |
## Examples of generated pages: |
| 226 |
|
| 227 |
- KDE API documentation: <https://api.kde.org/> |
| 228 |
|
| 229 |
## Licensing |
| 230 |
|
| 231 |
This project is licensed under BSD-2-Clause. But the specific theme used inside KDE |
| 232 |
is licensed under AGPL-3.0-or-later. If you find the AGPL too restrictive you can |
| 233 |
alternatively use the theme from [Docsy](https://github.com/google/docsy) (APACHE-2.0). |
| 234 |
For that you need to replace the style and js script present in `src/kapidox/data/templates/base.html`. |
| 235 |
|
| 236 |
If you need support or licensing clarification, feel free to contact the maintainers. |