Skip to contentSkip to conversation

scripts/kernel-doc: Fix the regex for matching -Werror flag

PATCH In review Yujie Liu 3 participants 3 messages Oct 30, 2023 Documentation

lore
Share & tools
lore

Yujie Liu

author
#0 lore raw

PATCH 1/1 scripts/kernel-doc: Fix the regex for matching -Werror flag

Swarup reported a "make htmldocs" warning:

Variable length lookbehind is experimental in regex; marked by <-- HERE in m/(?<=^|\s)-Werror(?=$|\s) <-- HERE / at ./scripts/kernel-doc line 188.

Akira managed to reproduce it by perl v5.34.0.

On second thought, it is not necessary to have the complicated "lookahead and lookbehind" things, and the regex can be simplified.

Generally, the kernel-doc warnings should be considered as errors only when "-Werror" flag is set in KCFLAGS, but not when "-Werror=<diagnostic-type>" is set, which means there needs to be a space or start of string before "-Werror", and a space or end of string after "-Werror".

The following cases have been tested to work as expected:

* kernel-doc warnings are considered as errors:

  $ KCFLAGS="-Werror" make W=1
  $ KCFLAGS="-Wcomment -Werror" make W=1
  $ KCFLAGS="-Werror -Wundef" make W=1
  $ KCFLAGS="-Wcomment -Werror -Wundef" make W=1

* kernel-doc warnings remain as warnings:

  $ KCFLAGS="-Werror=return-type" make W=1
  $ KCFLAGS="-Wcomment -Werror=return-type" make W=1
  $ KCFLAGS="-Werror=return-type -Wundef" make W=1
  $ KCFLAGS="-Wcomment -Werror=return-type -Wundef" make W=1

The "Variable length lookbehind is experimental in regex" warning is also resolved by this patch.

Fixes 91f950e8b9d8 ("scripts/kernel-doc: match -Werror flag strictly")
Cc Akira Yokosawa <[email protected]>
---
 scripts/kernel-doc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kernel-doc +1 -1
index d660e1f4b483..08a3e603db19 100755
@@ -185,7 +185,7 @@ if (defined($ENV{'KBUILD_VERBOSE'}) && $ENV{'KBUILD_VERBOSE'} =~ '1') {
 if (defined($ENV{'KCFLAGS'})) {
 	my $kcflags = "$ENV{'KCFLAGS'}";
 
-	if ($kcflags =~ /(?<=^|\s)-Werror(?=$|\s)/) {
+	if ($kcflags =~ /(\s|^)-Werror(\s|$)/) {
 		$Werror = 1;
 	}
 }
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 10 lines · Yujie Liu

Swarup reported a "make htmldocs" warning:

Variable length lookbehind is experimental in regex; marked by <-- HERE in m/(?<=^|\s)-Werror(?=$|\s) <-- HERE / at ./scripts/kernel-doc line 188.

Akira managed to reproduce it by perl v5.34.0.

On second thought, it is not necessary to have the complicated "lookahead and lookbehind" things, and the regex can be simplified.

Nice!

As a matter of fact, that experimental "Variable length lookbehind" support was new to perl v5.30. So your previous change didn't work on systems such as Debian buster, RHEL 8, and the like.

Thank you for the quick fix.

Let me add a couple of tags.

Quoted 23 lines

Generally, the kernel-doc warnings should be considered as errors only when "-Werror" flag is set in KCFLAGS, but not when "-Werror=<diagnostic-type>" is set, which means there needs to be a space or start of string before "-Werror", and a space or end of string after "-Werror".

The following cases have been tested to work as expected:

* kernel-doc warnings are considered as errors:

  $ KCFLAGS="-Werror" make W=1
  $ KCFLAGS="-Wcomment -Werror" make W=1
  $ KCFLAGS="-Werror -Wundef" make W=1
  $ KCFLAGS="-Wcomment -Werror -Wundef" make W=1

* kernel-doc warnings remain as warnings:

  $ KCFLAGS="-Werror=return-type" make W=1
  $ KCFLAGS="-Wcomment -Werror=return-type" make W=1
  $ KCFLAGS="-Werror=return-type -Wundef" make W=1
  $ KCFLAGS="-Wcomment -Werror=return-type -Wundef" make W=1
Quoted 5 lines

The "Variable length lookbehind is experimental in regex" warning is also resolved by this patch.

Fixes 91f950e8b9d8 ("scripts/kernel-doc: match -Werror flag strictly")
Quoted 1 line
Cc Akira Yokosawa <[email protected]>
Quoted 10 lines
---
 scripts/kernel-doc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kernel-doc +0 -0
index d660e1f4b483..08a3e603db19 100755

scripts/kernel-doc if (defined($ENV{'KBUILD_VERBOSE'}) && $ENV{'KBUILD_VERBOSE'} =~ '1') { · line 188

Quoted 5 lines
scripts/kernel-doc +1 -1
@@ -185,7 +185,7 @@ if (defined($ENV{'KBUILD_VERBOSE'}) && $ENV{'KBUILD_VERBOSE'} =~ '1') {
 if (defined($ENV{'KCFLAGS'})) {
 	my $kcflags = "$ENV{'KCFLAGS'}";
 
-	if ($kcflags =~ /(?<=^|\s)-Werror(?=$|\s)/) {
+	if ($kcflags =~ /(\s|^)-Werror(\s|$)/) {

Simpler is better. I can read this ;-)

Thanks, Akira

Quoted 3 lines
scripts/kernel-doc +0 -0
 		$Werror = 1;
 	}
 }
maintainer
#2 lore raw
In reply to Yujie Liu
Quoted 49 lines · Yujie Liu

Swarup reported a "make htmldocs" warning:

Variable length lookbehind is experimental in regex; marked by <-- HERE in m/(?<=^|\s)-Werror(?=$|\s) <-- HERE / at ./scripts/kernel-doc line 188.

Akira managed to reproduce it by perl v5.34.0.

On second thought, it is not necessary to have the complicated "lookahead and lookbehind" things, and the regex can be simplified.

Generally, the kernel-doc warnings should be considered as errors only when "-Werror" flag is set in KCFLAGS, but not when "-Werror=<diagnostic-type>" is set, which means there needs to be a space or start of string before "-Werror", and a space or end of string after "-Werror".

The following cases have been tested to work as expected:

* kernel-doc warnings are considered as errors:

  $ KCFLAGS="-Werror" make W=1
  $ KCFLAGS="-Wcomment -Werror" make W=1
  $ KCFLAGS="-Werror -Wundef" make W=1
  $ KCFLAGS="-Wcomment -Werror -Wundef" make W=1

* kernel-doc warnings remain as warnings:

  $ KCFLAGS="-Werror=return-type" make W=1
  $ KCFLAGS="-Wcomment -Werror=return-type" make W=1
  $ KCFLAGS="-Werror=return-type -Wundef" make W=1
  $ KCFLAGS="-Wcomment -Werror=return-type -Wundef" make W=1

The "Variable length lookbehind is experimental in regex" warning is also resolved by this patch.

Fixes 91f950e8b9d8 ("scripts/kernel-doc: match -Werror flag strictly")
Cc Akira Yokosawa <[email protected]>
---
 scripts/kernel-doc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kernel-doc +0 -0
index d660e1f4b483..08a3e603db19 100755

scripts/kernel-doc if (defined($ENV{'KBUILD_VERBOSE'}) && $ENV{'KBUILD_VERBOSE'} =~ '1') { · line 189

Quoted 6 lines
scripts/kernel-doc +1 -1
@@ -185,7 +185,7 @@ if (defined($ENV{'KBUILD_VERBOSE'}) && $ENV{'KBUILD_VERBOSE'} =~ '1') {
 if (defined($ENV{'KCFLAGS'})) {
 	my $kcflags = "$ENV{'KCFLAGS'}";
 
-	if ($kcflags =~ /(?<=^|\s)-Werror(?=$|\s)/) {
+	if ($kcflags =~ /(\s|^)-Werror(\s|$)/) {
 		$Werror = 1;

OK, I've applied this one and will sneak it into the 6.7 pull request, thanks.

jon