Commit graph

4 commits

Author SHA1 Message Date
Ulf Magnusson e2f647b08b scripts: kconfig: lint.py: Add check for missing CONFIG_ prefix
Add a new --check-missing-config-prefix check that looks for references
like

    #if MACRO
    #if(n)def MACRO
    defined(MACRO)
    IS_ENABLED(MACRO)

where MACRO is the name of a defined Kconfig symbol but doesn't have a
CONFIG_ prefix. Could be a typo.

Skip MACRO if it is #define'd somewhere, even if it looks like a Kconfig
symbol.

Found e.g. https://github.com/zephyrproject-rtos/zephyr/pull/22195.

Piggyback skipping binary files when grepping for Kconfig symbol
references.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-31 19:29:49 +01:00
Ulf Magnusson 5372dedf2f scripts: kconfig: lint.py: Improve error reporting
If the working directory for a command was missing (usually due to
forgetting to run 'west update'), you'd get a FileNotFoundError
exception along with a cryptic error like

    'git' not found

Only catch OSError instead (which is a base class of FileNotFoundError),
and always show the exception message. It makes it clear that it's the
working directory that's missing.

Add some other misc. improvements too:

 - Turn stderr output from external commands into a warning instead of
   an error

 - Add err() and warn() helpers

 - Include the command name in messages

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-09 11:19:57 -05:00
Ulf Magnusson e181e1b773 kconfiglib: Update to hide tracebacks for expected errors
Update Kconfiglib to upstream revision 9c0b562c94 to get this commit in:

    Add Kconfig.__init__() helper flag for suppressing tracebacks

    Tools that don't use standard_kconfig() currently generate spammy
    tracebacks for e.g. syntax errors.

    Add a suppress_traceback flag to Kconfig.__init__() for catching
    "expected" exceptions and printing them to stderr and exiting with
    status 1. Use it to make all tools consistently hide tracebacks.

Use the new flag to hide tracebacks for expected exceptions in
kconfig.py, lint.py, and genrest.py.

Some menuconfig robustness tweaks for wonky terminals are included as
well, and a new feature for customizing .config and autoconf.h header
comments via environment variables.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-12-20 19:48:09 -05:00
Ulf Magnusson a328c5190d kconfig: Add linting script
Add a cleaned-up version of a script I used to find a bunch of unused
symbols and some other Kconfig issues. It's set up to be run directly,
with few environment dependencies.

West is required, because the checks need to see Kconfig files and
source code from all modules.

Checks so far:

 - Symbols that can never be anything but n/empty

 - Symbols that look unused

 - menuconfig symbols with empty menus

 - Symbols only defined in Kconfig.defconfig files

See the help strings for the command-line flags for more information.

Some of these checks could probably be checked in CI later, though the
always-n and unused-symbol checks are a bit heuristic and might need a
lot of whitelisting.

Another reason I want to get this in is to have a clean standalone
reference for how to set up the environment for parsing the Kconfig
files. It's gotten trickier over time.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-07 15:32:50 +01:00