1.. _acrn_doc:
2
3ACRN Documentation Generation
4#############################
5
6These instructions will walk you through generating the Project ACRN's
7documentation and publishing it to https://projectacrn.github.io.
8You can also use these instructions to generate the ACRN documentation
9on your local system.
10
11.. contents::
12   :local:
13   :depth: 1
14
15Documentation Overview
16**********************
17
18Project ACRN content is written using the reStructuredText markup
19language (``.rst`` file extension) with Sphinx extensions, and processed
20using Sphinx to create a formatted stand-alone website. Developers can
21view this content either in its raw form as .rst markup files, or you
22can generate the HTML content and view it with a web browser directly on
23your workstation.
24
25You can read details about `reStructuredText`_, and `Sphinx`_ from
26their respective websites.
27
28The project's documentation contains the following items:
29
30* ReStructuredText source files used to generate documentation found at the
31  https://projectacrn.github.io website or via the redirect at
32  https://docs.projectacrn.org.  All of the reStructuredText sources
33  are found in the ``acrn-hypervisor/doc`` folder, or pulled in from sibling
34  folders (such as ``misc/``) by the build scripts.
35
36* Doxygen-generated material used to create all API-specific documents
37  found at http://projectacrn.github.io/latest/api/.  The documentation build
38  process uses doxygen to scan source files in the hypervisor and
39  device-model folders (as explained later).
40
41.. image:: images/doc-gen-flow.png
42   :align: center
43
44The reStructuredText files are processed by the Sphinx documentation system
45and use the breathe extension for including the doxygen-generated API
46material.
47
48
49Set Up the Documentation Working Folders
50****************************************
51
52You'll need ``git`` installed to get the working folders set up:
53
54* For an Ubuntu development system use:
55
56  .. code-block:: bash
57
58     sudo apt install git
59
60We use the source header files to generate API documentation and we use
61``github.io`` for publishing the generated documentation.  Here's the
62recommended folder setup for documentation contributions and generation:
63
64.. code-block: none
65
66   projectacrn/
67      acrn-hypervisor/
68         debian/
69         devicemodel/
70         doc/
71         hypervisor/
72         misc/
73
74The parent ``projectacrn folder`` is there because, if you have repo publishing
75rights, we'll also be creating a publishing area later in these steps.
76
77In the following steps, you'll create a fork of the upstream ``acrn-hypervisor``
78repo to your personal GitHub account, clone your personal fork to your local
79development computer, and then link that to the upstream repo as well:
80
81#. Use your browser to visit https://github.com/projectacrn and do a
82   fork of the **acrn-hypervisor** repo to your personal GitHub account.)
83
84   .. image:: images/acrn-doc-fork.png
85      :align: center
86
87#. At a command prompt, create a working folder on your development computer and
88   clone your personal acrn-hypervisor repository:
89
90   .. code-block:: bash
91
92      cd ~
93      mkdir projectacrn && cd projectacrn
94      git clone https://github.com/<github-username>/acrn-hypervisor.git
95
96#. For the cloned local repo, tell git about the upstream repo:
97
98   .. code-block:: bash
99
100      cd acrn-hypervisor
101      git remote add upstream https://github.com/projectacrn/acrn-hypervisor.git
102
103   After that, you'll have ``origin`` pointing to your cloned personal repo and
104   ``upstream`` pointing to the project repo.
105
106#. If you haven't done so already, be sure to configure git with your name
107   and email address for the ``signed-off-by`` line in your commit messages:
108
109   .. code-block:: bash
110
111      git config --global user.name "David Developer"
112      git config --global user.email "david.developer@company.com"
113
114Install the Documentation Tools
115*******************************
116
117Our documentation processing has been tested to run with Python 3.8.10 and
118later, and these other tools:
119
120* breathe                   version: 4.34.0 (>=4.2.3)
121* sphinx                    version: 5.3.0  (>=3.2.1, <6.0)
122* docutils                  version: 0.16.1 (>=0.16, <=0.17.1)
123* sphinx-rtd-theme          version: 1.0.0
124* sphinx-tabs               version: 3.4.0 (>=1.3.0, <=3.4.0)
125* doxygen                   version: 1.8.17 (Ubuntu 20.04) and 1.9.1 (Ubuntu 22.04)
126
127Depending on your Linux version, install the needed tools. You may get a
128different (newer) version of doxygen (installed using ``apt``) than shown here,
129that may also work.
130
131For Ubuntu use:
132
133.. code-block:: bash
134
135   sudo apt install doxygen python3-pip \
136     python3-wheel make graphviz xsltproc
137
138Then use ``pip3`` to install the remaining Python-based tools specified in the
139:acrn_file:`doc/scripts/requirements.txt` file:
140
141.. code-block:: bash
142
143   cd ~/projectacrn/acrn-hypervisor/doc
144   pip3 install --user -r scripts/requirements.txt
145
146Use this command to add ``$HOME/.local/bin`` to the front of your ``PATH`` so the system will
147find expected versions of these Python utilities such as ``sphinx-build`` and
148``breathe`` (you should first check whether this directory is already on your path):
149
150.. code-block:: bash
151
152   printf "\nexport PATH=\$HOME/.local/bin:\$PATH" >> ~/.bashrc
153
154.. important::
155
156   You will need to open a new terminal for this change to take effect.
157   Adding this to your ``~/.bashrc`` file ensures it is set by default.
158
159And with that you're ready to generate the documentation.
160
161.. note::
162
163   We've provided a script you can run to show what versions of the
164   documentation building tools are installed and compare with the
165   tool versions shown above. This tool will also verify you're using tool
166   versions known to work together::
167
168      doc/scripts/show-versions.py
169
170   for example:
171
172   .. code-block:: console
173
174      ~/projectacrn/acrn-hypervisor/doc$ scripts/show-versions.py
175
176      doc build tool versions found on your system...
177
178       breathe                   version: 4.34.0
179       sphinx                    version: 5.3.0
180       docutils                  version: 0.17.1
181       sphinx-rtd-theme          version: 1.0.0
182       sphinx-tabs               version: 3.4.0
183       doxygen                   version: 1.9.1
184
185Extra Tools for Generating PDF
186==============================
187
188While the primary output for ACRN documentation is for an HTML website, you can
189also generate a PDF version of the documentation.  A few extra tools are needed
190only if you want to create PDF output.  For Ubuntu users add these additional
191packages:
192
193.. code-block:: bash
194
195   sudo apt install texlive-latex-recommended texlive-fonts-recommended \
196     texlive-latex-extra latexmk texlive-xetex xindy
197
198Documentation Presentation Theme
199********************************
200
201Sphinx supports easy customization of the generated HTML documentation
202appearance through the use of themes.  Replace the theme files and do
203another ``make html`` and the output layout and style is changed. The
204sphinx build system creates document cache information that attempts to
205expedite documentation rebuilds, but occasionally can cause an unexpected error or
206warning to be generated.  Doing a ``make clean`` to create a clean
207generation environment and a ``make html`` again generally fixes these issues.
208
209The ``read-the-docs`` theme is installed as part of the
210``requirements.txt`` list above.  Tweaks to the standard
211``read-the-docs`` appearance are added by using CSS
212and JavaScript customization found in ``doc/static``, and
213theme template overrides found in ``doc/_templates``.
214
215Run the Documentation Processors
216********************************
217
218The ``acrn-hypervisor/doc`` directory has all the ``.rst`` source files, extra
219tools, and ``Makefile`` for generating a local copy of the ACRN technical
220documentation. (Some additional ``.rst`` files and other material is extracted
221or generated from the ``/misc`` folder as part of the ``Makefile``.)
222
223.. code-block:: bash
224
225   cd ~/projectacrn/acrn-hypervisor/doc
226   make html
227
228Depending on your development system, it will take less than two minutes to
229collect and generate the HTML content.  When done, you can view the HTML
230output with your browser started at
231``~/projectacrn/acrn-hypervisor/doc/_build/html/index.html``. You can
232also ``cd`` to the ``_build/html`` folder and run a local web server
233with the command:
234
235.. code-block:: bash
236
237   cd _build/html
238   python3 -m http.server
239
240and use your web browser to open the URL:  ``http://localhost:8000``.
241
242Generate PDF Output
243===================
244
245After the HTML content is generated, it leaves artifacts behind that you can
246use to generate PDF output using the Sphinx ``latex`` builder.  This
247builder initially creates LaTeX output in the ``_build/latex`` folder and then
248uses the ``latexmk`` tool to create the final ``acrn.pdf`` file in the same
249folder.  This process automatically makes a few passes over the content to create the index
250and resolve intra-document hyperlinks, and produces plenty of progress messages along the
251way.  The Sphinx-generated output for tables and code blocks also yields many "underfill"
252and "overfill" messages from the ``latex`` builder that can't be easily
253suppressed or fixed.  Because of that, we recommend running this PDF generation
254with the ``-silent`` options, like this (after you've run ``make html``:
255
256.. code-block:: bash
257
258   make latexpdf LATEXMKOPTS="-silent -f"
259
260For convenience, we've also created a make target called ``pdf`` that will
261generate the HTML content and then make the PDF file in one step:
262
263.. code-block:: bash
264
265   make pdf
266
267This make target runs quietly, and then verifies that no unexpected message from
268the build process are produced (using the :ref:`message filtering process
269<filter_expected>` explained below.  Either way, when the build completes, the
270generated PDF file is in ``_build/latex/acrn.pdf``.
271
272Publish Content
273***************
274
275If you have merge rights to the projectacrn repo called
276``projectacrn.github.io``, you can update the public project documentation
277found at https://projectacrn.github.io and redirected from
278https://docs.projectacrn.org.
279
280You'll need to do a one-time clone of the upstream repo (we publish
281directly to the upstream repo rather than to a personal forked copy):
282
283.. code-block:: bash
284
285   cd ~/projectacrn
286   git clone https://github.com/projectacrn/projectacrn.github.io.git
287
288Then, after you've verified the generated HTML from ``make html`` looks
289good, you can push directly to the publishing site with:
290
291.. code-block:: bash
292
293   make publish
294
295This uses git commands to synchronize the new content with what's
296already published and will delete files in the publishing repo's
297**latest** folder that are no longer needed. New or changed files from
298the newly-generated HTML content are added to the GitHub pages
299publishing repo.  The public site at https://projectacrn.github.io will
300be updated by the `GitHub pages system
301<https://guides.github.com/features/pages/>`_, typically within a few
302minutes.
303
304Document Versioning
305*******************
306
307The https://projectacrn.github.io site has a document version selector
308at the top of the left nav panel.  The contents of this version
309selector are defined in the ``conf.py`` sphinx configuration file,
310specifically:
311
312.. code-block:: python
313   :emphasize-lines: 5-6
314
315   html_context = {
316      'current_version': current_version,
317      'docs_title': docs_title,
318      'is_release': is_release,
319      'versions': ( ("latest", "/latest/"),
320                    ("2.7", "/2.7/"),
321                    ("2.6", "/2.6/"),
322                    ("2.5", "/2.5/"),
323                    ("2.0", "/2.0/"),
324                    ("1.6.1", "/1.6.1/"),
325                    ("1.0", "/1.0/"),   # keep 1.0
326                  )
327       }
328
329
330As new versions of ACRN documentation are added, update this
331``versions`` selection list to include the version number and publishing
332folder.  Note that there's no direct selection to go to a newer version
333from an older one, without going to ``latest`` first.
334
335By default, documentation build and publishing both assume we're generating
336documentation for the main branch and publishing to the ``/latest/``
337area on https://projectacrn.github.io. When we're generating the
338documentation for a tagged version (e.g., 2.7), check out that version
339of the repo, and add some extra flags to the ``make`` commands:
340
341.. code-block:: bash
342
343   cd ~/projectacrn/acrn-hypervisor/doc
344   git checkout v2.7
345   make clean
346   make DOC_TAG=release RELEASE=2.7 html
347   make DOC_TAG=release RELEASE=2.7 publish
348
349.. _filter_expected:
350
351Filter Expected Warnings
352************************
353
354Alas, there are some known issues with the doxygen/Sphinx/Breathe
355processing that generates warnings for some constructs, in particular
356around unnamed structures in nested unions or structs.
357While these issues are being considered for fixing in
358Sphinx/Breathe, we've added a post-processing filter on the output of
359the documentation build process to check for "expected" messages from the
360generation process output.
361
362The output from the Sphinx build is processed by the Python script
363``scripts/filter-known-issues.py`` together with a set of filter
364configuration files in the ``.known-issues/doc`` folder.  (This
365filtering is done as part of the ``Makefile``.)
366
367If you're contributing components included in the ACRN API
368documentation and run across these warnings, you can include filtering
369them out as "expected" warnings by adding or editing a conf file in the
370``.known-issues/doc`` folder, following the example of other conf files
371found there.
372
373.. _reStructuredText: http://sphinx-doc.org/rest.html
374.. _Sphinx: http://sphinx-doc.org/
375