Change in osmo-ci[master]: lint: add helper scripts

osmith gerrit-no-reply at lists.osmocom.org
Thu Jun 17 14:08:11 UTC 2021


osmith has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ci/+/24702 )

Change subject: lint: add helper scripts
......................................................................

lint: add helper scripts

Add lint_diff.sh, which runs checkpatch on git diff to either HEAD~1 (if
the tree is clean) or HEAD. This can be used as pre-commit hook, and
it's what jenkins will run.

Add lint_all.sh, which runs checkpatch on a whole repository to test if
the rules we are checking for make sense in Osmocom context.

Related: OS#5087
Change-Id: I1d02c169b05fb05b87209a444a5ddb86efc99d04
---
A lint/lint_all.sh
A lint/lint_diff.sh
2 files changed, 81 insertions(+), 0 deletions(-)

Approvals:
  laforge: Looks good to me, but someone else must approve
  fixeria: Looks good to me, but someone else must approve
  osmith: Looks good to me, approved; Verified



diff --git a/lint/lint_all.sh b/lint/lint_all.sh
new file mode 100755
index 0000000..1c25578
--- /dev/null
+++ b/lint/lint_all.sh
@@ -0,0 +1,43 @@
+#!/bin/sh -e
+# Script to test if linting is sane by running it on a whole repository
+GIT_DIR="$(git rev-parse --show-toplevel 2>/dev/null || true)"
+SCRIPT_DIR="$(dirname "$(realpath "$0")")"
+OUT=/tmp/lint_all_out
+TYPES="$1"
+
+echo "Running find in $GIT_DIR"
+files=$(find \
+	"$GIT_DIR" \
+	-name '*.c' \
+	-o -name '*.h' \
+	-o -name '*.cpp' \
+	-o -name '*.hpp')
+
+if [ -n "$TYPES" ]; then
+	echo "Running checkpath with --types="$TYPES" in $GIT_DIR"
+
+	"$SCRIPT_DIR"/checkpatch/checkpatch.pl \
+		-f \
+		--color=always \
+		--no-summary \
+		--no-tree \
+		--show-types \
+		--terse \
+		--types="$TYPES" \
+		$files \
+		| tee "$OUT"
+
+else
+	echo "Running checkpath in $GIT_DIR"
+
+	"$SCRIPT_DIR"/checkpatch/checkpatch_osmo.sh \
+		-f \
+		--color=always \
+		--no-summary \
+		--show-types \
+		--terse \
+		$files \
+		| tee "$OUT"
+fi
+
+wc -l "$OUT"
diff --git a/lint/lint_diff.sh b/lint/lint_diff.sh
new file mode 100755
index 0000000..f8daab7
--- /dev/null
+++ b/lint/lint_diff.sh
@@ -0,0 +1,38 @@
+#!/bin/sh -e
+# Jenkins runs this script on submitted gerrit patches. Can be used as git pre-commit hook.
+COMMIT="$1"
+GIT_DIR="$(git rev-parse --show-toplevel 2>/dev/null || true)"
+SCRIPT_DIR="$(dirname "$(realpath "$0")")"
+
+if [ -z "$GIT_DIR" ]; then
+	echo "ERROR: path is not a git repository: $PWD"
+	exit 1
+fi
+
+if [ -z "$COMMIT" ]; then
+	# Clean worktree: diff last commit against the one before
+	COMMIT="HEAD~1"
+
+	if [ -n "$(git status --porcelain)" ]; then
+		# Dirty worktree: diff uncommitted changes against last commit
+		COMMIT="HEAD"
+	fi
+fi
+
+echo "Running checkpatch on 'git diff $COMMIT'..."
+echo
+if git diff -U0 "$COMMIT" | "$SCRIPT_DIR/checkpatch/checkpatch_osmo.sh" - \
+	--color=always \
+	--mailback \
+	--show-types \
+	--showfile \
+	--terse
+then
+	exit 0
+fi
+
+echo
+echo "Please fix the linting errors above. More information:"
+echo "https://osmocom.org/projects/cellular-infrastructure/wiki/Linting"
+echo
+exit 1

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-ci/+/24702
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ci
Gerrit-Branch: master
Gerrit-Change-Id: I1d02c169b05fb05b87209a444a5ddb86efc99d04
Gerrit-Change-Number: 24702
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith at sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: osmith <osmith at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210617/79eb9be4/attachment.htm>


More information about the gerrit-log mailing list