[v2] devtools: set DTS directory to format check

Message ID 20221123112200.3109840-1-thomas@monjalon.net (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] devtools: set DTS directory to format check |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-broadcom-Performance fail Performance Testing issues
ci/intel-Testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS

Commit Message

Thomas Monjalon Nov. 23, 2022, 11:22 a.m. UTC
  The script was running on the current directory.
If not in the DTS directory, it would re-format every Python files.

A new positional argument is added to specify the directory to check.
In most cases, the (new) default value should be enough.

While updating argument handling,
the usage is printed in case of wrong argument.

The directory is also printed in headings,
and a last heading is added for the summary part.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Reviewed-by: Owen Hilyard <ohilyard@iol.unh.edu>
Reviewed-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
---
v2: add directory in headings and improve headings
---
 devtools/dts-check-format.sh | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
  

Comments

Juraj Linkeš Nov. 23, 2022, 1:41 p.m. UTC | #1
-----Original Message-----
From: Thomas Monjalon <thomas@monjalon.net> 
Sent: Wednesday, November 23, 2022 12:22 PM
To: dev@dpdk.org
Cc: Juraj Linkeš <juraj.linkes@pantheon.tech>; Owen Hilyard <ohilyard@iol.unh.edu>; Lijuan Tu <lijuan.tu@intel.com>
Subject: [PATCH v2] devtools: set DTS directory to format check

The script was running on the current directory.
If not in the DTS directory, it would re-format every Python files.

A new positional argument is added to specify the directory to check.
In most cases, the (new) default value should be enough.

While updating argument handling,
the usage is printed in case of wrong argument.

The directory is also printed in headings, and a last heading is added for the summary part.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Reviewed-by: Owen Hilyard <ohilyard@iol.unh.edu>
Reviewed-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
---
v2: add directory in headings and improve headings
---

Nice touch with the headings. The patch looks and works great.

Tested-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
  
Thomas Monjalon Nov. 23, 2022, 3:56 p.m. UTC | #2
> The script was running on the current directory.
> If not in the DTS directory, it would re-format every Python files.
> 
> A new positional argument is added to specify the directory to check.
> In most cases, the (new) default value should be enough.
> 
> While updating argument handling,
> the usage is printed in case of wrong argument.
> 
> The directory is also printed in headings, and a last heading is added for the summary part.
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> Reviewed-by: Owen Hilyard <ohilyard@iol.unh.edu>
> Reviewed-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
> ---
> v2: add directory in headings and improve headings
> ---
> 
> Nice touch with the headings. The patch looks and works great.

Thanks for the ideas.

> Tested-by: Juraj Linkeš <juraj.linkes@pantheon.tech>

Applied
  

Patch

diff --git a/devtools/dts-check-format.sh b/devtools/dts-check-format.sh
index dc07150775..c9b3702642 100755
--- a/devtools/dts-check-format.sh
+++ b/devtools/dts-check-format.sh
@@ -3,11 +3,10 @@ 
 # Copyright(c) 2022 University of New Hampshire
 
 usage() {
-	echo "Run formatting and linting programs for DTS. Usage:"
-
+	echo "Usage: $(basename $0) [options] [directory]"
+	echo 'Options:'
 	# Get source code comments after getopts arguments and print them both
 	grep -E '[a-zA-Z]+\) +#' "$0" | tr -d '#'
-	exit 0
 }
 
 format=true
@@ -17,7 +16,9 @@  lint=true
 while getopts "hfl" arg; do
 	case $arg in
 	h) # Display this message
+		echo 'Run formatting and linting programs for DTS.'
 		usage
+		exit 0
 		;;
 	f) # Don't run formatters
 		format=false
@@ -25,17 +26,27 @@  while getopts "hfl" arg; do
 	l) # Don't run linter
 		lint=false
 		;;
-	*)
+	?)
+		usage
+		exit 1
 	esac
 done
+shift $(($OPTIND - 1))
 
+directory=$(realpath --relative-base=$(pwd) ${1:-$(dirname $0)/../dts})
+cd $directory || exit 1
+
+heading() {
+	echo $*
+	echo $* | sed 's/./-/g' # underline
+}
 
 errors=0
 
 if $format; then
 	if command -v git > /dev/null; then
 		if git rev-parse --is-inside-work-tree >&-; then
-			echo "Formatting:"
+			heading "Formatting in $directory/"
 			if command -v black > /dev/null; then
 				echo "Formatting code with black:"
 				black .
@@ -72,7 +83,7 @@  if $lint; then
 	if $format; then
 		echo
 	fi
-	echo "Linting:"
+	heading "Linting in $directory/"
 	if command -v pylama > /dev/null; then
 		pylama .
 		errors=$((errors + $?))
@@ -83,5 +94,6 @@  if $lint; then
 fi
 
 echo
+heading "Summary for $directory/"
 echo "Found $errors errors"
 exit $errors