Add support for treating compiler warnings as errors
cover Add support for treating compiler warnings as errors
To enforce a zero-warnings policy (e.g. in CI builds), all compiler warnings have to be treated as errors.
Extend Kbuild and buildman with according options to achieve this. Enable these new options in all Travis CI builds. All builds with compiler warnings will now fail. Only DTC warnings are still being ignored.
Example build which failed due to a compiler warning:
https://travis-ci.org/danielschwierzeck/u-boot/jobs/333349371#L936
Daniel Schwierzeck (4):
Kbuild: support W=[N,]err for passing '-Werror' to the compiler
buildman: add option -E for treating compiler warnings as errors travis.yml: fix 'set +e' in build script
travis.yml: run buildman with option -E
.travis.yml | 5 ++--- scripts/Makefile.extrawarn | 3 +++ tools/buildman/builder.py | 5 ++++- tools/buildman/builderthread.py | 2 ++ tools/buildman/cmdline.py | 2 ++ tools/buildman/control.py | 3 ++- 6 files changed, 15 insertions(+), 5 deletions(-)
Signature · 1 line
2.16.1
PATCH 1/4 Kbuild: support W=[N, ]err for passing '-Werror' to the compiler
Extend the Kbuild's W=N option with an optional 'err' value. This will pass -Werror to the compiler to treat all warnings as errors. This is useful to enforce a zero-warnings policy.
The 'err' value can also be combined with the numerical values like this:
make W=1
make W=err
make W=1,err
---
scripts/Makefile.extrawarn | 3 +++ 1 file changed, 3 insertions(+)
scripts/Makefile.extrawarn +3 -0
@@ -48,9 +48,12 @@ warning-3 += -Wswitch-default warning-3 += $(call cc-option, -Wpacked-bitfield-compat) warning-3 += $(call cc-option, -Wvla) +warning-err := -Werror + warning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) warning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) warning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) +warning += $(warning-$(findstring err, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) ifeq ("$(strip $(warning))","") $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown)
Signature · 1 line
2.16.1
PATCH 1/4 Kbuild: support W=[N, ]err for passing '-Werror' to the compiler
Hi Daniel,
2018-01-26 2:21 GMT+09:00 Daniel Schwierzeck <[email protected]>:
Quoted 35 lines
Extend the Kbuild's W=N option with an optional 'err' value. This will pass -Werror to the compiler to treat all warnings as errors. This is useful to enforce a zero-warnings policy.
The 'err' value can also be combined with the numerical values like this:
make W=1
make W=err
make W=1,errSigned-off-by Daniel Schwierzeck <[email protected]>---
scripts/Makefile.extrawarn | 3 +++ 1 file changed, 3 insertions(+)scripts/Makefile.extrawarn +3
-1@@ -48,9 +48,12 @@ warning-3 += -Wswitch-default warning-3 += $(call cc-option, -Wpacked-bitfield-compat) warning-3 += $(call cc-option, -Wvla) +warning-err := -Werror + warning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) warning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) warning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) +warning += $(warning-$(findstring err, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) ifeq ("$(strip $(warning))","") $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown) --
Quoted 1 line
2.16.1
I saw a similar patch before in linux-kbuild ML.
Kbuild provides a way to specify user-specific options. See the following lines in the top-level Makefile:
# Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments KBUILD_CPPFLAGS += $(KCPPFLAGS) KBUILD_AFLAGS += $(KAFLAGS) KBUILD_CFLAGS += $(KCFLAGS)
"make W=err" is a shorthand of "make KCFLAGS=-Werror", right?
I tend to hesitate to add another way
to do the same thing...
Signature · 2 lines
Best Regards Masahiro Yamada
PATCH 1/4 Kbuild: support W=[N, ]err for passing '-Werror' to the compiler
Hi Masahiro,
Quoted 56 lines · Masahiro Yamada
Hi Daniel,
2018-01-26 2:21 GMT+09:00 Daniel Schwierzeck <[email protected]>:
Quoted 35 lines
Extend the Kbuild's W=N option with an optional 'err' value. This will pass -Werror to the compiler to treat all warnings as errors. This is useful to enforce a zero-warnings policy.
The 'err' value can also be combined with the numerical values like this:
make W=1
make W=err
make W=1,errSigned-off-by Daniel Schwierzeck <[email protected]>---
scripts/Makefile.extrawarn | 3 +++ 1 file changed, 3 insertions(+)scripts/Makefile.extrawarn +3
-1@@ -48,9 +48,12 @@ warning-3 += -Wswitch-default warning-3 += $(call cc-option, -Wpacked-bitfield-compat) warning-3 += $(call cc-option, -Wvla) +warning-err := -Werror + warning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) warning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) warning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) +warning += $(warning-$(findstring err, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) ifeq ("$(strip $(warning))","") $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown) --Quoted 1 line
2.16.1
I saw a similar patch before in linux-kbuild ML.
Kbuildprovides a way to specify user-specific options. See the following lines in the top-levelMakefile:# Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments KBUILD_CPPFLAGS += $(KCPPFLAGS) KBUILD_AFLAGS += $(KAFLAGS) KBUILD_CFLAGS += $(KCFLAGS)
Quoted 5 lines
"make W=err" is a shorthand of "make KCFLAGS=-Werror", right?
I tend to hesitate to add another way
to do the same thing...
I didn't noticed that possibility, thanks for the pointer. I'll withdraw this patch and add a short pointer in the README instead.
Signature · 9 lines
- Daniel -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: OpenPGP digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180126/b4535051/attachment.sig>
PATCH 2/4 buildman: add option -E for treating compiler warnings as errors
In reply to Daniel SchwierzeckAdd a new option '-E' for treating all compiler warnings as errors. Eventually this will pass 'W=err' to Kbuild.
---
tools/buildman/builder.py | 5 ++++- tools/buildman/builderthread.py | 2 ++ tools/buildman/cmdline.py | 2 ++ tools/buildman/control.py | 3 ++- 4 files changed, 10 insertions(+), 2 deletions(-)
tools/buildman/builder.py +4 -1
@@ -212,7 +212,8 @@ class Builder: gnu_make='make', checkout=True, show_unknown=True, step=1, no_subdirs=False, full_path=False, verbose_build=False, incremental=False, per_board_out_dir=False, - config_only=False, squash_config_y=False): + config_only=False, squash_config_y=False, + warnings_as_errors=False): """Create a new Builder object Args:
@@ -237,6 +238,7 @@ class Builder: board rather than a thread-specific directory config_only: Only configure each build, don't build it squash_config_y: Convert CONFIG options with the value 'y' to '1' + warnings_as_errors: Treat all compiler warnings as errors """ self.toolchains = toolchains self.base_dir = base_dir
@@ -270,6 +272,7 @@ class Builder: if not self.squash_config_y: self.config_filenames += EXTRA_CONFIG_FILENAMES + self.warnings_as_errors = warnings_as_errors self.col = terminal.Color() self._re_function = re.compile('(.*): In function.*')
tools/buildman/builderthread.py +2 -0
@@ -216,6 +216,8 @@ class BuilderThread(threading.Thread): args.append('-s') if self.builder.num_jobs is not None: args.extend(['-j', str(self.builder.num_jobs)]) + if self.builder.warnings_as_errors: + args.append('W=err') config_args = ['%s_defconfig' % brd.target] config_out = '' args.extend(self.builder.toolchains.GetMakeArguments(brd))
tools/buildman/cmdline.py +2 -0
@@ -32,6 +32,8 @@ def ParseArgs(): help="Don't build, just configure each commit") parser.add_option('-e', '--show_errors', action='store_true', default=False, help='Show errors and warnings') + parser.add_option('-E', '--warnings-as-errors', action='store_true', + default=False, help='Treat all compiler warnings as errors') parser.add_option('-f', '--force-build', dest='force_build', action='store_true', default=False, help='Force build of boards even if already built')
tools/buildman/control.py +2 -1
@@ -263,7 +263,8 @@ def DoBuildman(options, args, toolchains=None, make_func=None, boards=None, incremental=options.incremental, per_board_out_dir=options.per_board_out_dir, config_only=options.config_only, - squash_config_y=not options.preserve_config_y) + squash_config_y=not options.preserve_config_y, + warnings_as_errors=options.warnings_as_errors) builder.force_config_on_failure = not options.quick if make_func: builder.do_make = make_func
Signature · 1 line
2.16.1
PATCH 2/4 buildman: add option -E for treating compiler warnings as errors
`On 25 January 2018 at 10:21, Daniel Schwierzeck
Quoted 2 lines · <[email protected]> wrote:
Add a new option '-E' for treating all compiler warnings as errors. Eventually this will pass 'W=err' to
Kbuild.
nit: I read 'eventually' as 'in a future patch'
How about 'This will cause buildman to pass ...' ?
Quoted 10 lines
Signed-off-by Daniel Schwierzeck <[email protected]>---
tools/buildman/builder.py | 5 ++++- tools/buildman/builderthread.py | 2 ++ tools/buildman/cmdline.py | 2 ++ tools/buildman/control.py | 3 ++- 4 files changed, 10 insertions(+), 2 deletions(-)
PATCH 3/4 travis.yml: fix 'set +e' in build script
In reply to Daniel SchwierzeckThe build script should not manipulate shell flags (especially '-e'). A non-zero exit value can also be catched with 'cmd || ret=$?'.
---
.travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
.travis.yml +2 -3
@@ -101,9 +101,8 @@ script: # # Exit code 129 means warnings only. - if [[ "${BUILDMAN}" != "" ]]; then - set +e; - tools/buildman/buildman -P ${BUILDMAN}; - ret=$?; + ret=0; + tools/buildman/buildman -P ${BUILDMAN} || ret=$?; if [[ $ret -ne 0 && $ret -ne 129 ]]; then tools/buildman/buildman -sdeP ${BUILDMAN}; exit $ret;
Signature · 1 line
2.16.1
PATCH 3/4 travis.yml: fix 'set +e' in build script
Quoted 8 lines · Daniel Schwierzeck
The build script should not manipulate shell flags (especially '-e'). A non-zero exit value can also be catched with 'cmd || ret=$?'.
Signed-off-by Daniel Schwierzeck <[email protected]>---
.travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
PATCH 4/4 travis.yml: run buildman with option -E
In reply to Daniel SchwierzeckThis forces all compiler warnings to be treated as errors.
---
.travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
.travis.yml +1 -1
@@ -102,7 +102,7 @@ script: # Exit code 129 means warnings only. - if [[ "${BUILDMAN}" != "" ]]; then ret=0; - tools/buildman/buildman -P ${BUILDMAN} || ret=$?; + tools/buildman/buildman -P -E ${BUILDMAN} || ret=$?; if [[ $ret -ne 0 && $ret -ne 129 ]]; then tools/buildman/buildman -sdeP ${BUILDMAN}; exit $ret;
Signature · 1 line
2.16.1
PATCH 4/4 travis.yml: run buildman with option -E
Quoted 8 lines · Daniel Schwierzeck
This forces all compiler warnings to be treated as errors.
Signed-off-by Daniel Schwierzeck <[email protected]>---
.travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
But just checking that this actually passes at present?