^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #! /usr/bin/env python
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # -*- coding: utf-8 -*-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) # Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) # Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) # modification, are permitted provided that the following conditions are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) # * Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) # notice, this list of conditions and the following disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) # * Redistributions in binary form must reproduce the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) # notice, this list of conditions and the following disclaimer in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) # documentation and/or other materials provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) # * Neither the name of The Linux Foundation nor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) # the names of its contributors may be used to endorse or promote
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) # products derived from this software without specific prior written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) # permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) # IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) # NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) # Invoke clang, looking for warnings, and causing a failure if there are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) # non-whitelisted warnings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) from __future__ import print_function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) import errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) import re
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) import os
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) import sys
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) import subprocess
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) allowed_warnings = set([
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) "tcpci.h:195", # drivers/usb/typec/tcpm/tcpci.h:195:12: warning: 'enum typec_cc_status' declared inside parameter list will not be visible outside of this definition or declaration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) "atags_to_fdt.c:129", # arch/arm/boot/compressed/atags_to_fdt.c:129:5: warning: stack frame size of 2368 bytes in function 'atags_to_fdt' [-Wframe-larger-than=]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) "file.c:3010", # fs/f2fs/file.c:3010:12: warning: unused function 'f2fs_ioctl_check_project'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) "configfs.c:1488", # drivers/usb/gadget/configfs.c:1488:12: warning: unused function 'configfs_composite_setup'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) "configfs.c:1513", # drivers/usb/gadget/configfs.c:1513:13: warning: unused function 'configfs_composite_disconnect'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) ])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) # Capture the name of the object file, can find it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ofile = None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) do_exit = False;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) warning_re = re.compile(r'''(.*/|)([^/]+\.[a-z]+:\d+):(\d+:)? warning:''')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) def interpret_warning(line):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) """Decode the message from clang. The messages we care about have a filename, and a warning"""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) line = line.rstrip('\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) m = warning_re.match(line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if m and m.group(2) not in allowed_warnings:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) print ("error, forbidden warning:" + m.group(2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) # If there is a warning, remove any object if it exists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if ofile:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) os.remove(ofile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) except OSError:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) pass
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) global do_exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) do_exit = True;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) def run_clang():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) args = sys.argv[1:]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) # Look for -o
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) i = args.index('-o')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) global ofile
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) ofile = args[i+1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) except (ValueError, IndexError):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) pass
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) env = os.environ.copy()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) env['LC_ALL'] = 'C'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) proc = subprocess.Popen(args, stderr=subprocess.PIPE, env=env)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) for line in proc.stderr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) print (line.decode("utf-8"), end="")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) interpret_warning(line.decode("utf-8"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if do_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) sys.exit(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) result = proc.wait()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) except OSError as e:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) result = e.errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if result == errno.ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) print (args[0] + ':' + e.strerror)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) print ('Is your PATH set correctly?')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) print (' '.join(args) + str(e))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if __name__ == '__main__':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) status = run_clang()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) sys.exit(status)