Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(doc_builder.py) overhaul, remove bugs, clean up, modularize #7913

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

vwheeler63
Copy link
Contributor

@vwheeler63 vwheeler63 commented Mar 10, 2025

This PR has been long in the making. Firstly, doc_builder.py was a module that was partly a package that dealt with Doxygen XML output as well as logic that generated API pages and links to those pages for build.py -- and these two logically separate functions were literally mixed inside the file, making it difficult to understand and maintain. Finally, it had a significant amount of duplicated functionality, undocumented and/or obfuscated (difficult-to-comprehend) code, and several important bugs, all of which have been fixed herein.

  • doc_builder.py was split into 2 cleanly-designed modules:

    • doxygen_xml.py is now the module that deals with Doxygen XML output (also used by gen_json.py, which still generates what it previously generated), and
    • api_doc_builder.py is now much cleaner and better logic that:
      • generates API pages, and
      • adds hyperlinks to those pages to eligible docs in the intermediate directory.
  • 3 bugs were found and fixed in doxygen_xml.py that was previously causing about 11.7KB of documentation to be erroneously omitted from the JSON output by gen_json.py, and simultaneously omitted linkage of certain elements in the data structure back to their source files. Both of these were fixed and documented.

  • api_doc_builder.py now takes into account NOT generating API pages for source code that Doxygen was told to ignore (e.g. thorvg and other 3rd-party library code that is not part of the LVGL API). Simultaneously, this eliminates a large number of Sphinx errors from the doc build.

  • Issue Generated API-Page Link Problems #7068 spells out illogic in auto-generating hyperlinks to the API pages, that especially did not age well when documents were renamed or restructured. This has been thoroughly handled herein.

  • The API-page hyperlinks added to eligible documents are now of better quality:

    • For a document to be eligible for adding API-page links to, it must have an API section at the end.
    • Writers/editors can add their own API hyperlinks of they wish. These will remain at the top of the list and will not be repeated.
    • Per Issue Generated API-Page Link Problems #7068, writers/editors can now add guiding API-hyperlink directives to documents that remains robust regardless of documents being renamed and/or restructured.
    • Previously lv_types_h was in virtually every hyperlink list (useless). No more.
    • lv_xxxx_private_h links are now included. Reason: advanced users are going to need this documentation, and it is important for all users to understand that these files exist even when that user is not directly accessing the fields in "private" structs. Better to err on side of thoroughness.
    • API-hyperlink lists are now ordered with a special sort algorithm that helps readers more quickly find links in long lists.
  • Functionality that previously prepared the Doxyfile and ran Doxygen is factored out from 2 places to 1 place, now handled inside doxygen_xml.py.

  • Functionality that handled non-trivial log-type announcements to STDOUT during the build processes factored out from many places to 1 place in new announce.py module.

  • doxygen_xml.py now uses the new doxygen_config.py module to gracefully and reliably manage Doxyfile configuration contents, so the need for the Doxyfile to carry place-holder values for the doc-build process (that make it unusable to an end user) is no longer needed. The result is that Doxyfile is now set up so it is syntactically correct and logical for its location, so any user can

    $ cd ./docs/
    $ doxygen

    and it will generate HTML output in ./docs/doxygen/html or ./docs/doxygen/xxxx where xxxx is any other format the user turns on in the Doxyfile. The local .gitignore file has been modified to allow for this without making Git think new files have arrived. It's not that this is needed, but it is sometimes nice be able to reference Doxygen HTML when verifying API documentation in source files is being done correctly. This is about 50X faster than doing a whole doc-build to find out. This is very useful when you are "tweaking" API documentation in source files to ensure Doxygen understands it correctly. Further, it seemed somewhat unprofessional to have a Doxyfile sitting there carrying invalid Doxygen syntax and thereby being useless, even if someone wanted to use it—he could not change it lest it would previously break the doc-build process. This restriction (thankfully) no longer applies.

As usual, http://crystal-clear-research.com/for_gabor/demo/docs.lvgl.io/master/ is a reflection of what the documentation will look like with this PR merged.

Resolves #7068

cc: @kisvegabor

I attest this is okay to merge.

Notes

  • Update the Documentation if needed. Done.
  • Add Examples if relevant. n/a
  • Add Tests if applicable. n/a
  • If you added new options to lv_conf_template.h run lv_conf_internal_gen.py and update Kconfig. n/a
  • Run scripts/code-format.py (astyle v3.4.12 needs to installed by running cd scripts; ./install_astyle.sh) and follow the Code Conventions. n/a
  • Mark the Pull request as Draft while you are working on the first version, and mark is as Ready when it's ready for review. Done.
  • When changes were requested, re-request review to notify the maintainers. Done.
  • Help us to review this Pull Request! Anyone can approve or request changes.

...and:

- make `api_doc_builder.py` a client of `doxy_xml_parser` handling
  creation of API pages and adding API hyperlinks to those pages.
  This moves from old `doc_builder.py` functionality that was ONLY
  used by build.py.  (It also serves `gen_json.py`, so doesn't need
  build.py functionality.)
- pycparser_monkeypatch.py:  rename `doc_builder.py` module to
  `doxy_xml_parser` and document what it provides.  Add some
  function args to provide DoxygenXmlParser() with what it needs.
- gen_json.py:  function args to provide DoxygenXmlParser() with
  what it needs, and rename some vars to be very clear about what
  they are.
...how logic is managed when no change of directory is needed.
...and build.py:  enhance announcements
...now handling reads and writes of Doxyfile for both
`gen_json.py` and `build.py` via `api_doc_builder.py`.
The place-holder "tags" in Doxyfile are no longer needed thanks
to the introduction of `doxygen_config.py` module that now gives us
an easy interface to the Doxygen settings during the doc-build process.
The Doxyfile settings pertinent to the doc-build are now set (overridden)
during the doc-build without altering the original Doxyfile.
- Maintenance nightmare recursive directory-tree-walking logic
  replaced with clean, easy-to-understand tree-walking logic.
- API page now not included if Doxygen did not generate any
  documentation for it.  This places the control point of what
  gets excluded in the Doxyfile EXCLUDE_PATTERNS list,
  which is where it belongs.  No more empty API pages with
  error messages in them.
...Doxygen TAGFILES!  (Very cool shortcut found to connect
C symbols with the C files they were contained in.  A much more
complex version of this is currently being used to generate hyperlinks
to API pages.
...that was causing struct docstrings to be excluded from
`gen_json.py`'s JSON output.  It was also adversely impacting the
new algorithm for adding API links to docs, since STRUCT objects
`file_name` attributes were not being populated.
...preventing them from being associated with their source files.
...that Doxygen does not generate documentation for.

Also, new API-link-generation algorithm partially implemented,
with TODOs listed for what is left.
- Only `.rst` files with API section at end are eligible.
- Allow doc writers/editors to add their own API links.
  New links added will not duplicate these, and the editor-added
  links will remain at the top.
- Now parses and adds API-links per new link directives as per Issue lvgl#7068.
- Minus the new link directcives, a more logical version of the original
  algorithm is used (until API-link directives can be added).
- Previously `lv_types_h` link was in almost every list.  No more.
- `lv_xxxx_private_h` links now included where applicable.
  Reason:  advanced users are going to need this documentation,
  and it is important for all users to understand that these files exist
  even when that user is not directly accessing the fields in the
  private structs.  Better to err on the side of thoroughness.
- API-link lists now have a special sort algorithm applied to them
  to help users find links quickly in long lists.
- Modify build.py to pass simpler dir list to examine.
- Fix 3 build.py announce lines that were not passing __file__ correctly.
@vwheeler63 vwheeler63 force-pushed the docs/doc_builder_overhaul branch from e52f5fc to ce609ed Compare March 10, 2025 17:12
...add `./docs/src/intro/` directory to docs searched for API sections
at end, since they may be added to certain docs therein.
@vwheeler63 vwheeler63 force-pushed the docs/doc_builder_overhaul branch from ce609ed to ad46630 Compare March 10, 2025 17:17
...that was causing UNION objects to be added into the STRUCTS
dictionary and leaving the unions dictionary empty.  The result
is that `gen_json.py` now has 465 additional bytes of docstrings
that were being erroneously omitted before.
@vwheeler63 vwheeler63 force-pushed the docs/doc_builder_overhaul branch from de5d5ad to acfe952 Compare March 10, 2025 18:40
Copy link
Member

@kisvegabor kisvegabor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Victor,

Im on embedded world and could not immerse in it deeply. In principle in looks great, and happy that these long outstanding error with thorvg (and others) are resolved. @liamHowatt please test it on your end.

@vwheeler63
Copy link
Contributor Author

vwheeler63 commented Mar 11, 2025

In principle in looks great, and happy that these long outstanding error with thorvg (and others) are resolved.

cc: @liamHowatt

Indeed. By the way, this upgrade now makes several things possible that were hidden problems before:

  • Doc renaming and restructuring can now be done without losing valuable API links.
  • A number of docs incorrectly have API links to things like thorvg files, when they are not actually part of the LVGL API. There are 7 of them, which I am planning to handle after this merge is complete.
  • Refine API links. Some documents like draw.rst have an unusually long list of API links and at least half of them (if not 2/3) are not really applicable -- all because the word "draw" was found as the "word" after "lv_..." (or "_lv_...") in 1 or more C symbols—which is the incomplete algorithm this upgrade gets us away from. There are quite a few places this can occur.

Anyway, my point is to let the two of you know these things are coming (with a "wrap-up" PR) and have been prevented (up to this point) by that incomplete algorithm being in the way—remedied herein.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generated API-Page Link Problems
2 participants