Skip to contentSkip to conversation

Add support for treating compiler warnings as errors

PATCH New Daniel Schwierzeck 2 participants 10 messages Jan 26, 2018 – Feb 5, 2018

lore
Share & tools
lore
#0 lore raw

v2 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

The patch which fixes the warning above:
https://patchwork.ozlabs.org/patch/866009/

Changes in v2:
- new patch
- replace 'W=err' with 'KCFLAGS=-Werror'

Daniel Schwierzeck (4):
README: add doc for how to supply user specific compiler flags to
Kbuild
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 ++---
 README                          | 5 +++++
 tools/buildman/builder.py       | 5 ++++-
 tools/buildman/builderthread.py | 2 ++
 tools/buildman/cmdline.py       | 2 ++
 tools/buildman/control.py       | 3 ++-
 6 files changed, 17 insertions(+), 5 deletions(-)
Signature · 1 line
2.16.1
#1 lore raw

PATCH v2 1/4 README: add doc for how to supply user specific compiler flags to Kbuild

Probably not all users are aware of this possibility, thus add a pointer to the README. Also add a useful example.

---

Changes in v2:
- new patch

 README | 5 +++++
 1 file changed, 5 insertions(+)
README +5 -0
index b53ea7dfe3..b055ae7ef2 100644
@@ -3719,6 +3719,11 @@ this behavior and build U-Boot to some external directory:
 Note that the command line "O=" setting overrides the KBUILD_OUTPUT environment
 variable.
 
+User specific CPPFLAGS, AFLAGS and CFLAGS can be passed to the compiler by
+setting the according environment variables KCPPFLAGS, KAFLAGS and KCFLAGS.
+For example to treat all compiler warnings as errors:
+
+	make KCFLAGS=-Werror
 
 Please be aware that the Makefiles assume you are using GNU make, so
 for instance on NetBSD you might need to use "gmake" instead of
Signature · 1 line
2.16.1
#2 lore raw

PATCH v2 1/4 README: add doc for how to supply user specific compiler flags to Kbuild

Quoted 4 lines · Daniel Schwierzeck

Probably not all users are aware of this possibility, thus add a pointer to the README. Also add a useful example.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180205/01f952b0/attachment.sig>
#3 lore raw

PATCH v2 2/4 buildman: add option -E for treating compiler warnings as errors

In reply to Daniel Schwierzeck

Add a new option '-E' for treating all compiler warnings as errors. Eventually this will pass 'KCFLAGS=-Werror' to Kbuild.

---

Changes in v2:
- replace 'W=err' with 'KCFLAGS=-Werror'

 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
index acb0810457..4e72b7d60d 100644
@@ -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
index 9e8ca80c5b..9ac101a5a4 100644
@@ -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('KCFLAGS=-Werror')
                 config_args = ['%s_defconfig' % brd.target]
                 config_out = ''
                 args.extend(self.builder.toolchains.GetMakeArguments(brd))
tools/buildman/cmdline.py +2 -0
index 74247f0aff..6949d6bf2c 100644
@@ -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
index 73b1a14fb6..3cac9f7cf6 100644
@@ -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
#4 lore raw

PATCH v2 2/4 buildman: add option -E for treating compiler warnings as errors

Quoted 4 lines · Daniel Schwierzeck

Add a new option '-E' for treating all compiler warnings as errors. Eventually this will pass 'KCFLAGS=-Werror' to Kbuild.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180205/405f2da5/attachment.sig>
#5 lore raw

PATCH v2 3/4 travis.yml: fix 'set +e' in build script

In reply to Daniel Schwierzeck

The build script should not manipulate shell flags (especially '-e'). A non-zero exit value can also be catched with 'cmd || ret=$?'.

---

Changes in v2: None

 .travis.yml | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
.travis.yml +2 -3
index 2a98c4bb11..1e55e1b7f1 100644
@@ -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
#6 lore raw

PATCH v2 3/4 travis.yml: fix 'set +e' in build script

Quoted 4 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=$?'.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180126/f79f4873/attachment.sig>
#7 lore raw

PATCH v2 3/4 travis.yml: fix 'set +e' in build script

In reply to Daniel Schwierzeck
Quoted 5 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=$?'.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180205/8cc99f42/attachment.sig>
#8 lore raw

PATCH v2 4/4 travis.yml: run buildman with option -E

In reply to Daniel Schwierzeck

This forces all compiler warnings to be treated as errors.

---

Changes in v2: None

 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
.travis.yml +1 -1
index 1e55e1b7f1..59d1dd99e8 100644
@@ -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
#9 lore raw

PATCH v2 4/4 travis.yml: run buildman with option -E

Quoted 3 lines · Daniel Schwierzeck

This forces all compiler warnings to be treated as errors.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180205/d259f4c4/attachment.sig>