-
Notifications
You must be signed in to change notification settings - Fork 8.1k
traceconfig: generate an annotated Markdown document with source refs #95808
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
base: main
Are you sure you want to change the base?
Conversation
20e4518
to
67704a7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new feature to generate Markdown documentation for Kconfig configuration parameters that details how each symbol received its final value. The documentation includes source references linking to the exact locations in Kconfig files or configuration files where values were set.
- Extends kconfiglib to track source references for all symbol value assignments
- Adds a new
traceconfig
build target that generateskconfig-trace.md
documentation - Implements comprehensive test coverage for the source reference functionality
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
scripts/kconfig/kconfiglib.py | Core implementation of source reference tracking in kconfiglib |
scripts/kconfig/kconfig.py | Adds writing of source reference data in JSON and pickle formats |
scripts/kconfig/traceconfig.py | New script to generate Markdown documentation from source reference data |
cmake/modules/kconfig.cmake | Adds the traceconfig build target |
tests/kconfig/srcrefs/* | Test suite validating source reference functionality |
doc/build/kconfig/tracing.rst | Documentation for the new tracing feature |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
config.md
document with source refsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fairly reasonable.
scripts/kconfig/traceconfig.py
Outdated
SRCREF_TO_STR = { | ||
kconfiglib.SRCREF_UNSET: "unset", | ||
kconfiglib.SRCREF_DEFAULT: "default", | ||
kconfiglib.SRCREF_USER: "user set", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe set by user
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
But please note that changes to Kconfiglib should go upstream first: https://github.com/zephyrproject-rtos/Kconfiglib and then brought down to Zephyr with a reference.
Note also that kconfiglib is used by other projects.
It even states that Kconfiglib is python2/3 compliant (perhaps we should remove python2 as it's no longer maintained, but guess that's another discussion 😉 )
f50932d
to
985e967
Compare
v2:
@erwango Tried to look into adding optional auto-run via |
Tbh, I won't help much here. @carlescufi maybe ? |
# fmt: off | ||
|
||
# Indices for the fields in the trace entries | ||
# Keep these in sync with the generation code in scripts/kconfig/kconfig.py! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'd also place a warning in kconfig.py
, since it's more likely that changes there break this test than the other way around.
985e967
to
579f819
Compare
Replace 'filename' and 'linenr' usages with a single 'loc' attribute, which is a (filename, linenr) tuple. This simplifies code dealing with locations, and makes it explicitly constant. The original attributes are now provided via properties for compatibility. Signed-off-by: Luca Burelli <[email protected]>
Replace filename and linenr parameters to _warn() with a single loc element, which is a constant (filename, linenr) tuple that can be more efficiently passed and stored. Signed-off-by: Luca Burelli <[email protected]>
The 'user_loc' stores the location (filename and line number) where a symbol or choice was last set via a direct user selection. Signed-off-by: Luca Burelli <[email protected]>
Store the location (filename and line number) where a 'select', 'imply', 'range' or 'default' was added to a Symbol or Choice. Signed-off-by: Luca Burelli <[email protected]>
Track information about what caused a value to be set in the 'origin' property of Symbol. 'imply' and 'select' dependencies do not have a location associated with them, so in those cases the location is a string representation of the dependency expression. For defaults and user values, the location in the Kconfig file is stored. Signed-off-by: Luca Burelli <[email protected]>
Collect and save trace data for all symbols in the merged configuration. This includes information about where each symbol was defined or assigned, which can be useful for debugging complex Kconfig setups. The trace data includes the following information for each symbol: - Name - Visibility - Type - Value - Kind and location of value origin (as defined in kconfiglib) The trace data is saved for later use in two formats: a binary pickle file and a human-readable JSON file. Signed-off-by: Luca Burelli <[email protected]>
The new 'traceconfig' target generates a Markdown file listing all configuration symbols, their values, and where those values originated (user assignment, default, selection, implication, or unset). Signed-off-by: Luca Burelli <[email protected]>
Add a test case that verifies Kconfig value origin traces are correctly generated in both JSON and pickle formats. The test includes a sample Kconfig configuration with dependencies, selections, and choices to cover various scenarios. A validation script checks the generated source origin data against expected values. In addition, the 'traceconfig' target is called to test the generation of the Markdown file with the Kconfig trace report. Signed-off-by: Luca Burelli <[email protected]>
579f819
to
eea6715
Compare
Please retry analysis of this Pull-Request directly on SonarQube Cloud |
@tejlmand and others, please re-review, would be useful to have in 4.3... |
This pull request adds a new
traceconfig
build target to generate Markdown documentation for Kconfig symbols that details the reason a value was chosen for each symbol in the configuration. The list of symbols is split in three sorted groups:select
s or implicitdefault
s).Symbols that have a value include a readable and clickable (if the viewer supports it) link to the location of the statement that resulted in that value being applied, be it an explicit assignment or a
default
. For the symbols that areselect
-ed orimply
-ed by multiple sources, the set of matching requirements are printed.Documentation for the new feature is available and a test suite has been added to validate Kconfig source reference functionality.
Sample generated documentation
The new target generates a
zephyr/kconfig-trace.md
file in the project's build folder. This is an example of a full generated documentation for thesample/drivers/spi_flash
project running on thearduino_opta//m7
board.The objective is for the generated document to be easily readable by humans with a simple editor. The entries are rendered like this:
As a raw source
As a Github table
Note: links here have been edited to refer to the upstream used in the PR generation. They are usually relative to where the file was generated.
CONFIG_SERIAL
CONFIG_SIZE_OPTIMIZATIONS
CONFIG_SOC_EARLY_INIT_HOOK
SOC_SERIES_STM32H7X && SOC_FAMILY_STM32
CONFIG_SOC_FLASH_STM32
CONFIG_SRAM_BASE_ADDRESS
CONFIG_SRAM_REGION_PERMISSIONS
ARM_MPU && CPU_HAS_MPU
CONFIG_SRAM_SIZE
CONFIG_STACK_ALIGN_DOUBLE_WORD
CONFIG_STDOUT_CONSOLE
Rendered in VSCode:
Review notes
loc
s (a tuple of filename and line number) in a few specific places to store line information.loc
element shared with multiple entities.Symbols
to collapse this information in a common form, which is exported for later usage by external tools.