All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] utils/checkpackagelib/lib_mk.py: handle 'else' and 'elif' statements
@ 2020-12-09 15:32 Thomas De Schampheleire
  2021-01-02 12:55 ` Thomas Petazzoni
  2021-01-05 21:50 ` Peter Korsgaard
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas De Schampheleire @ 2020-12-09 15:32 UTC (permalink / raw)
  To: buildroot

From: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>

An 'else' or 'elif' clause inside a make conditional should not be indented
in the same way as the if/endif clause. check-package did not recognize the
else statement and expected an indentation.

For example:

ifdef FOOBAR
	interesting
else
	more interesting
endif

would, according to check-package, need to become:

ifdef FOOBAR
	interesting
	else
	more interesting
endif

Treat 'else' and 'elif' the same as if-like keywords in the Indent test, but
take into account that 'else' is also valid shell, so we need to correctly
handle line continuation to prevent complaining about the 'else' in:

ifdef FOOBAR
	if true; \
	    ... \
	else \
	    ... \
	fi
endif

We don't add the 'else' and 'elif' statements to start_conditional, because
it would cause incorrect nesting counting in class OverriddenVariable.

Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
---
 utils/checkpackagelib/lib_mk.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/utils/checkpackagelib/lib_mk.py b/utils/checkpackagelib/lib_mk.py
index 45e37e4598..0278354434 100644
--- a/utils/checkpackagelib/lib_mk.py
+++ b/utils/checkpackagelib/lib_mk.py
@@ -16,12 +16,13 @@ from checkpackagelib.lib import Utf8Characters         # noqa: F401
 
 # used in more than one check
 start_conditional = ["ifdef", "ifeq", "ifndef", "ifneq"]
+continue_conditional = ["elif", "else"]
 end_conditional = ["endif"]
 
 
 class Indent(_CheckFunction):
     COMMENT = re.compile(r"^\s*#")
-    CONDITIONAL = re.compile(r"^\s*({})\s".format("|".join(start_conditional + end_conditional)))
+    CONDITIONAL = re.compile(r"^\s*({})\s".format("|".join(start_conditional + end_conditional + continue_conditional)))
     ENDS_WITH_BACKSLASH = re.compile(r"^[^#].*\\$")
     END_DEFINE = re.compile(r"^\s*endef\s")
     MAKEFILE_TARGET = re.compile(r"^[^# \t]+:\s")
@@ -43,7 +44,7 @@ class Indent(_CheckFunction):
         expect_tabs = False
         if self.define or self.backslash or self.makefile_target:
             expect_tabs = True
-        if self.CONDITIONAL.search(text):
+        if not self.backslash and self.CONDITIONAL.search(text):
             expect_tabs = False
 
         # calculate for next line
-- 
2.26.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Buildroot] [PATCH] utils/checkpackagelib/lib_mk.py: handle 'else' and 'elif' statements
  2020-12-09 15:32 [Buildroot] [PATCH] utils/checkpackagelib/lib_mk.py: handle 'else' and 'elif' statements Thomas De Schampheleire
@ 2021-01-02 12:55 ` Thomas Petazzoni
  2021-01-05 21:50 ` Peter Korsgaard
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Petazzoni @ 2021-01-02 12:55 UTC (permalink / raw)
  To: buildroot

On Wed,  9 Dec 2020 16:32:18 +0100
Thomas De Schampheleire <patrickdepinguin@gmail.com> wrote:

> From: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
> 
> An 'else' or 'elif' clause inside a make conditional should not be indented
> in the same way as the if/endif clause. check-package did not recognize the
> else statement and expected an indentation.
> 
> For example:
> 
> ifdef FOOBAR
> 	interesting
> else
> 	more interesting
> endif
> 
> would, according to check-package, need to become:
> 
> ifdef FOOBAR
> 	interesting
> 	else
> 	more interesting
> endif
> 
> Treat 'else' and 'elif' the same as if-like keywords in the Indent test, but
> take into account that 'else' is also valid shell, so we need to correctly
> handle line continuation to prevent complaining about the 'else' in:
> 
> ifdef FOOBAR
> 	if true; \
> 	    ... \
> 	else \
> 	    ... \
> 	fi
> endif
> 
> We don't add the 'else' and 'elif' statements to start_conditional, because
> it would cause incorrect nesting counting in class OverriddenVariable.
> 
> Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
> ---
>  utils/checkpackagelib/lib_mk.py | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Applied to master, thanks.

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Buildroot] [PATCH] utils/checkpackagelib/lib_mk.py: handle 'else' and 'elif' statements
  2020-12-09 15:32 [Buildroot] [PATCH] utils/checkpackagelib/lib_mk.py: handle 'else' and 'elif' statements Thomas De Schampheleire
  2021-01-02 12:55 ` Thomas Petazzoni
@ 2021-01-05 21:50 ` Peter Korsgaard
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Korsgaard @ 2021-01-05 21:50 UTC (permalink / raw)
  To: buildroot

>>>>> "Thomas" == Thomas De Schampheleire <patrickdepinguin@gmail.com> writes:

 > From: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
 > An 'else' or 'elif' clause inside a make conditional should not be indented
 > in the same way as the if/endif clause. check-package did not recognize the
 > else statement and expected an indentation.

 > For example:

 > ifdef FOOBAR
 > 	interesting
 > else
 > 	more interesting
 > endif

 > would, according to check-package, need to become:

 > ifdef FOOBAR
 > 	interesting
 > 	else
 > 	more interesting
 > endif

 > Treat 'else' and 'elif' the same as if-like keywords in the Indent test, but
 > take into account that 'else' is also valid shell, so we need to correctly
 > handle line continuation to prevent complaining about the 'else' in:

 > ifdef FOOBAR
 > 	if true; \
 > 	    ... \
 > 	else \
 > 	    ... \
 > 	fi
 > endif

 > We don't add the 'else' and 'elif' statements to start_conditional, because
 > it would cause incorrect nesting counting in class OverriddenVariable.

 > Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>

Committed to 2020.02.x and 2020.11.x, thanks.

-- 
Bye, Peter Korsgaard

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-05 21:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-09 15:32 [Buildroot] [PATCH] utils/checkpackagelib/lib_mk.py: handle 'else' and 'elif' statements Thomas De Schampheleire
2021-01-02 12:55 ` Thomas Petazzoni
2021-01-05 21:50 ` Peter Korsgaard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.