summaryrefslogtreecommitdiff
path: root/util/lint
diff options
context:
space:
mode:
authorNaresh G Solanki <naresh.solanki@intel.com>2018-01-25 19:02:25 +0530
committerPatrick Georgi <pgeorgi@google.com>2018-04-09 08:18:43 +0000
commita6464b7ffd08b2e060a8c132f27aa2d8d77cb041 (patch)
tree5564a4bf511b2dcb8510c691aa36345ab569a635 /util/lint
parent6053a9ce05c1ca9c8919689fd766e14f4a8b4884 (diff)
downloadcoreboot-a6464b7ffd08b2e060a8c132f27aa2d8d77cb041.tar.xz
util/lint: Generate json output from checkpatch output
checkpatch_json.py processes the output of checkpatch.pl & generates json format output of comments. This json format output can be used to post comment on particular CL using gerrit. BUG=None BRANCH=None TEST= Run following commands: 1. Capture output of checkpatch.pl to file say checkpatch.txt nice -n 20 git diff HEAD~ | util/lint/checkpatch.pl --no-signoff -q - | tee checkpatch.txt 2. Generate json format file for the output. util/lint/checkpatch_json.py checkpatch.txt comment.json 3. Post the comment.json using gerrit ssh coreboot.org gerrit review -j "<CL number>,<patchset number>" < comment.json Change-Id: I2471792796ab8e7d9855a6559fc731345ebd1525 Signed-off-by: Naresh G Solanki <naresh.solanki@intel.com> Signed-off-by: Maulik V Vaghela <maulik.v.vaghela@intel.com> Reviewed-on: https://review.coreboot.org/23429 Reviewed-by: Subrata Banik <subrata.banik@intel.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'util/lint')
-rwxr-xr-xutil/lint/checkpatch_json.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/util/lint/checkpatch_json.py b/util/lint/checkpatch_json.py
new file mode 100755
index 0000000000..3254aae03b
--- /dev/null
+++ b/util/lint/checkpatch_json.py
@@ -0,0 +1,69 @@
+#!/usr/bin/python
+# Copyright (C) 2018 Intel Corporation.
+# written by Naresh G Solanki<naresh.solanki@intel.com> and
+# Maulik V Vaghela <maulik.v.vaghela@intel.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+
+"""
+This utilty generate json output to post comment in gerrit.
+
+INPUT: output of checkpatch.pl.
+OUTPUT: json format output that can be used to post comment in gerrit
+"""
+import os
+import sys
+import json
+
+data = {}
+data['comments'] = []
+list_temp = {}
+
+def update_struct( file_path, msg_output, line_number):
+ if file_path not in list_temp:
+ list_temp[file_path] = []
+ list_temp[file_path].append({
+ "line" : line_number,
+ "message" : msg_output,}
+ )
+
+def parse_file(input_file):
+ fp = open (input_file, "r")
+ for line in fp:
+ if "ERROR" in line:
+ msg_output = line.split("ERROR:")[1].strip()
+ elif "WARNING" in line:
+ msg_output = line.split("WARNING:")[1].strip()
+ elif "FILE" in line:
+ temp = line.split("FILE:")
+ file_path = temp[1].split(":")[0]
+ line_number = temp[1].split(":")[1]
+ update_struct( file_path.strip(), msg_output, str(line_number) )
+ else:
+ continue
+ fp.close()
+
+def main():
+ if (len(sys.argv) < 3) or (sys.argv[1] == "-h"):
+ print "HELP:"
+ print sys.argv[0] + " <input file> <output file in json>"
+ sys.exit()
+
+ print sys.argv[1]
+ parse_file(sys.argv[1])
+ data['comments'] = list_temp
+ print json.dumps(data)
+ out_file = open( sys.argv[2] , "w")
+ json.dump(data, out_file, sort_keys=True, indent=4)
+ out_file.close()
+
+if __name__ == "__main__":
+ main()