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

doc: extensions: add kconfig search extension #41753

Merged
merged 4 commits into from Mar 2, 2022

Conversation

gmarull
Copy link
Member

@gmarull gmarull commented Jan 12, 2022

Introduction

This PR adds a new Sphinx extension to handle Kconfig documentation. The way this extension works differs significantly from the current approach, mainly due to technical limitations that will be detailed next. As of today, a bunch of RST pages are generated (one per option, so ~10K) by a script (gen_kconfig_rest.py). These pages get parsed and rendered by Sphinx when the documentation is built. It turns out that adding ~10K individual pages to Sphinx slows things down, to a point we had to create the KCONFIG_TURBO_MODE or html-fast targets. In practice, this means that any viable solution needs to stay away from individual pages. In fact, the way bindings docs work suffer from the same issue, just that we still have less of them.

Technical aspects of the solution proposed here:

  • It is a native Sphinx extension (no more CMake hackery required)
  • It uses kconfiglib to build a JSON database for all Kconfig symbols
  • Introduces a new Sphinx language domain for Kconfig. The domain provides a Sphinx directive (.. kconfig:search::) that can be used to insert a Kconfig search tool on any RST page. When building HTML docs, that directive gets replaced by an actual search form. The :kconfig:option: role is now available to reference options (goes to Kconfig search form pre-selecting the option). Thanks to using a regular Sphinx domain, Kconfig options can also be referenced in other projects using Intersphinx.
  • A client-side Javascript library takes care of the rest: fetches the database and, based on user input, it renders Kconfig content dynamically. The library also handles URL hash, that is, if the page holding the Kconfig form is queried with #KCONFIG_OPTION_TO_DISPLAY it will just display it. This allows for permalinks, e.g., CONFIG_SPI.

Pros:

  • A native Sphinx extension
  • Only a single page is needed: this means docs will be faster by default
  • We can quickly search Kconfig options (it's faster than Sphinx search!)

Cons:

  • Kconfig options don't have a page now, so search engines will not index them.

Demo

https://teslabs.github.io/zephyr-kconfig-test/kconfig.html

image

@gmarull gmarull added the dev-review To be discussed in dev-review meeting label Jan 12, 2022
@nashif
Copy link
Member

nashif commented Jan 12, 2022

  • Kconfig options don't have a page now, so search engines will not index them.

can we just list them somewhere without any individual rst pages for search engines to index with instructions to use the search capability for more details?

@gmarull
Copy link
Member Author

gmarull commented Jan 12, 2022

  • Kconfig options don't have a page now, so search engines will not index them.

can we just list them somewhere without any individual rst pages for search engines to index with instructions to use the search capability for more details?

Maybe by rendering the whole database will help if crawler is detected: https://developers.google.com/search/docs/advanced/javascript/dynamic-rendering

@github-actions github-actions bot added the Release Notes To be mentioned in the release notes label Jan 12, 2022
@mbolivar-nordic
Copy link
Contributor

Maybe by rendering the whole database will help if crawler is detected: https://developers.google.com/search/docs/advanced/javascript/dynamic-rendering

that kind of sounds like an html-slow ;)

@mbolivar-nordic
Copy link
Contributor

It's a cool idea and I played around with it a bit on your demo site. It is indeed fast, which is great. I don't think having a complete list of Kconfig options in our rendered HTML is very useful except for crawlers, so I think that's not a big loss.

One thing I noticed so far is that you chose to narrow down the set of locations from the complete list of locations in the current pages to just one location. This is picking bad results.

For example, look at CONFIG_SPI_2_NRF_SPIM: https://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_SPI_2_NRF_SPIM.html

The search results page is picking the "wrong" location for it:

2022-38-13_11-38-38

@gmarull
Copy link
Member Author

gmarull commented Jan 14, 2022

It's a cool idea and I played around with it a bit on your demo site. It is indeed fast, which is great. I don't think having a complete list of Kconfig options in our rendered HTML is very useful except for crawlers, so I think that's not a big loss.

One thing I noticed so far is that you chose to narrow down the set of locations from the complete list of locations in the current pages to just one location. This is picking bad results.

For example, look at CONFIG_SPI_2_NRF_SPIM: docs.zephyrproject.org/latest/reference/kconfig/CONFIG_SPI_2_NRF_SPIM.html

The search results page is picking the "wrong" location for it:

2022-38-13_11-38-38

Seems to be a bug in the database generation. It's incomplete now, I need to figure out a way to store all the locations and present the information in a better way to avoid things like that:

image

@gmarull gmarull force-pushed the doc-new-kconfig branch 2 times, most recently from 912f914 to 163d3e6 Compare January 14, 2022 10:11
@mbolivar-nordic
Copy link
Contributor

+1 assuming the issue I pointed out is fixed

@de-nordic
Copy link
Collaborator

Would it be possible to add some html param that would allow to capture search list? This would be useful in case when you need to inform somebody on list of Kconfig options that are dedicated to specific subsystem, for example:
https://teslabs.github.io/zephyr-kconfig-test/kconfig.html?seach=CONFIG_FS_LITTLEFS_
would redirect user to page with the CONFIG_FS_LITTLEFS_ already placed in search bar and list narrowed to Kconfig options beginning with CONFIG_FS_LITTLEFS_.

Add a new extension to handle Kconfig documentation. This means that no
more CMake hackery is required. However, the way it works differs from
the current approach. Instead of creating a single page for each Kconfig
option, the extension creates a JSON "database" which is then used on
the client side to render Kconfig options on a search page. The reason
to go for a single page choice is because Sphinx is significantly slow
when handling a lot of pages. Kconfig was responsible for an increase of
about ~10K pages.

Main features:

- Generates a Kconfig JSON database using kconfiglib APIs.
- Adds a new Sphinx domain for Kconfig. The domain provides a directive,
  :kconfig:search:: that can be used to insert a Kconfig search box onto
  any page. This page is where all Kconfig references inserted using the
  :kconfig:option: role will point to. The search functionality is
  implemented on the client side using Javascript. If the URL contains a
  hash with a Kconfig option (e.g. #CONFIG_SPI) it will load it.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Enable the new extension and delete usage of the old script/extensions.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Kconfig options now belong to the Kconfig domain, therefore, the
:kconfig:option: role needs to be used.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
These are no longer used.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
@gmarull
Copy link
Member Author

gmarull commented Mar 1, 2022

@mbolivar-nordic @henrikbrixandersen @carlescufi @nashif should be ready now

Copy link
Member

@henrikbrixandersen henrikbrixandersen left a comment

Choose a reason for hiding this comment

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

The documentation changes (and the entire concept) looks fine. Thanks!

I know too little of Sphinx to feel comfortable in reviewing the actual Kconfig extension, though.

@gmarull gmarull dismissed henrikbrixandersen’s stale review March 1, 2022 16:00

canopen changes dropped

Copy link
Contributor

@mbolivar-nordic mbolivar-nordic left a comment

Choose a reason for hiding this comment

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

I'm giving a +1 for the feature without having reviewed in detail because I'm confident @gmarull will fix any issues that might get reported after this is merged. Thanks for this.

@carlescufi carlescufi merged commit 483585b into zephyrproject-rtos:main Mar 2, 2022
@gmarull gmarull deleted the doc-new-kconfig branch March 2, 2022 08:29
@stephanosio
Copy link
Member

@gmarull IIUC, http://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_*.html no longer works with this change; then the Kconfig symbol hint link should be updated as well:

SYM_INFO_HINT = """\
See http://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_{0.name}.html
and/or look up {0.name} in the menuconfig/guiconfig interface. The Application
Development Primer, Setting Configuration Values, and Kconfig - Tips and Best
Practices sections of the manual might be helpful too.\
"""

coreboot-org-bot pushed a commit to coreboot/chrome-ec that referenced this pull request Mar 3, 2022
Kconfig generated documentation links changed with
zephyrproject-rtos/zephyr#41753, this fixes all
the upstream links in the existing documentation.

BRANCH=none
BUG=none
TEST=check link on gerrit

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Change-Id: Ib619924837ace0a482d7977fb2676456e2fc6858
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3500306
Reviewed-by: Aaron Massey <aaronmassey@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants