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