Path: blob/main/crypto/openssl/doc/HOWTO/documenting-functions-and-macros.md
34868 views
Documenting public Functions and Macros
In the last few years, the OpenSSL project has strived to improve the quality and coverage of the API documentation. A while ago, this goal has been turned into an official documentation-policy. This policy is actively enforced by the make doc-nits
target resp. check-docs
GitHub action.
If you add a new public function or macro to a header file without documenting it, it will give you an error message like this:
and you'll want to document this.
So, create a new .pod
file named doc/man3/FUNCTION.pod
.
If you are asked to document several related functions in that file, you can create a single pod file in which you document them together. In this case, use the name of the first function as the file name, like for the above example:
If you do use an unrelated name (like BIO_dgram.pod
) then you'll get a warning about that.
Next, you need to add your new file to the doc/build.info
file. This command does it automatically for you:
this will update doc/build.info
. You should git add the result as generate_doc_buildinfo
is not run on every build.
With these two changes, running make doc-nits
locally should now agree with you that you have documented all your new defines, but it might then complain:
If it is the case that your interface is meant to be public, then you need to edit the file util/other.syms
to add the names of your #define
functions. This file gets sorted alphabetically prior to each major release, but new additions should be placed at the end of the file.
Example
For demonstration purposes, two new public symbols have been added by "implementing" a public function BIO_set_dgram_foo()
and a public function-like macro BIO_set_dgram_bar()
:
If you run make doc-nits
, you might be surprised that it only complains about the undocumented macro, not the function:
The explanation for this is that one important step is still missing, it needs to be done first: you need to run
which triggers a scan of the public headers for new API functions.
All new functions will be added to either util/libcrypto.num
or util/libssl.num
. Those files store the information about the symbols which need to be exported from the shared library resp. DLL. Among other stuff, they contain the ordinal numbers for the module definition file of the Windows DLL, which is the reason for the .num
extension.
After running make update
, you can use git diff
to check the outcome:
The changes need to be committed, ideally as a separate commit:
which has the advantage that it can easily be discarded when it becomes necessary to rerun make update
.
Finally, we reached the point where make doc-nits
complains about both symbols:
Additionally, public symbols added should contain an entry in the HISTORY section of their documentation explaining the exact OpenSSL version in which they have appeared for the first time. The option -i for "find-doc-nits" can be utilized to check for this. A completely new documentation file should also contain a HISTORY section with wording along this line, e.g. "These functions have been added in OpenSSL version xxx.".
Summary
The bottom line is that only the way how the public symbols are recorded is different between functions and macros, the rest of the documentation procedure is analogous.