Skip to contentSkip to conversation

check-syntax: update arguments for astyle v3.2 (possibly earlier)

PATCH In review Paul Moore 2 participants 4 messages Oct 24, 2024 – Jan 2, 2025 SELinux security module

lore
Share & tools
lore

Paul Moore

author maintainer
#0 lore raw

PATCH 1/3 check-syntax: update arguments for astyle v3.2 (possibly earlier)

Update the astyle arguments in tools/check-syntax to work with modern version of astyle.

It is worth mentioning that astyle v3.6.3 appears to have a problem with aligning/indenting continuation lines, preferring blind indentation over alignment.

---
 tools/check-syntax | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/check-syntax +1 -2
index 2115a7960dd5..2775eb46c6c4 100755
@@ -57,10 +57,9 @@ function tool_c_style() {
 	astyle --options=none --lineend=linux --mode=c \
 		--style=linux \
 		--indent=force-tab=8 \
-		--indent-preprocessor \
 		--indent-col1-comments \
 		--min-conditional-indent=0 \
-		--max-instatement-indent=80 \
+		--max-continuation-indent=80 \
 		--pad-oper \
 		--align-pointer=name \
 		--align-reference=name \
Signature · 1 line
2.47.0
author maintainer
#1 lore raw

PATCH 2/3 check-syntax: ignore "bad" astyle versions

Create a list of known bad versions of astyle and ignore them.

---
 tools/check-syntax | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)
tools/check-syntax +20 -11
index 2775eb46c6c4..c55c51420142 100755
@@ -54,17 +54,26 @@ EOF
 #     1    Source file
 #
 function tool_c_style() {
-	astyle --options=none --lineend=linux --mode=c \
-		--style=linux \
-		--indent=force-tab=8 \
-		--indent-col1-comments \
-		--min-conditional-indent=0 \
-		--max-continuation-indent=80 \
-		--pad-oper \
-		--align-pointer=name \
-		--align-reference=name \
-		--max-code-length=80 \
-		--break-after-logical < "$1"
+	# filter on astyle version
+	case "$(astyle -V)" in
+	"Artistic Style Version 3.6.3")
+		# continuation lines indented vs aligned
+		cat "$1"
+		;;
+	*)
+		astyle --options=none --lineend=linux --mode=c \
+			--style=linux \
+			--indent=force-tab=8 \
+			--indent-col1-comments \
+			--min-conditional-indent=0 \
+			--max-continuation-indent=80 \
+			--pad-oper \
+			--align-pointer=name \
+			--align-reference=name \
+			--max-code-length=80 \
+			--break-after-logical < "$1"
+		;;
+	esac
 }
 
 #
Signature · 1 line
2.47.0
author maintainer
#2 lore raw

PATCH 3/3 all: coding style fixes

In reply to Paul Moore

Fixed using astyle v3.6.2.

---
 tests/file/test_sigiotask.c | 2 +-
 tests/ioctl/test_noioctl.c  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
tests/file/test_sigiotask.c +1 -1
index 1a8f8f51d438..97d343b71d6a 100644
@@ -58,7 +58,7 @@ int main(int argc, char **argv)
 	/*
 	 * Spawn off the child process to handle the information protocol.
 	 */
-	if( (pid = fork()) < 0 ) {
+	if((pid = fork()) < 0 ) {
 		perror("test_sigiotask:fork");
 		exit(2);
 	}
tests/ioctl/test_noioctl.c +2 -2
index 4b67e9a23640..319d90fa2ee3 100644
@@ -63,7 +63,7 @@ int main(int argc, char **argv)
 	 * < 2.6.27 or >= 2.6.39:  Should only check FD__USE and succeed.
 	 */
 	rc = ioctl(fd, FIONBIO, &val);
-	if( !rc == !useaccessmode ) {
+	if(!rc == !useaccessmode ) {
 		printf("test_noioctl:FIONBIO");
 		exit(1);
 	}
@@ -74,7 +74,7 @@ int main(int argc, char **argv)
 	 * Old:  Should hit the FILE__GETATTR test and fail.
 	 */
 	rc = ioctl(fd, FS_IOC_GETVERSION, &val);
-	if( (useaccessmode && rc == 0) ||
+	if((useaccessmode && rc == 0) ||
 	    (!useaccessmode && rc < 0 && errno != ENOTTY) ) {
 		perror("test_noioctl:FS_IOC_GETVERSION");
 		exit(1);
Signature · 1 line
2.47.0
#3 lore raw
In reply to Paul Moore
Quoted 30 lines · Paul Moore

Update the astyle arguments in tools/check-syntax to work with modern version of astyle.

It is worth mentioning that astyle v3.6.3 appears to have a problem with aligning/indenting continuation lines, preferring blind indentation over alignment.

---
 tools/check-syntax | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/check-syntax +1 -3
index 2115a7960dd5..2775eb46c6c4 100755
@@ -57,10 +57,9 @@ function tool_c_style() {
        astyle --options=none --lineend=linux --mode=c \
                --style=linux \
                --indent=force-tab=8 \
-               --indent-preprocessor \
                --indent-col1-comments \
                --min-conditional-indent=0 \
-               --max-instatement-indent=80 \
+               --max-continuation-indent=80 \
                --pad-oper \
                --align-pointer=name \
                --align-reference=name \
--
Quoted 3 lines

2.47.0

Thanks! I applied these with some changes:
1. I dropped patch 2 because I don't like the idea of filtering out known bad versions.
2. I updated patch 3 with what astyle 3.6.6 enforces (this version is now in Fedora 41 and it finally doesn't have buggy behavior with the testsuite's inputs).

The style-check job now passes successfully.

https://github.com/SELinuxProject/selinux-testsuite/commit/0f3dec2ab35e8739bb31bab8e6fcae51010c557c
https://github.com/SELinuxProject/selinux-testsuite/commit/68ff0417fd8ac0e5c9c5897a31dd3c7d17201306

--
Ondrej Mosnacek
Senior Software Engineer, Linux Security - SELinux kernel Red Hat, Inc.