osmith has submitted this change. (
https://gerrit.osmocom.org/c/osmo-ci/+/42215?usp=email )
Change subject: lint/checkpatch: support multiple configs
......................................................................
lint/checkpatch: support multiple configs
Run checkpatch with any .checkpatch*.conf found in the project dir. This
is in preparation for having two .checkpatch.conf files in osmo-trx, in
order to use different linting rules for C++ code:
* .checkpatch.c.conf
* .checkpatch.c++.conf
Related: osmo-trx I0df5b6f2f0bf1469a80a1f5859809c30f523f683
Change-Id: Ia2e75d9783382cefc3900a4ab51a5a919a2cbbbc
---
M .gitignore
M lint/checkpatch/checkpatch.pl
M lint/checkpatch/checkpatch_json.py
M lint/checkpatch/checkpatch_osmo.sh
M lint/lint_all.sh
5 files changed, 74 insertions(+), 47 deletions(-)
Approvals:
fixeria: Looks good to me, but someone else must approve
osmith: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/.gitignore b/.gitignore
index 6e99147..b849dfb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,3 +17,4 @@
_temp_manuals/
_temp_releases/
scripts/repo-install-test/run-inside-env.sh
+.stdin_temp
diff --git a/lint/checkpatch/checkpatch.pl b/lint/checkpatch/checkpatch.pl
index 9a81dc2..46d1733 100755
--- a/lint/checkpatch/checkpatch.pl
+++ b/lint/checkpatch/checkpatch.pl
@@ -56,7 +56,7 @@
my @ignore = ();
my @exclude = ();
my $help = 0;
-my $configuration_file = ".checkpatch.conf";
+my $configuration_file = $ENV{'CHECKPATCH_CONFIG'} // '.checkpatch.conf';
my $max_line_length = 100;
my $ignore_perl_version = 0;
my $minimum_perl_version = 5.10.0;
diff --git a/lint/checkpatch/checkpatch_json.py
b/lint/checkpatch/checkpatch_json.py
index bf7f0af..e0c4dcd 100755
--- a/lint/checkpatch/checkpatch_json.py
+++ b/lint/checkpatch/checkpatch_json.py
@@ -17,13 +17,15 @@
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({
+ error = {
"robot_id" : "checkpatch",
"robot_run_id" : sys.argv[3],
"url" : sys.argv[4],
"line" : line_number,
- "message" : msg_output,}
- )
+ "message" : msg_output,
+ }
+ if error not in list_temp[file_path]:
+ list_temp[file_path].append(error)
def parse_file(input_file):
fp = open (input_file, "r")
diff --git a/lint/checkpatch/checkpatch_osmo.sh
b/lint/checkpatch/checkpatch_osmo.sh
index f56464a..ac586f7 100755
--- a/lint/checkpatch/checkpatch_osmo.sh
+++ b/lint/checkpatch/checkpatch_osmo.sh
@@ -2,6 +2,7 @@
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
PROJECT_DIR="$(git rev-parse --show-toplevel)"
PROJECT="$(basename "$PROJECT_DIR")"
+STDIN_TEMP="$SCRIPT_DIR/.stdin_temp"
exclude_paths_common() {
# Test output
@@ -83,48 +84,71 @@
# * UNNECESSARY_INT: not followed (see
https://gerrit.osmocom.org/c/libosmocore/+/25345)
# * UNSPECIFIED_INT: not followed (doesn't seem useful for us)
# * VOLATILE: using volatile makes sense in embedded projects so this warning
is not useful for us
+run_checkpatch() {
+ cat "$STDIN_TEMP" | $SCRIPT_DIR/checkpatch.pl \
+ $ARGS_EXCLUDE_PATHS_COMMON \
+ $ARGS_EXCLUDE_PATHS_COMMON_ASN1C \
+ $ARGS_EXCLUDE_PATHS_PROJECT \
+ --ignore ASSIGN_IN_IF \
+ --ignore AVOID_EXTERNS \
+ --ignore BLOCK_COMMENT_STYLE \
+ --ignore COMPLEX_MACRO \
+ --ignore CONSTANT_COMPARISON \
+ --ignore DEEP_INDENTATION \
+ --ignore EMBEDDED_FILENAME \
+ --ignore EMBEDDED_FUNCTION_NAME \
+ --ignore EXECUTE_PERMISSIONS \
+ --ignore FILE_PATH_CHANGES \
+ --ignore GLOBAL_INITIALISERS \
+ --ignore IF_0 \
+ --ignore INITIALISED_STATIC \
+ --ignore LINE_CONTINUATIONS \
+ --ignore LINE_SPACING \
+ --ignore LONG_LINE \
+ --ignore LONG_LINE_COMMENT \
+ --ignore LONG_LINE_STRING \
+ --ignore MACRO_WITH_FLOW_CONTROL \
+ --ignore MISSING_SPACE \
+ --ignore PREFER_DEFINED_ATTRIBUTE_MACRO \
+ --ignore PREFER_FALLTHROUGH \
+ --ignore REPEATED_WORD \
+ --ignore SPDX_LICENSE_TAG \
+ --ignore SPLIT_STRING \
+ --ignore STRING_FRAGMENTS \
+ --ignore SYMBOLIC_PERMS \
+ --ignore TRACING_LOGGING \
+ --ignore TRAILING_STATEMENTS \
+ --ignore UNNECESSARY_BREAK \
+ --ignore UNNECESSARY_INT \
+ --ignore UNSPECIFIED_INT \
+ --ignore VOLATILE \
+ --max-line-length 120 \
+ --typedefsfile "$SCRIPT_DIR/typedefs_osmo.txt" \
+ --no-signoff \
+ --no-tree \
+ "$@"
+}
+
+# This script gets called with stdin set to a git diff or empty string. Put it
+# into a temp file so we can pass it along to checkpatch multiple times.
+cat >"$STDIN_TEMP"
cd "$PROJECT_DIR"
-$SCRIPT_DIR/checkpatch.pl \
- $(exclude_paths_common) \
- $(exclude_paths_common_asn1c) \
- $(exclude_paths_project) \
- --ignore ASSIGN_IN_IF \
- --ignore AVOID_EXTERNS \
- --ignore BLOCK_COMMENT_STYLE \
- --ignore COMPLEX_MACRO \
- --ignore CONSTANT_COMPARISON \
- --ignore DEEP_INDENTATION \
- --ignore EMBEDDED_FILENAME \
- --ignore EMBEDDED_FUNCTION_NAME \
- --ignore EXECUTE_PERMISSIONS \
- --ignore FILE_PATH_CHANGES \
- --ignore GLOBAL_INITIALISERS \
- --ignore IF_0 \
- --ignore INITIALISED_STATIC \
- --ignore LINE_CONTINUATIONS \
- --ignore LINE_SPACING \
- --ignore LONG_LINE \
- --ignore LONG_LINE_COMMENT \
- --ignore LONG_LINE_STRING \
- --ignore MACRO_WITH_FLOW_CONTROL \
- --ignore MISSING_SPACE \
- --ignore PREFER_DEFINED_ATTRIBUTE_MACRO \
- --ignore PREFER_FALLTHROUGH \
- --ignore REPEATED_WORD \
- --ignore SPDX_LICENSE_TAG \
- --ignore SPLIT_STRING \
- --ignore STRING_FRAGMENTS \
- --ignore SYMBOLIC_PERMS \
- --ignore TRACING_LOGGING \
- --ignore TRAILING_STATEMENTS \
- --ignore UNNECESSARY_BREAK \
- --ignore UNNECESSARY_INT \
- --ignore UNSPECIFIED_INT \
- --ignore VOLATILE \
- --max-line-length 120 \
- --typedefsfile "$SCRIPT_DIR/typedefs_osmo.txt" \
- --no-signoff \
- --no-tree \
- "$@"
+ARGS_EXCLUDE_PATHS_COMMON="$(exclude_paths_common)"
+ARGS_EXCLUDE_PATHS_COMMON_ASN1C="$(exclude_paths_common_asn1c)"
+ARGS_EXCLUDE_PATHS_PROJECT="$(exclude_paths_project)"
+RET=0
+
+for i in .checkpatch*.conf; do
+ if [ -e "$i" ]; then
+ echo "config: $i"
+ CHECKPATCH_CONFIG="$i" run_checkpatch "$@" || RET=1
+ else
+ # The glob found nothing, just run normally
+ run_checkpatch "$@" || RET=1
+ fi
+done
+
+rm "$STDIN_TEMP"
+exit $RET
diff --git a/lint/lint_all.sh b/lint/lint_all.sh
index 1c25578..a86cc32 100755
--- a/lint/lint_all.sh
+++ b/lint/lint_all.sh
@@ -30,7 +30,7 @@
else
echo "Running checkpath in $GIT_DIR"
- "$SCRIPT_DIR"/checkpatch/checkpatch_osmo.sh \
+ echo "" | "$SCRIPT_DIR"/checkpatch/checkpatch_osmo.sh \
-f \
--color=always \
--no-summary \
--
To view, visit https://gerrit.osmocom.org/c/osmo-ci/+/42215?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-ci
Gerrit-Branch: master
Gerrit-Change-Id: Ia2e75d9783382cefc3900a4ab51a5a919a2cbbbc
Gerrit-Change-Number: 42215
Gerrit-PatchSet: 3
Gerrit-Owner: osmith <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>