Commit graph

23 commits

Author SHA1 Message Date
Valentin Rothberg
3b28f4f2c2 checkkconfigsymbols.py: support Kconfig's 'imply' statement
Support the new imply statement in Kconfig.  The imply statement has
been added by commit 237e3ad0f1 ("Kconfig: Introduce the "imply"
keyword") and is a weak version of a select, but the target symbol can
still be turned off.

Signed-off-by: Andreas Ziegler <andreas.ziegler@fau.de>
Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-02-03 11:49:06 +01:00
Valentin Rothberg
8e8e333179 checkkconfigsymbols.py: don't sort similar symbols
Don't sort the list of string-similar Kconfig symbols alphabetically to
preserve the correct order of string similarity.

Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-01-19 11:28:31 +01:00
Valentin Rothberg
0d18c19288 checkkconfigsymbols.py: support git's "^" syntax
Support git's "^" syntax for diffing two commits, for instance via
"--diff HEAD^^^..HEAD".

Signed-off-by: Michael Ellermann <mpe@ellerman.id.au>
Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-10-28 08:12:14 -04:00
Valentin Rothberg
2f9cc12bb3 checkkconfigsymbols: use arglist instead of cmd string
Splitting a command string could lead to unintended arguments.  Use an
argument list in the execute() function instead.

Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-08-28 11:08:34 +02:00
Valentin Rothberg
ef3f55438d checkkconfigsymblos: consistent symbol terminology
'symbol' and 'feature' are used synonymously to refer to Kconfig symbols
(configs, menus, etc.).  Use the term 'symbol' to have a consistent
terminology and to make the code more comprehensible.

Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-08-28 11:08:34 +02:00
Valentin Rothberg
36c79c7fac checkkconfigsymbols.py: fix pylint and pep8 warnings
Fix pylint and pep8 warnings to have a consistent syntax and style.

Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-08-28 11:08:34 +02:00
Valentin Rothberg
14390e3164 checkkconfigsymbols: use ArgumentParser
Replace the deprecated OptionParser with ArgumentParser, as recommended
by pylint.

Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-08-28 11:08:34 +02:00
Valentin Rothberg
7c5227af25 checkkconfigsymbols.py: port to Python 3
Python 2 is slowly dying, so port the script to Python 3.

Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-08-28 11:08:34 +02:00
Valentin Rothberg
f175ba174e checkkconfigsymbols.py: avoid shell injection
Use subprocess and set shell to False to avoid potential shell
injections.

Reported-by: Bernd Dietzel <tcpip@t-online.de>
Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-08-27 11:44:01 +02:00
Andrew Donnellan
4c73c0882b checkkconfigsymbols.py: add --no-color option, don't print color to non-TTY
Only print the ANSI colour escape codes if stdout is a TTY. Useful if
redirecting output to a file or piping to another script.

Also add a new option, --no-color, if the user wants to disable colour
output for whatever reason.

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Acked-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-08-18 18:12:07 +02:00
Andreas Ziegler
38cbfe4fe8 checkkconfigsymbols.py: Fix typo in help message
Fix a typo in the help message for the -d parameter by removing one 'm'.

Signed-off-by: Andreas Ziegler <andreas.ziegler@fau.de>
Acked-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-05-01 14:11:12 -07:00
Valentin Rothberg
1b2c841467 checkkconfigsymbols.py: find similar symbols
Add support to find string-similar symbols.  When option --sim SYM is
specified, checkkconfigsymbols.py will print at most 10 symbols defined
in Kconfig that are string similar to SYM in the following format:
    Similar symbols: $COMMA_SEPARATED_LIST_OF_SYMBOLS

Note, if no similar symbols are found it is indicated as follows:
    Similar symbols: no similar symbols found

Since the implemented functionality is also useful when searching the
entire source or when diffing two commits, a list of similar symbols is
printed unconditionally with the other data.  In order to make the
output more readable, the format now looks as follows:

    $UNDEFINED_SYMBOL
    Referencing files: $COMMA_SEPARATED_LIST_OF_FILES
    Similar symbols: $COMMA_SEPARATED_LIST_OF_SYMBOLS
    [Optional with '--find']
    Commits changing symbol:
        - $COMMIT_1_HASH ("$COMMIT_1_MESSAGE")
        - $COMMIT_2_HASH ("$COMMIT_2_MESSAGE")
            or
        - no commit found

Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-12-14 10:54:23 -08:00
Valentin Rothberg
e2042a8a80 checkkconfigsymbols.py: multiprocessing of files
Distribute the parsing of source and Kconfig files on all available
cores to speed up processing.

Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-12-14 10:54:23 -08:00
Valentin Rothberg
0bd38ae355 scripts/checkkconfigsymbols.py: support default statements
Until now, checkkonfigsymbols.py did not check default statements for
references on missing Kconfig symbols (i.e., undefined Kconfig options).
Hence, add support to parse and check the Kconfig default statement.

Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-08-03 17:16:58 -07:00
Valentin Rothberg
c745566306 checkkconfigsymbols.py: colored output
Color output to make it more readable.  Symbols will be printed yellow,
relevant commits (see --find) red.

Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Acked-by: Stefan Hengelein <stefan.hengelein@fau.de>
Acked-by: Andreas Ruprecht <andreas.ruprecht@fau.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-08-03 17:16:58 -07:00
Valentin Rothberg
a42fa92ce7 checkkconfigsymbols.py: find relevant commits
Add option -f/--find to find relevant commits when using the --diff
option.  --find is useful in case a user wants to check commits that
potentially cause a Kconfig symbol to be missing.  This is done via 'git
log -G $SYMBOL' (i.e., to get a list of commits that change $SYMBOL).
The relevant commits are printed below the "SYMBOL\tFILES" line,
followed by an empty line to increase readability.

Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Acked-by: Stefan Hengelein <stefan.hengelein@fau.de>
Acked-by: Andreas Ruprecht <andreas.ruprecht@fau.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-08-03 17:16:58 -07:00
Valentin Rothberg
4b6fda0b80 checkkconfigsymbols.py: set python2 as default interpreter
Some more recent distributions set the default interpreter to python3,
causing the script to break since it's written for python2.

Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-05-24 12:15:29 -07:00
Valentin Rothberg
cf132e4a8e checkkconfigsymbols.py: add option -i to ignore files
Sometimes a user might be interested to filter certain reports (e.g.,
the many defconfigs).  Now, this can be achieved by specifying a Python
regex with -i / --ignore.

Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-05-24 12:15:29 -07:00
Valentin Rothberg
e9533ae539 checkkconfigsymbols.py: fix sorted output
Commit b1a3f24348 ("checkkconfigsymbols.py: make it Git aware")
mistakenly removed to print undefined Kconfig symbols in alphabetical
order.  Furthermore, the script does not print anything anymore when the
entire tree is checked (i.e., when no commit is specified).

This patch restores the sorted output and adds the missing print for the
default case.  Additionally, the file lists are now sorted as well which
(a) makes it easier to read and (b) makes the output deterministic.

Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-03-24 15:18:44 +01:00
Valentin Rothberg
b1a3f24348 checkkconfigsymbols.py: make it Git aware
The script now supports to check a specified commit or a specified range
of commits (i.e., commit1..commit2).  Developers and maintainers are
encouraged to use this functionality before sending or merging patches
to avoid potential bugs and to keep the code, documentation, etc. clean.

This patch adds the following options to the script:

 -c COMMIT, --commit=COMMIT
                  Check if the specified commit (hash) introduces
                  undefined Kconfig symbols.

 -d DIFF, --diff=DIFF
                  Diff undefined symbols between two commits.  The input
                  format bases on Git log's 'commmit1..commit2'.

  --force         Reset current Git tree even when it's dirty.

Note that the first two options require to 'git reset --hard' the user's
Git tree.  This hard reset is necessary to keep the script fast, but it
can lead to the loss of uncommitted data.  Hence, the script aborts in
case it is executed in a dirty tree.  It won't abort if '--force' is
passed.

If neither -c nor -d is specified, the script defaults to check the
entire local tree (i.e., the previous behavior).

Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-03-16 21:10:28 +01:00
Valentin Rothberg
208d51154c checkkconfigsymbols.py: filter reports for tools/
Recent changes to the build system of tools suggest to filter reports
for the entire tools directory.  Various C preprocessor identifiers are
prefixed with CONFIG_ but are NOT defined in Kconfig but in Makefiles in
the tools directory.  Such identifiers are false positives for most static
analysis tools (i.e., scripts/checkkconfigsymbols.py) since the CONFIG_
prefix and the _MODULE suffix is reserved for Kconfig features in CPP
and Make syntax.

Signed-off-by: Valentin Rothberg <Valentin.Rothberg@lip6.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-03-09 20:45:44 +01:00
Valentin Rothberg
cc641d5529 checkkconfigsymbols.py: improve detection of defects
This patch improves the detection of defects by updating the
regular expression to find Kconfig identifiers in the source
code, and fixes some cases of false positives. The following
changes are made:
- improve regex to find Kconfig identifiers in the source
- exclude .log files from analysis
- improve filtering of false positives (e.g, CONFIG_XXX)
- change output format from (feature:\tlist) to (feature\tlist)

Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-11-08 20:50:43 -08:00
Valentin Rothberg
24fe1f03e4 checkkconfigsymbols.sh: reimplementation in python
The scripts/checkkconfigsymbols.sh script searches Kconfig features
in the source code that are not defined in Kconfig. Such identifiers
always evaluate to false and are the source of various kinds of bugs.
However, the shell script is slow and it does not detect such broken
references in Kbuild and Kconfig files (e.g., ``depends on UNDEFINED´´).
Furthermore, it generates false positives. The script is also hard to
read and understand, and is thereby difficult to maintain.

This patch replaces the shell script with an implementation in Python,
which:
    (a) detects the same bugs, but does not report previous false positives
    (b) additionally detects broken references in Kconfig and all
        non-Kconfig files, such as Kbuild, .[cSh], .txt, .sh, defconfig, etc.
    (c) is up to 75 times faster than the shell script
    (d) only checks files under version control

The new script reduces the runtime on my machine (i7-2620M, 8GB RAM, SSD)
from 3m47s to 0m3s, and reports 938 broken references in Linux v3.17-rc1;
419 additional reports of which 16 are located in Kconfig files,
287 in defconfigs, 63 in ./Documentation, 1 in Kbuild.

Moreover, we intentionally include references in comments, which have been
ignored until now. Such comments may be leftovers of features that have
been removed or renamed in Kconfig (e.g., ``#endif /* CONFIG_MPC52xx */´´).
These references can be misleading and should be removed or replaced.

Note that the output format changed from (file list <tab> feature) to
(feature <tab> file list) as it simplifies the detection of the Kconfig
feature for long file lists.

Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Stefan Hengelein <stefan.hengelein@fau.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-11-07 09:55:27 -08:00