2021-09-21 23:04:37 +02:00
|
|
|
#!/usr/bin/env python3
|
2017-07-01 18:07:00 +02:00
|
|
|
# See utils/checkpackagelib/readme.txt before editing this file.
|
2017-02-19 23:17:17 +01:00
|
|
|
|
|
|
|
import argparse
|
|
|
|
import inspect
|
2022-07-31 21:35:14 +02:00
|
|
|
import magic
|
2018-04-01 07:08:14 +02:00
|
|
|
import os
|
2017-02-19 23:17:17 +01:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
2021-12-26 19:49:15 +01:00
|
|
|
import checkpackagelib.base
|
2017-04-19 20:06:21 +02:00
|
|
|
import checkpackagelib.lib_config
|
utils/check-package: new check for Buildroot's defconfig files
Now that we do have support for checking hashes for custom versions
(for the few packages for which we do support custom versions, like the
kernel, some bootloaders...), we want to ensure that our defconfig
files, when they enable one or more such custom version, do enable
checking the hashes for those versions, and thus we want to require all
our defconfigs do enable BR2_DOWNLOAD_FORCE_CHECK_HASHES.
Add a check for that condition.
We need to be careful that we only check Buildroot's defconfig, whether
in-tree or in a br2-external, and not kernel or other kconfig-based
defconfig files, like those in board/ sub-directories. So we only match
defconfig files that are in a configs/ directory, whether at the
toplevel (for in-tree defconfigs), or not (for br2-external defconfigs).
Since we only have two defconfigs that check hashes for custom versions,
regnerate .checkpackageignore to ignore all so-far broken defconfigs.
Suggested-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Cc: Ricardo Martincoski <ricardo.martincoski@datacom.com.br>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2024-03-31 22:34:03 +02:00
|
|
|
import checkpackagelib.lib_defconfig
|
2017-04-19 20:06:21 +02:00
|
|
|
import checkpackagelib.lib_hash
|
2023-05-06 23:25:31 +02:00
|
|
|
import checkpackagelib.lib_ignore
|
2017-04-19 20:06:21 +02:00
|
|
|
import checkpackagelib.lib_mk
|
|
|
|
import checkpackagelib.lib_patch
|
2022-07-31 21:35:18 +02:00
|
|
|
import checkpackagelib.lib_python
|
2022-07-31 21:35:14 +02:00
|
|
|
import checkpackagelib.lib_shellscript
|
2021-12-26 19:49:17 +01:00
|
|
|
import checkpackagelib.lib_sysv
|
2017-02-19 23:17:17 +01:00
|
|
|
|
|
|
|
VERBOSE_LEVEL_TO_SHOW_IGNORED_FILES = 3
|
|
|
|
flags = None # Command line arguments.
|
|
|
|
|
2022-07-31 21:35:14 +02:00
|
|
|
# There are two Python packages called 'magic':
|
|
|
|
# https://pypi.org/project/file-magic/
|
|
|
|
# https://pypi.org/project/python-magic/
|
|
|
|
# Both allow to return a MIME file type, but with a slightly different
|
|
|
|
# interface. Detect which one of the two we have based on one of the
|
|
|
|
# attributes.
|
|
|
|
if hasattr(magic, 'FileMagic'):
|
|
|
|
# https://pypi.org/project/file-magic/
|
|
|
|
def get_filetype(fname):
|
|
|
|
return magic.detect_from_filename(fname).mime_type
|
|
|
|
else:
|
|
|
|
# https://pypi.org/project/python-magic/
|
|
|
|
def get_filetype(fname):
|
|
|
|
return magic.from_file(fname, mime=True)
|
|
|
|
|
2017-02-19 23:17:17 +01:00
|
|
|
|
utils/check-package: decouple adding rules from fixing all intree files
When a new check_function is added to check-package, often there are
files in the tree that would generate warnings.
An example is the Sob check_function for patch files:
| $ ./utils/check-package --i Sob $(git ls-files) >/dev/null
| 369301 lines processed
| 46 warnings generated
Currently these warnings are listed when calling check-package directly,
and also at the output of pkg-stats, but the check_function does not run
on 'make check-package' (that is used to catch regressions on GitLab CI
'check-package' job) until all warnings in the tree are fixed.
This (theoretically) allows new .patch files be added without SoB,
without the GitLab CI catching it.
So add a way to check-package itself ignore current warnings, while
still catching new files that do not follow that new check_function.
Add a file named .checkpackageignore to the buildroot topdir.
It contains the list of check_functions that are expected to fail for
each given intree file tested by check-package.
Each entries is in the format:
<filename> <check_function> [<check_function> ...]
These are 2 examples of possible entries:
package/initscripts/init.d/rcK ConsecutiveEmptyLines EmptyLastLine Shellcheck
utils/test-pkg Shellcheck
Keeping such a list allows us to have fine-grained control over which
warning to ignore.
In order to avoid this list to grow indefinitely, containing entries for
files that are already fixed, make each entry an 'expected to fail'
instead of just an 'ignore', and generate a warning if a check_function
that was expect to fail for a given files does not generate that
warning.
Unfortunately one case that do not generate warning is an entry for a
file that is deleted in a later commit.
By default, all checks are applied. The --ignore-list option allows to
specify a file that contains the list of warnings that should be
ignored.
The paths in the ignore file must be relative to the location of the
ignore file itself, which means:
- in the main Buildroot tree, the paths in the ignore file are
relative to the root of the main Buildroot tree
- in a BR2_EXTERNAL tree, if the ignore file is at the root of the
BR2_EXTERNAL, the paths it contains must be relative to that root
of the BR2_EXTERNAL
This is one more step towards standardizing the use of just 'make
check-package' before submitting patches to the list.
Cc: Sen Hastings <sen@phobosdpl.com>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2022-07-31 21:35:08 +02:00
|
|
|
def get_ignored_parsers_per_file(intree_only, ignore_filename):
|
|
|
|
ignored = dict()
|
|
|
|
entry_base_dir = ''
|
|
|
|
|
|
|
|
if not ignore_filename:
|
|
|
|
return ignored
|
|
|
|
|
|
|
|
filename = os.path.abspath(ignore_filename)
|
|
|
|
entry_base_dir = os.path.join(os.path.dirname(filename))
|
|
|
|
|
|
|
|
with open(filename, "r") as f:
|
|
|
|
for line in f.readlines():
|
|
|
|
filename, warnings_str = line.split(' ', 1)
|
|
|
|
warnings = warnings_str.split()
|
|
|
|
ignored[os.path.join(entry_base_dir, filename)] = warnings
|
|
|
|
return ignored
|
|
|
|
|
|
|
|
|
2017-02-19 23:17:17 +01:00
|
|
|
def parse_args():
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
|
|
|
# Do not use argparse.FileType("r") here because only files with known
|
|
|
|
# format will be open based on the filename.
|
|
|
|
parser.add_argument("files", metavar="F", type=str, nargs="*",
|
|
|
|
help="list of files")
|
|
|
|
|
2018-04-01 07:08:14 +02:00
|
|
|
parser.add_argument("--br2-external", "-b", dest='intree_only', action="store_false",
|
|
|
|
help="do not apply the pathname filters used for intree files")
|
utils/check-package: decouple adding rules from fixing all intree files
When a new check_function is added to check-package, often there are
files in the tree that would generate warnings.
An example is the Sob check_function for patch files:
| $ ./utils/check-package --i Sob $(git ls-files) >/dev/null
| 369301 lines processed
| 46 warnings generated
Currently these warnings are listed when calling check-package directly,
and also at the output of pkg-stats, but the check_function does not run
on 'make check-package' (that is used to catch regressions on GitLab CI
'check-package' job) until all warnings in the tree are fixed.
This (theoretically) allows new .patch files be added without SoB,
without the GitLab CI catching it.
So add a way to check-package itself ignore current warnings, while
still catching new files that do not follow that new check_function.
Add a file named .checkpackageignore to the buildroot topdir.
It contains the list of check_functions that are expected to fail for
each given intree file tested by check-package.
Each entries is in the format:
<filename> <check_function> [<check_function> ...]
These are 2 examples of possible entries:
package/initscripts/init.d/rcK ConsecutiveEmptyLines EmptyLastLine Shellcheck
utils/test-pkg Shellcheck
Keeping such a list allows us to have fine-grained control over which
warning to ignore.
In order to avoid this list to grow indefinitely, containing entries for
files that are already fixed, make each entry an 'expected to fail'
instead of just an 'ignore', and generate a warning if a check_function
that was expect to fail for a given files does not generate that
warning.
Unfortunately one case that do not generate warning is an entry for a
file that is deleted in a later commit.
By default, all checks are applied. The --ignore-list option allows to
specify a file that contains the list of warnings that should be
ignored.
The paths in the ignore file must be relative to the location of the
ignore file itself, which means:
- in the main Buildroot tree, the paths in the ignore file are
relative to the root of the main Buildroot tree
- in a BR2_EXTERNAL tree, if the ignore file is at the root of the
BR2_EXTERNAL, the paths it contains must be relative to that root
of the BR2_EXTERNAL
This is one more step towards standardizing the use of just 'make
check-package' before submitting patches to the list.
Cc: Sen Hastings <sen@phobosdpl.com>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2022-07-31 21:35:08 +02:00
|
|
|
parser.add_argument("--ignore-list", dest='ignore_filename', action="store",
|
|
|
|
help='override the default list of ignored warnings')
|
2018-04-01 07:08:14 +02:00
|
|
|
|
2017-02-19 23:17:17 +01:00
|
|
|
parser.add_argument("--manual-url", action="store",
|
2024-02-10 22:24:54 +01:00
|
|
|
default="https://nightly.buildroot.org/",
|
2017-02-19 23:17:17 +01:00
|
|
|
help="default: %(default)s")
|
|
|
|
parser.add_argument("--verbose", "-v", action="count", default=0)
|
2019-07-02 20:52:27 +02:00
|
|
|
parser.add_argument("--quiet", "-q", action="count", default=0)
|
2017-02-19 23:17:17 +01:00
|
|
|
|
|
|
|
# Now the debug options in the order they are processed.
|
|
|
|
parser.add_argument("--include-only", dest="include_list", action="append",
|
|
|
|
help="run only the specified functions (debug)")
|
|
|
|
parser.add_argument("--exclude", dest="exclude_list", action="append",
|
|
|
|
help="do not run the specified functions (debug)")
|
|
|
|
parser.add_argument("--dry-run", action="store_true", help="print the "
|
|
|
|
"functions that would be called for each file (debug)")
|
2022-07-31 21:35:10 +02:00
|
|
|
parser.add_argument("--failed-only", action="store_true", help="print only"
|
|
|
|
" the name of the functions that failed (debug)")
|
2017-02-19 23:17:17 +01:00
|
|
|
|
utils/check-package: decouple adding rules from fixing all intree files
When a new check_function is added to check-package, often there are
files in the tree that would generate warnings.
An example is the Sob check_function for patch files:
| $ ./utils/check-package --i Sob $(git ls-files) >/dev/null
| 369301 lines processed
| 46 warnings generated
Currently these warnings are listed when calling check-package directly,
and also at the output of pkg-stats, but the check_function does not run
on 'make check-package' (that is used to catch regressions on GitLab CI
'check-package' job) until all warnings in the tree are fixed.
This (theoretically) allows new .patch files be added without SoB,
without the GitLab CI catching it.
So add a way to check-package itself ignore current warnings, while
still catching new files that do not follow that new check_function.
Add a file named .checkpackageignore to the buildroot topdir.
It contains the list of check_functions that are expected to fail for
each given intree file tested by check-package.
Each entries is in the format:
<filename> <check_function> [<check_function> ...]
These are 2 examples of possible entries:
package/initscripts/init.d/rcK ConsecutiveEmptyLines EmptyLastLine Shellcheck
utils/test-pkg Shellcheck
Keeping such a list allows us to have fine-grained control over which
warning to ignore.
In order to avoid this list to grow indefinitely, containing entries for
files that are already fixed, make each entry an 'expected to fail'
instead of just an 'ignore', and generate a warning if a check_function
that was expect to fail for a given files does not generate that
warning.
Unfortunately one case that do not generate warning is an entry for a
file that is deleted in a later commit.
By default, all checks are applied. The --ignore-list option allows to
specify a file that contains the list of warnings that should be
ignored.
The paths in the ignore file must be relative to the location of the
ignore file itself, which means:
- in the main Buildroot tree, the paths in the ignore file are
relative to the root of the main Buildroot tree
- in a BR2_EXTERNAL tree, if the ignore file is at the root of the
BR2_EXTERNAL, the paths it contains must be relative to that root
of the BR2_EXTERNAL
This is one more step towards standardizing the use of just 'make
check-package' before submitting patches to the list.
Cc: Sen Hastings <sen@phobosdpl.com>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2022-07-31 21:35:08 +02:00
|
|
|
flags = parser.parse_args()
|
|
|
|
|
|
|
|
flags.ignore_list = get_ignored_parsers_per_file(flags.intree_only, flags.ignore_filename)
|
|
|
|
|
2022-07-31 21:35:10 +02:00
|
|
|
if flags.failed_only:
|
|
|
|
flags.dry_run = False
|
|
|
|
flags.verbose = -1
|
|
|
|
|
utils/check-package: decouple adding rules from fixing all intree files
When a new check_function is added to check-package, often there are
files in the tree that would generate warnings.
An example is the Sob check_function for patch files:
| $ ./utils/check-package --i Sob $(git ls-files) >/dev/null
| 369301 lines processed
| 46 warnings generated
Currently these warnings are listed when calling check-package directly,
and also at the output of pkg-stats, but the check_function does not run
on 'make check-package' (that is used to catch regressions on GitLab CI
'check-package' job) until all warnings in the tree are fixed.
This (theoretically) allows new .patch files be added without SoB,
without the GitLab CI catching it.
So add a way to check-package itself ignore current warnings, while
still catching new files that do not follow that new check_function.
Add a file named .checkpackageignore to the buildroot topdir.
It contains the list of check_functions that are expected to fail for
each given intree file tested by check-package.
Each entries is in the format:
<filename> <check_function> [<check_function> ...]
These are 2 examples of possible entries:
package/initscripts/init.d/rcK ConsecutiveEmptyLines EmptyLastLine Shellcheck
utils/test-pkg Shellcheck
Keeping such a list allows us to have fine-grained control over which
warning to ignore.
In order to avoid this list to grow indefinitely, containing entries for
files that are already fixed, make each entry an 'expected to fail'
instead of just an 'ignore', and generate a warning if a check_function
that was expect to fail for a given files does not generate that
warning.
Unfortunately one case that do not generate warning is an entry for a
file that is deleted in a later commit.
By default, all checks are applied. The --ignore-list option allows to
specify a file that contains the list of warnings that should be
ignored.
The paths in the ignore file must be relative to the location of the
ignore file itself, which means:
- in the main Buildroot tree, the paths in the ignore file are
relative to the root of the main Buildroot tree
- in a BR2_EXTERNAL tree, if the ignore file is at the root of the
BR2_EXTERNAL, the paths it contains must be relative to that root
of the BR2_EXTERNAL
This is one more step towards standardizing the use of just 'make
check-package' before submitting patches to the list.
Cc: Sen Hastings <sen@phobosdpl.com>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2022-07-31 21:35:08 +02:00
|
|
|
return flags
|
2017-02-19 23:17:17 +01:00
|
|
|
|
|
|
|
|
2022-07-31 21:35:14 +02:00
|
|
|
def get_lib_from_filetype(fname):
|
|
|
|
if not os.path.isfile(fname):
|
|
|
|
return None
|
|
|
|
filetype = get_filetype(fname)
|
|
|
|
if filetype == "text/x-shellscript":
|
|
|
|
return checkpackagelib.lib_shellscript
|
2022-07-31 21:35:18 +02:00
|
|
|
if filetype in ["text/x-python", "text/x-script.python"]:
|
|
|
|
return checkpackagelib.lib_python
|
2022-07-31 21:35:14 +02:00
|
|
|
return None
|
|
|
|
|
|
|
|
|
2020-08-12 16:28:59 +02:00
|
|
|
CONFIG_IN_FILENAME = re.compile(r"Config\.\S*$")
|
|
|
|
DO_CHECK_INTREE = re.compile(r"|".join([
|
2023-05-06 23:25:31 +02:00
|
|
|
r".checkpackageignore",
|
2020-08-12 16:28:59 +02:00
|
|
|
r"Config.in",
|
|
|
|
r"arch/",
|
2022-07-31 21:35:16 +02:00
|
|
|
r"board/",
|
2020-08-12 16:28:59 +02:00
|
|
|
r"boot/",
|
utils/check-package: new check for Buildroot's defconfig files
Now that we do have support for checking hashes for custom versions
(for the few packages for which we do support custom versions, like the
kernel, some bootloaders...), we want to ensure that our defconfig
files, when they enable one or more such custom version, do enable
checking the hashes for those versions, and thus we want to require all
our defconfigs do enable BR2_DOWNLOAD_FORCE_CHECK_HASHES.
Add a check for that condition.
We need to be careful that we only check Buildroot's defconfig, whether
in-tree or in a br2-external, and not kernel or other kconfig-based
defconfig files, like those in board/ sub-directories. So we only match
defconfig files that are in a configs/ directory, whether at the
toplevel (for in-tree defconfigs), or not (for br2-external defconfigs).
Since we only have two defconfigs that check hashes for custom versions,
regnerate .checkpackageignore to ignore all so-far broken defconfigs.
Suggested-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Cc: Ricardo Martincoski <ricardo.martincoski@datacom.com.br>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2024-03-31 22:34:03 +02:00
|
|
|
r"configs/",
|
2020-08-12 16:28:59 +02:00
|
|
|
r"fs/",
|
|
|
|
r"linux/",
|
|
|
|
r"package/",
|
2022-07-31 21:35:17 +02:00
|
|
|
r"support/",
|
2020-08-12 16:28:59 +02:00
|
|
|
r"system/",
|
|
|
|
r"toolchain/",
|
2022-07-31 21:35:15 +02:00
|
|
|
r"utils/",
|
2018-04-01 07:08:14 +02:00
|
|
|
]))
|
2020-08-12 16:28:59 +02:00
|
|
|
DO_NOT_CHECK_INTREE = re.compile(r"|".join([
|
|
|
|
r"boot/barebox/barebox\.mk$",
|
|
|
|
r"fs/common\.mk$",
|
|
|
|
r"package/doc-asciidoc\.mk$",
|
|
|
|
r"package/pkg-\S*\.mk$",
|
2022-07-31 21:35:17 +02:00
|
|
|
r"support/dependencies/[^/]+\.mk$",
|
|
|
|
r"support/gnuconfig/config\.",
|
|
|
|
r"support/kconfig/",
|
|
|
|
r"support/misc/[^/]+\.mk$",
|
|
|
|
r"support/testing/tests/.*br2-external/",
|
2020-08-12 16:28:59 +02:00
|
|
|
r"toolchain/helpers\.mk$",
|
|
|
|
r"toolchain/toolchain-external/pkg-toolchain-external\.mk$",
|
2018-04-01 07:08:14 +02:00
|
|
|
]))
|
2017-02-19 23:17:17 +01:00
|
|
|
|
2021-12-26 19:49:17 +01:00
|
|
|
SYSV_INIT_SCRIPT_FILENAME = re.compile(r"/S\d\d[^/]+$")
|
|
|
|
|
utils/check-package: new check for Buildroot's defconfig files
Now that we do have support for checking hashes for custom versions
(for the few packages for which we do support custom versions, like the
kernel, some bootloaders...), we want to ensure that our defconfig
files, when they enable one or more such custom version, do enable
checking the hashes for those versions, and thus we want to require all
our defconfigs do enable BR2_DOWNLOAD_FORCE_CHECK_HASHES.
Add a check for that condition.
We need to be careful that we only check Buildroot's defconfig, whether
in-tree or in a br2-external, and not kernel or other kconfig-based
defconfig files, like those in board/ sub-directories. So we only match
defconfig files that are in a configs/ directory, whether at the
toplevel (for in-tree defconfigs), or not (for br2-external defconfigs).
Since we only have two defconfigs that check hashes for custom versions,
regnerate .checkpackageignore to ignore all so-far broken defconfigs.
Suggested-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Cc: Ricardo Martincoski <ricardo.martincoski@datacom.com.br>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2024-03-31 22:34:03 +02:00
|
|
|
# For defconfigs: avoid matching kernel, uboot... defconfig files, so
|
|
|
|
# limit to defconfig files in a configs/ directory, either in-tree or
|
|
|
|
# in a br2-external tree.
|
|
|
|
BR_DEFCONFIG_FILENAME = re.compile(r"^(.+/)?configs/[^/]+_defconfig$")
|
|
|
|
|
2017-02-19 23:17:17 +01:00
|
|
|
|
|
|
|
def get_lib_from_filename(fname):
|
2018-04-01 07:08:14 +02:00
|
|
|
if flags.intree_only:
|
|
|
|
if DO_CHECK_INTREE.match(fname) is None:
|
|
|
|
return None
|
|
|
|
if DO_NOT_CHECK_INTREE.match(fname):
|
|
|
|
return None
|
2018-11-04 05:12:08 +01:00
|
|
|
else:
|
|
|
|
if os.path.basename(fname) == "external.mk" and \
|
|
|
|
os.path.exists(fname[:-2] + "desc"):
|
|
|
|
return None
|
2023-05-06 23:25:31 +02:00
|
|
|
if fname == ".checkpackageignore":
|
|
|
|
return checkpackagelib.lib_ignore
|
2017-02-19 23:17:17 +01:00
|
|
|
if CONFIG_IN_FILENAME.search(fname):
|
2017-04-19 20:06:21 +02:00
|
|
|
return checkpackagelib.lib_config
|
utils/check-package: new check for Buildroot's defconfig files
Now that we do have support for checking hashes for custom versions
(for the few packages for which we do support custom versions, like the
kernel, some bootloaders...), we want to ensure that our defconfig
files, when they enable one or more such custom version, do enable
checking the hashes for those versions, and thus we want to require all
our defconfigs do enable BR2_DOWNLOAD_FORCE_CHECK_HASHES.
Add a check for that condition.
We need to be careful that we only check Buildroot's defconfig, whether
in-tree or in a br2-external, and not kernel or other kconfig-based
defconfig files, like those in board/ sub-directories. So we only match
defconfig files that are in a configs/ directory, whether at the
toplevel (for in-tree defconfigs), or not (for br2-external defconfigs).
Since we only have two defconfigs that check hashes for custom versions,
regnerate .checkpackageignore to ignore all so-far broken defconfigs.
Suggested-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Cc: Ricardo Martincoski <ricardo.martincoski@datacom.com.br>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2024-03-31 22:34:03 +02:00
|
|
|
if BR_DEFCONFIG_FILENAME.search(fname):
|
|
|
|
return checkpackagelib.lib_defconfig
|
2017-02-19 23:17:17 +01:00
|
|
|
if fname.endswith(".hash"):
|
2017-04-19 20:06:21 +02:00
|
|
|
return checkpackagelib.lib_hash
|
2017-02-19 23:17:17 +01:00
|
|
|
if fname.endswith(".mk"):
|
2017-04-19 20:06:21 +02:00
|
|
|
return checkpackagelib.lib_mk
|
2017-02-19 23:17:17 +01:00
|
|
|
if fname.endswith(".patch"):
|
2017-04-19 20:06:21 +02:00
|
|
|
return checkpackagelib.lib_patch
|
2021-12-26 19:49:17 +01:00
|
|
|
if SYSV_INIT_SCRIPT_FILENAME.search(fname):
|
|
|
|
return checkpackagelib.lib_sysv
|
2022-07-31 21:35:14 +02:00
|
|
|
return get_lib_from_filetype(fname)
|
2017-02-19 23:17:17 +01:00
|
|
|
|
|
|
|
|
2021-12-26 19:49:15 +01:00
|
|
|
def common_inspect_rules(m):
|
2017-02-19 23:17:17 +01:00
|
|
|
# do not call the base class
|
|
|
|
if m.__name__.startswith("_"):
|
|
|
|
return False
|
|
|
|
if flags.include_list and m.__name__ not in flags.include_list:
|
|
|
|
return False
|
|
|
|
if flags.exclude_list and m.__name__ in flags.exclude_list:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2021-12-26 19:49:15 +01:00
|
|
|
def is_a_check_function(m):
|
|
|
|
if not inspect.isclass(m):
|
|
|
|
return False
|
|
|
|
if not issubclass(m, checkpackagelib.base._CheckFunction):
|
|
|
|
return False
|
|
|
|
return common_inspect_rules(m)
|
|
|
|
|
|
|
|
|
|
|
|
def is_external_tool(m):
|
|
|
|
if not inspect.isclass(m):
|
|
|
|
return False
|
|
|
|
if not issubclass(m, checkpackagelib.base._Tool):
|
|
|
|
return False
|
|
|
|
return common_inspect_rules(m)
|
|
|
|
|
|
|
|
|
utils/check-package: decouple adding rules from fixing all intree files
When a new check_function is added to check-package, often there are
files in the tree that would generate warnings.
An example is the Sob check_function for patch files:
| $ ./utils/check-package --i Sob $(git ls-files) >/dev/null
| 369301 lines processed
| 46 warnings generated
Currently these warnings are listed when calling check-package directly,
and also at the output of pkg-stats, but the check_function does not run
on 'make check-package' (that is used to catch regressions on GitLab CI
'check-package' job) until all warnings in the tree are fixed.
This (theoretically) allows new .patch files be added without SoB,
without the GitLab CI catching it.
So add a way to check-package itself ignore current warnings, while
still catching new files that do not follow that new check_function.
Add a file named .checkpackageignore to the buildroot topdir.
It contains the list of check_functions that are expected to fail for
each given intree file tested by check-package.
Each entries is in the format:
<filename> <check_function> [<check_function> ...]
These are 2 examples of possible entries:
package/initscripts/init.d/rcK ConsecutiveEmptyLines EmptyLastLine Shellcheck
utils/test-pkg Shellcheck
Keeping such a list allows us to have fine-grained control over which
warning to ignore.
In order to avoid this list to grow indefinitely, containing entries for
files that are already fixed, make each entry an 'expected to fail'
instead of just an 'ignore', and generate a warning if a check_function
that was expect to fail for a given files does not generate that
warning.
Unfortunately one case that do not generate warning is an entry for a
file that is deleted in a later commit.
By default, all checks are applied. The --ignore-list option allows to
specify a file that contains the list of warnings that should be
ignored.
The paths in the ignore file must be relative to the location of the
ignore file itself, which means:
- in the main Buildroot tree, the paths in the ignore file are
relative to the root of the main Buildroot tree
- in a BR2_EXTERNAL tree, if the ignore file is at the root of the
BR2_EXTERNAL, the paths it contains must be relative to that root
of the BR2_EXTERNAL
This is one more step towards standardizing the use of just 'make
check-package' before submitting patches to the list.
Cc: Sen Hastings <sen@phobosdpl.com>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2022-07-31 21:35:08 +02:00
|
|
|
def print_warnings(warnings, xfail):
|
2017-02-19 23:17:17 +01:00
|
|
|
# Avoid the need to use 'return []' at the end of every check function.
|
|
|
|
if warnings is None:
|
utils/check-package: decouple adding rules from fixing all intree files
When a new check_function is added to check-package, often there are
files in the tree that would generate warnings.
An example is the Sob check_function for patch files:
| $ ./utils/check-package --i Sob $(git ls-files) >/dev/null
| 369301 lines processed
| 46 warnings generated
Currently these warnings are listed when calling check-package directly,
and also at the output of pkg-stats, but the check_function does not run
on 'make check-package' (that is used to catch regressions on GitLab CI
'check-package' job) until all warnings in the tree are fixed.
This (theoretically) allows new .patch files be added without SoB,
without the GitLab CI catching it.
So add a way to check-package itself ignore current warnings, while
still catching new files that do not follow that new check_function.
Add a file named .checkpackageignore to the buildroot topdir.
It contains the list of check_functions that are expected to fail for
each given intree file tested by check-package.
Each entries is in the format:
<filename> <check_function> [<check_function> ...]
These are 2 examples of possible entries:
package/initscripts/init.d/rcK ConsecutiveEmptyLines EmptyLastLine Shellcheck
utils/test-pkg Shellcheck
Keeping such a list allows us to have fine-grained control over which
warning to ignore.
In order to avoid this list to grow indefinitely, containing entries for
files that are already fixed, make each entry an 'expected to fail'
instead of just an 'ignore', and generate a warning if a check_function
that was expect to fail for a given files does not generate that
warning.
Unfortunately one case that do not generate warning is an entry for a
file that is deleted in a later commit.
By default, all checks are applied. The --ignore-list option allows to
specify a file that contains the list of warnings that should be
ignored.
The paths in the ignore file must be relative to the location of the
ignore file itself, which means:
- in the main Buildroot tree, the paths in the ignore file are
relative to the root of the main Buildroot tree
- in a BR2_EXTERNAL tree, if the ignore file is at the root of the
BR2_EXTERNAL, the paths it contains must be relative to that root
of the BR2_EXTERNAL
This is one more step towards standardizing the use of just 'make
check-package' before submitting patches to the list.
Cc: Sen Hastings <sen@phobosdpl.com>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2022-07-31 21:35:08 +02:00
|
|
|
return 0, 0 # No warning generated.
|
2017-02-19 23:17:17 +01:00
|
|
|
|
utils/check-package: decouple adding rules from fixing all intree files
When a new check_function is added to check-package, often there are
files in the tree that would generate warnings.
An example is the Sob check_function for patch files:
| $ ./utils/check-package --i Sob $(git ls-files) >/dev/null
| 369301 lines processed
| 46 warnings generated
Currently these warnings are listed when calling check-package directly,
and also at the output of pkg-stats, but the check_function does not run
on 'make check-package' (that is used to catch regressions on GitLab CI
'check-package' job) until all warnings in the tree are fixed.
This (theoretically) allows new .patch files be added without SoB,
without the GitLab CI catching it.
So add a way to check-package itself ignore current warnings, while
still catching new files that do not follow that new check_function.
Add a file named .checkpackageignore to the buildroot topdir.
It contains the list of check_functions that are expected to fail for
each given intree file tested by check-package.
Each entries is in the format:
<filename> <check_function> [<check_function> ...]
These are 2 examples of possible entries:
package/initscripts/init.d/rcK ConsecutiveEmptyLines EmptyLastLine Shellcheck
utils/test-pkg Shellcheck
Keeping such a list allows us to have fine-grained control over which
warning to ignore.
In order to avoid this list to grow indefinitely, containing entries for
files that are already fixed, make each entry an 'expected to fail'
instead of just an 'ignore', and generate a warning if a check_function
that was expect to fail for a given files does not generate that
warning.
Unfortunately one case that do not generate warning is an entry for a
file that is deleted in a later commit.
By default, all checks are applied. The --ignore-list option allows to
specify a file that contains the list of warnings that should be
ignored.
The paths in the ignore file must be relative to the location of the
ignore file itself, which means:
- in the main Buildroot tree, the paths in the ignore file are
relative to the root of the main Buildroot tree
- in a BR2_EXTERNAL tree, if the ignore file is at the root of the
BR2_EXTERNAL, the paths it contains must be relative to that root
of the BR2_EXTERNAL
This is one more step towards standardizing the use of just 'make
check-package' before submitting patches to the list.
Cc: Sen Hastings <sen@phobosdpl.com>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2022-07-31 21:35:08 +02:00
|
|
|
if xfail:
|
|
|
|
return 0, 1 # Warning not generated, fail expected for this file.
|
2017-02-19 23:17:17 +01:00
|
|
|
for level, message in enumerate(warnings):
|
|
|
|
if flags.verbose >= level:
|
|
|
|
print(message.replace("\t", "< tab >").rstrip())
|
utils/check-package: decouple adding rules from fixing all intree files
When a new check_function is added to check-package, often there are
files in the tree that would generate warnings.
An example is the Sob check_function for patch files:
| $ ./utils/check-package --i Sob $(git ls-files) >/dev/null
| 369301 lines processed
| 46 warnings generated
Currently these warnings are listed when calling check-package directly,
and also at the output of pkg-stats, but the check_function does not run
on 'make check-package' (that is used to catch regressions on GitLab CI
'check-package' job) until all warnings in the tree are fixed.
This (theoretically) allows new .patch files be added without SoB,
without the GitLab CI catching it.
So add a way to check-package itself ignore current warnings, while
still catching new files that do not follow that new check_function.
Add a file named .checkpackageignore to the buildroot topdir.
It contains the list of check_functions that are expected to fail for
each given intree file tested by check-package.
Each entries is in the format:
<filename> <check_function> [<check_function> ...]
These are 2 examples of possible entries:
package/initscripts/init.d/rcK ConsecutiveEmptyLines EmptyLastLine Shellcheck
utils/test-pkg Shellcheck
Keeping such a list allows us to have fine-grained control over which
warning to ignore.
In order to avoid this list to grow indefinitely, containing entries for
files that are already fixed, make each entry an 'expected to fail'
instead of just an 'ignore', and generate a warning if a check_function
that was expect to fail for a given files does not generate that
warning.
Unfortunately one case that do not generate warning is an entry for a
file that is deleted in a later commit.
By default, all checks are applied. The --ignore-list option allows to
specify a file that contains the list of warnings that should be
ignored.
The paths in the ignore file must be relative to the location of the
ignore file itself, which means:
- in the main Buildroot tree, the paths in the ignore file are
relative to the root of the main Buildroot tree
- in a BR2_EXTERNAL tree, if the ignore file is at the root of the
BR2_EXTERNAL, the paths it contains must be relative to that root
of the BR2_EXTERNAL
This is one more step towards standardizing the use of just 'make
check-package' before submitting patches to the list.
Cc: Sen Hastings <sen@phobosdpl.com>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2022-07-31 21:35:08 +02:00
|
|
|
return 1, 1 # One more warning to count.
|
2017-02-19 23:17:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
def check_file_using_lib(fname):
|
|
|
|
# Count number of warnings generated and lines processed.
|
|
|
|
nwarnings = 0
|
|
|
|
nlines = 0
|
utils/check-package: decouple adding rules from fixing all intree files
When a new check_function is added to check-package, often there are
files in the tree that would generate warnings.
An example is the Sob check_function for patch files:
| $ ./utils/check-package --i Sob $(git ls-files) >/dev/null
| 369301 lines processed
| 46 warnings generated
Currently these warnings are listed when calling check-package directly,
and also at the output of pkg-stats, but the check_function does not run
on 'make check-package' (that is used to catch regressions on GitLab CI
'check-package' job) until all warnings in the tree are fixed.
This (theoretically) allows new .patch files be added without SoB,
without the GitLab CI catching it.
So add a way to check-package itself ignore current warnings, while
still catching new files that do not follow that new check_function.
Add a file named .checkpackageignore to the buildroot topdir.
It contains the list of check_functions that are expected to fail for
each given intree file tested by check-package.
Each entries is in the format:
<filename> <check_function> [<check_function> ...]
These are 2 examples of possible entries:
package/initscripts/init.d/rcK ConsecutiveEmptyLines EmptyLastLine Shellcheck
utils/test-pkg Shellcheck
Keeping such a list allows us to have fine-grained control over which
warning to ignore.
In order to avoid this list to grow indefinitely, containing entries for
files that are already fixed, make each entry an 'expected to fail'
instead of just an 'ignore', and generate a warning if a check_function
that was expect to fail for a given files does not generate that
warning.
Unfortunately one case that do not generate warning is an entry for a
file that is deleted in a later commit.
By default, all checks are applied. The --ignore-list option allows to
specify a file that contains the list of warnings that should be
ignored.
The paths in the ignore file must be relative to the location of the
ignore file itself, which means:
- in the main Buildroot tree, the paths in the ignore file are
relative to the root of the main Buildroot tree
- in a BR2_EXTERNAL tree, if the ignore file is at the root of the
BR2_EXTERNAL, the paths it contains must be relative to that root
of the BR2_EXTERNAL
This is one more step towards standardizing the use of just 'make
check-package' before submitting patches to the list.
Cc: Sen Hastings <sen@phobosdpl.com>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2022-07-31 21:35:08 +02:00
|
|
|
xfail = flags.ignore_list.get(os.path.abspath(fname), [])
|
|
|
|
failed = set()
|
2017-02-19 23:17:17 +01:00
|
|
|
|
|
|
|
lib = get_lib_from_filename(fname)
|
|
|
|
if not lib:
|
|
|
|
if flags.verbose >= VERBOSE_LEVEL_TO_SHOW_IGNORED_FILES:
|
|
|
|
print("{}: ignored".format(fname))
|
|
|
|
return nwarnings, nlines
|
2021-12-26 19:49:15 +01:00
|
|
|
internal_functions = inspect.getmembers(lib, is_a_check_function)
|
|
|
|
external_tools = inspect.getmembers(lib, is_external_tool)
|
|
|
|
all_checks = internal_functions + external_tools
|
2017-02-19 23:17:17 +01:00
|
|
|
|
|
|
|
if flags.dry_run:
|
2021-12-26 19:49:15 +01:00
|
|
|
functions_to_run = [c[0] for c in all_checks]
|
2017-02-19 23:17:17 +01:00
|
|
|
print("{}: would run: {}".format(fname, functions_to_run))
|
|
|
|
return nwarnings, nlines
|
|
|
|
|
utils/check-package: emit library name along with check function name
Currently, when we generate .checkpackageignore, we store, for each
error, only the name of the function that generated that error.
Although we currently do not have two check libs that have same-name
check functions, there is nothing that would prevent that, and there
is no reason why two unrelated libs could not implement checks with
the same name.
If such a situation were to arise, we'd have no way, when parsing the
ignore list (in-tree: .checkpackageignore), to know which of the libs
the exclusion would apply to.
Fix that by storing both the library and function names together. The
leading "checkpackagelib." (with the trailing dot, 16 chars) is removed
for brevity, because it's present in all libs' names.
As a consequence, regenerate .checkpackageignore.
Note: people using that script to validate their br2-external trees will
also have to regenerate their own exclusion list if they have one.
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Cc: Ricardo Martincoski <ricardo.martincoski@datacom.com.br>
Reviewed-by: Arnout Vandecappelle <arnout@mind.be>
2024-03-31 19:26:06 +02:00
|
|
|
objects = [[f"{lib.__name__[16:]}.{c[0]}", c[1](fname, flags.manual_url)] for c in internal_functions]
|
2017-02-19 23:17:17 +01:00
|
|
|
|
utils/check-package: decouple adding rules from fixing all intree files
When a new check_function is added to check-package, often there are
files in the tree that would generate warnings.
An example is the Sob check_function for patch files:
| $ ./utils/check-package --i Sob $(git ls-files) >/dev/null
| 369301 lines processed
| 46 warnings generated
Currently these warnings are listed when calling check-package directly,
and also at the output of pkg-stats, but the check_function does not run
on 'make check-package' (that is used to catch regressions on GitLab CI
'check-package' job) until all warnings in the tree are fixed.
This (theoretically) allows new .patch files be added without SoB,
without the GitLab CI catching it.
So add a way to check-package itself ignore current warnings, while
still catching new files that do not follow that new check_function.
Add a file named .checkpackageignore to the buildroot topdir.
It contains the list of check_functions that are expected to fail for
each given intree file tested by check-package.
Each entries is in the format:
<filename> <check_function> [<check_function> ...]
These are 2 examples of possible entries:
package/initscripts/init.d/rcK ConsecutiveEmptyLines EmptyLastLine Shellcheck
utils/test-pkg Shellcheck
Keeping such a list allows us to have fine-grained control over which
warning to ignore.
In order to avoid this list to grow indefinitely, containing entries for
files that are already fixed, make each entry an 'expected to fail'
instead of just an 'ignore', and generate a warning if a check_function
that was expect to fail for a given files does not generate that
warning.
Unfortunately one case that do not generate warning is an entry for a
file that is deleted in a later commit.
By default, all checks are applied. The --ignore-list option allows to
specify a file that contains the list of warnings that should be
ignored.
The paths in the ignore file must be relative to the location of the
ignore file itself, which means:
- in the main Buildroot tree, the paths in the ignore file are
relative to the root of the main Buildroot tree
- in a BR2_EXTERNAL tree, if the ignore file is at the root of the
BR2_EXTERNAL, the paths it contains must be relative to that root
of the BR2_EXTERNAL
This is one more step towards standardizing the use of just 'make
check-package' before submitting patches to the list.
Cc: Sen Hastings <sen@phobosdpl.com>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2022-07-31 21:35:08 +02:00
|
|
|
for name, cf in objects:
|
|
|
|
warn, fail = print_warnings(cf.before(), name in xfail)
|
|
|
|
if fail > 0:
|
|
|
|
failed.add(name)
|
|
|
|
nwarnings += warn
|
2023-04-03 03:35:30 +02:00
|
|
|
|
2019-01-27 19:59:41 +01:00
|
|
|
lastline = ""
|
2023-09-02 14:47:49 +02:00
|
|
|
with open(fname, "r", errors="surrogateescape") as f:
|
|
|
|
for lineno, text in enumerate(f):
|
|
|
|
nlines += 1
|
|
|
|
for name, cf in objects:
|
|
|
|
if cf.disable.search(lastline):
|
|
|
|
continue
|
|
|
|
line_sts = cf.check_line(lineno + 1, text)
|
|
|
|
warn, fail = print_warnings(line_sts, name in xfail)
|
|
|
|
if fail > 0:
|
|
|
|
failed.add(name)
|
|
|
|
nwarnings += warn
|
|
|
|
lastline = text
|
2023-04-03 03:35:30 +02:00
|
|
|
|
utils/check-package: decouple adding rules from fixing all intree files
When a new check_function is added to check-package, often there are
files in the tree that would generate warnings.
An example is the Sob check_function for patch files:
| $ ./utils/check-package --i Sob $(git ls-files) >/dev/null
| 369301 lines processed
| 46 warnings generated
Currently these warnings are listed when calling check-package directly,
and also at the output of pkg-stats, but the check_function does not run
on 'make check-package' (that is used to catch regressions on GitLab CI
'check-package' job) until all warnings in the tree are fixed.
This (theoretically) allows new .patch files be added without SoB,
without the GitLab CI catching it.
So add a way to check-package itself ignore current warnings, while
still catching new files that do not follow that new check_function.
Add a file named .checkpackageignore to the buildroot topdir.
It contains the list of check_functions that are expected to fail for
each given intree file tested by check-package.
Each entries is in the format:
<filename> <check_function> [<check_function> ...]
These are 2 examples of possible entries:
package/initscripts/init.d/rcK ConsecutiveEmptyLines EmptyLastLine Shellcheck
utils/test-pkg Shellcheck
Keeping such a list allows us to have fine-grained control over which
warning to ignore.
In order to avoid this list to grow indefinitely, containing entries for
files that are already fixed, make each entry an 'expected to fail'
instead of just an 'ignore', and generate a warning if a check_function
that was expect to fail for a given files does not generate that
warning.
Unfortunately one case that do not generate warning is an entry for a
file that is deleted in a later commit.
By default, all checks are applied. The --ignore-list option allows to
specify a file that contains the list of warnings that should be
ignored.
The paths in the ignore file must be relative to the location of the
ignore file itself, which means:
- in the main Buildroot tree, the paths in the ignore file are
relative to the root of the main Buildroot tree
- in a BR2_EXTERNAL tree, if the ignore file is at the root of the
BR2_EXTERNAL, the paths it contains must be relative to that root
of the BR2_EXTERNAL
This is one more step towards standardizing the use of just 'make
check-package' before submitting patches to the list.
Cc: Sen Hastings <sen@phobosdpl.com>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2022-07-31 21:35:08 +02:00
|
|
|
for name, cf in objects:
|
|
|
|
warn, fail = print_warnings(cf.after(), name in xfail)
|
|
|
|
if fail > 0:
|
|
|
|
failed.add(name)
|
|
|
|
nwarnings += warn
|
|
|
|
|
|
|
|
tools = [[c[0], c[1](fname)] for c in external_tools]
|
|
|
|
|
|
|
|
for name, tool in tools:
|
|
|
|
warn, fail = print_warnings(tool.run(), name in xfail)
|
|
|
|
if fail > 0:
|
|
|
|
failed.add(name)
|
|
|
|
nwarnings += warn
|
|
|
|
|
|
|
|
for should_fail in xfail:
|
|
|
|
if should_fail not in failed:
|
2023-04-23 21:47:51 +02:00
|
|
|
print("{}:0: {} was expected to fail, did you fix the file and forget to update {}?"
|
utils/check-package: decouple adding rules from fixing all intree files
When a new check_function is added to check-package, often there are
files in the tree that would generate warnings.
An example is the Sob check_function for patch files:
| $ ./utils/check-package --i Sob $(git ls-files) >/dev/null
| 369301 lines processed
| 46 warnings generated
Currently these warnings are listed when calling check-package directly,
and also at the output of pkg-stats, but the check_function does not run
on 'make check-package' (that is used to catch regressions on GitLab CI
'check-package' job) until all warnings in the tree are fixed.
This (theoretically) allows new .patch files be added without SoB,
without the GitLab CI catching it.
So add a way to check-package itself ignore current warnings, while
still catching new files that do not follow that new check_function.
Add a file named .checkpackageignore to the buildroot topdir.
It contains the list of check_functions that are expected to fail for
each given intree file tested by check-package.
Each entries is in the format:
<filename> <check_function> [<check_function> ...]
These are 2 examples of possible entries:
package/initscripts/init.d/rcK ConsecutiveEmptyLines EmptyLastLine Shellcheck
utils/test-pkg Shellcheck
Keeping such a list allows us to have fine-grained control over which
warning to ignore.
In order to avoid this list to grow indefinitely, containing entries for
files that are already fixed, make each entry an 'expected to fail'
instead of just an 'ignore', and generate a warning if a check_function
that was expect to fail for a given files does not generate that
warning.
Unfortunately one case that do not generate warning is an entry for a
file that is deleted in a later commit.
By default, all checks are applied. The --ignore-list option allows to
specify a file that contains the list of warnings that should be
ignored.
The paths in the ignore file must be relative to the location of the
ignore file itself, which means:
- in the main Buildroot tree, the paths in the ignore file are
relative to the root of the main Buildroot tree
- in a BR2_EXTERNAL tree, if the ignore file is at the root of the
BR2_EXTERNAL, the paths it contains must be relative to that root
of the BR2_EXTERNAL
This is one more step towards standardizing the use of just 'make
check-package' before submitting patches to the list.
Cc: Sen Hastings <sen@phobosdpl.com>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2022-07-31 21:35:08 +02:00
|
|
|
.format(fname, should_fail, flags.ignore_filename))
|
|
|
|
nwarnings += 1
|
2021-12-26 19:49:15 +01:00
|
|
|
|
2022-07-31 21:35:10 +02:00
|
|
|
if flags.failed_only:
|
|
|
|
if len(failed) > 0:
|
|
|
|
f = " ".join(sorted(failed))
|
|
|
|
print("{} {}".format(fname, f))
|
|
|
|
|
2017-02-19 23:17:17 +01:00
|
|
|
return nwarnings, nlines
|
|
|
|
|
|
|
|
|
|
|
|
def __main__():
|
|
|
|
global flags
|
|
|
|
flags = parse_args()
|
|
|
|
|
2018-04-01 07:08:14 +02:00
|
|
|
if flags.intree_only:
|
|
|
|
# change all paths received to be relative to the base dir
|
2018-04-01 22:05:16 +02:00
|
|
|
base_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
2018-04-01 07:08:14 +02:00
|
|
|
files_to_check = [os.path.relpath(os.path.abspath(f), base_dir) for f in flags.files]
|
|
|
|
# move current dir so the script find the files
|
|
|
|
os.chdir(base_dir)
|
|
|
|
else:
|
|
|
|
files_to_check = flags.files
|
|
|
|
|
|
|
|
if len(files_to_check) == 0:
|
2017-02-19 23:17:17 +01:00
|
|
|
print("No files to check style")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# Accumulate number of warnings generated and lines processed.
|
|
|
|
total_warnings = 0
|
|
|
|
total_lines = 0
|
|
|
|
|
2018-04-01 07:08:14 +02:00
|
|
|
for fname in files_to_check:
|
2017-02-19 23:17:17 +01:00
|
|
|
nwarnings, nlines = check_file_using_lib(fname)
|
|
|
|
total_warnings += nwarnings
|
|
|
|
total_lines += nlines
|
|
|
|
|
|
|
|
# The warning messages are printed to stdout and can be post-processed
|
|
|
|
# (e.g. counted by 'wc'), so for stats use stderr. Wait all warnings are
|
|
|
|
# printed, for the case there are many of them, before printing stats.
|
|
|
|
sys.stdout.flush()
|
2019-07-02 20:52:27 +02:00
|
|
|
|
|
|
|
if not flags.quiet:
|
|
|
|
print("{} lines processed".format(total_lines), file=sys.stderr)
|
|
|
|
print("{} warnings generated".format(total_warnings), file=sys.stderr)
|
2017-02-19 23:17:17 +01:00
|
|
|
|
2022-07-31 21:35:10 +02:00
|
|
|
if total_warnings > 0 and not flags.failed_only:
|
2017-02-19 23:17:17 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
__main__()
|