aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2020-06-07 01:10:06 +0200
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2020-06-25 20:04:55 +0200
commit5d3fe27660ca820352dcc18e31d7ab2559ef930c (patch)
treeceb4f8ad21d66066e0bcc8a3176cb8e359225c83
parent5b48de6f20350e281e54820e2fcc63225dca309f (diff)
downloadhardware_replicant_libsamsung-ipc-5d3fe27660ca820352dcc18e31d7ab2559ef930c.tar.gz
hardware_replicant_libsamsung-ipc-5d3fe27660ca820352dcc18e31d7ab2559ef930c.tar.bz2
hardware_replicant_libsamsung-ipc-5d3fe27660ca820352dcc18e31d7ab2559ef930c.zip
Add a tool to help check the conversion to Linux code style
When sending a patch for Linux, and running checkpatch.pl, you typically only need to check the patch with it. However since we're doing an initial conversion to the Linux code style, we also need to check all the content of the files as well, as otherwise the parts that are not being touched by the patches won't be checked at all. We also need to get it right, as otherwise running checkpatch.pl on subsequent patches could trigger some errors that would not come from the patches being checked, but that would instead come from previous code style errors, that were left unfixed. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> Reviewed-by: Joonas Kylmälä <joonas.kylmala@iki.fi>
-rwxr-xr-xscripts/check_code_style_conversion.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/scripts/check_code_style_conversion.py b/scripts/check_code_style_conversion.py
new file mode 100755
index 0000000..015796a
--- /dev/null
+++ b/scripts/check_code_style_conversion.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# This is a script that helps checking the initial patches that converted
+# libsamsung-ipc to the kernel code style.
+#
+# As there is a massive amount of files to convert, and that the number of
+# patches is also big, this script can hopefully make testing and reviewing
+# easier.
+#
+# Copyright (C) 2020 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+import os
+import re
+import sh
+import sys
+
+def usage(progname):
+ print("{} <revision_range>".format(progname))
+ sys.exit(1)
+
+def run(*args):
+ # print(*args)
+ return sh.sh("-c", " ".join(args))
+
+def git(*args):
+ return sh.git("--no-pager", *args)
+
+def git_log_oneline(revision_range, *args):
+ return git("show",
+ "--oneline",
+ "-s",
+ "--no-decorate",
+ '--color=never',
+ revision_range,
+ *args).split(os.linesep)[:-1]
+
+def git_get_diffed_files(commit1, commit2):
+ return git("diff", "--name-only", commit1, commit2).split(os.linesep)[:-1]
+
+def git_get_commit_list(revision_range):
+ return git_log_oneline(revision_range, '--reverse', '--format=%h')
+
+def checkpatch(revision_range):
+ for commit in git_get_commit_list(revision_range):
+ print("Checking {}".format(git_log_oneline(commit)[0]))
+
+ # Check the commit
+ try:
+ diff = run("scripts" + os.sep + "checkpatch.pl", "-g", commit)
+ print(" [ OK ] Commit")
+ except:
+ print(" [ !! ] Commit")
+
+ # Check the files of the commit
+ modified_files = git_get_diffed_files(commit, commit + "~1")
+ for modified_file in modified_files:
+ try:
+ file_report = run("scripts" + os.sep + "checkpatch.pl",
+ "-f", modified_file)
+ print(" [ OK ] {}".format(modified_file))
+ except:
+ print(" [ !! ] {}".format(modified_file))
+
+if __name__ == '__main__':
+ if len(sys.argv) != 2:
+ usage(sys.argv[0])
+
+ revision_range = sys.argv[1]
+ checkpatch(revision_range)