soc/intel: Clean up some includes
[coreboot.git] / util / lint / checkpatch_json.py
blob341bc57733dff914e46d085825a19562d50c5785
1 #!/usr/bin/env python3
2 # SPDX-License-Identifier: GPL-2.0-only
4 """
5 This utilty generate json output to post comment in gerrit.
7 INPUT: output of checkpatch.pl.
8 OUTPUT: json format output that can be used to post comment in gerrit
9 """
10 import os
11 import sys
12 import json
13 import re
15 data = {}
16 data['comments'] = []
17 list_temp = {}
19 def update_struct( file_path, msg_output, line_number):
20 if file_path not in list_temp:
21 list_temp[file_path] = []
22 list_temp[file_path].append({
23 "robot_id" : "checkpatch",
24 "robot_run_id" : sys.argv[3],
25 "url" : sys.argv[4],
26 "line" : line_number,
27 "message" : msg_output,}
30 def parse_file(input_file):
31 fp = open (input_file, "r")
32 for line in fp:
33 if line.startswith("ERROR:"):
34 msg_output = line.split("ERROR:")[1].strip()
35 elif line.startswith("WARNING:"):
36 msg_output = line.split("WARNING:")[1].strip()
37 elif ": FILE:" in line:
38 temp = line.split("FILE:")
39 file_path = temp[1].split(":")[0]
40 line_number = temp[1].split(":")[1]
41 update_struct( file_path.strip(), msg_output, str(line_number) )
42 elif re.search("^\d+:\Z",line) != "None" and line.startswith("#"):
43 file_path="/COMMIT_MSG"
44 line = line.replace('#', '')
45 line_number = int(line.split(":")[0]) + 2
46 update_struct( file_path.strip(), msg_output, str(line_number) )
47 else:
48 continue
49 fp.close()
51 def main():
52 if (len(sys.argv) < 5) or (sys.argv[1] == "-h"):
53 print("HELP:")
54 print(sys.argv[0] + " <input file> <output file in json> <job-id> <job-url>")
55 sys.exit()
57 print(sys.argv[1])
58 parse_file(sys.argv[1])
59 data['robot_comments'] = list_temp
60 print(json.dumps(data))
61 out_file = open( sys.argv[2] , "w")
62 json.dump(data, out_file, sort_keys=True, indent=4)
63 out_file.close()
65 if __name__ == "__main__":
66 main()