[libcamera-devel,2/3] utils: checkstyle: Ensure "..." include style for internal headers
diff mbox series

Message ID 20220526110009.13874-3-laurent.pinchart@ideasonboard.com
State Accepted
Commit 7a529a9e3525cef170d9b58d920e805f7ce0bbd2
Headers show
Series
  • libcamera: checkstyle: Improve header formatter
Related show

Commit Message

Laurent Pinchart May 26, 2022, 11 a.m. UTC
libcamera uses the "..." include style for internal headers. Enforce it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 utils/checkstyle.py | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

Comments

Umang Jain May 27, 2022, 9:47 a.m. UTC | #1
Hi Laurent,

Thank you for the patch.

On 5/26/22 13:00, Laurent Pinchart via libcamera-devel wrote:
> libcamera uses the "..." include style for internal headers. Enforce it.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>


Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>

> ---
>   utils/checkstyle.py | 18 ++++++++++++++++--
>   1 file changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/utils/checkstyle.py b/utils/checkstyle.py
> index 66af96abd402..61783165bef2 100755
> --- a/utils/checkstyle.py
> +++ b/utils/checkstyle.py
> @@ -643,7 +643,7 @@ class DPointerFormatter(Formatter):
>   class IncludeOrderFormatter(Formatter):
>       patterns = ('*.cpp', '*.h')
>   
> -    include_regex = re.compile('^#include ["<]([^">]*)[">]')
> +    include_regex = re.compile('^#include (["<])([^">]*)([">])')
>   
>       @classmethod
>       def format(cls, filename, data):
> @@ -657,7 +657,21 @@ class IncludeOrderFormatter(Formatter):
>               if match:
>                   # If the current line is an #include statement, add it to the
>                   # includes group and continue to the next line.
> -                includes.append((line, match.group(1)))
> +                open_token = match.group(1)
> +                file_name = match.group(2)
> +                close_token = match.group(3)
> +
> +                # Ensure the "..." include style for internal headers and the
> +                # <...> style for all other libcamera headers.
> +                if (file_name.startswith('libcamera/internal')):
> +                    open_token = '"'
> +                    close_token = '"'
> +                elif (file_name.startswith('libcamera/')):
> +                    open_token = '<'
> +                    close_token = '>'
> +
> +                line = f'#include {open_token}{file_name}{close_token}'
> +                includes.append((line, file_name))
>                   continue
>   
>               # The current line is not an #include statement, output the sorted
Nicolas Dufresne via libcamera-devel May 31, 2022, 5:40 a.m. UTC | #2
Hi Laurent,

On Thu, May 26, 2022 at 02:00:08PM +0300, Laurent Pinchart via libcamera-devel wrote:
> libcamera uses the "..." include style for internal headers. Enforce it.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  utils/checkstyle.py | 18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/utils/checkstyle.py b/utils/checkstyle.py
> index 66af96abd402..61783165bef2 100755
> --- a/utils/checkstyle.py
> +++ b/utils/checkstyle.py
> @@ -643,7 +643,7 @@ class DPointerFormatter(Formatter):
>  class IncludeOrderFormatter(Formatter):
>      patterns = ('*.cpp', '*.h')
>  
> -    include_regex = re.compile('^#include ["<]([^">]*)[">]')
> +    include_regex = re.compile('^#include (["<])([^">]*)([">])')
>  
>      @classmethod
>      def format(cls, filename, data):
> @@ -657,7 +657,21 @@ class IncludeOrderFormatter(Formatter):
>              if match:
>                  # If the current line is an #include statement, add it to the
>                  # includes group and continue to the next line.
> -                includes.append((line, match.group(1)))
> +                open_token = match.group(1)
> +                file_name = match.group(2)
> +                close_token = match.group(3)
> +
> +                # Ensure the "..." include style for internal headers and the
> +                # <...> style for all other libcamera headers.
> +                if (file_name.startswith('libcamera/internal')):
> +                    open_token = '"'
> +                    close_token = '"'
> +                elif (file_name.startswith('libcamera/')):
> +                    open_token = '<'
> +                    close_token = '>'
> +
> +                line = f'#include {open_token}{file_name}{close_token}'
> +                includes.append((line, file_name))
>                  continue
>  
>              # The current line is not an #include statement, output the sorted

Patch
diff mbox series

diff --git a/utils/checkstyle.py b/utils/checkstyle.py
index 66af96abd402..61783165bef2 100755
--- a/utils/checkstyle.py
+++ b/utils/checkstyle.py
@@ -643,7 +643,7 @@  class DPointerFormatter(Formatter):
 class IncludeOrderFormatter(Formatter):
     patterns = ('*.cpp', '*.h')
 
-    include_regex = re.compile('^#include ["<]([^">]*)[">]')
+    include_regex = re.compile('^#include (["<])([^">]*)([">])')
 
     @classmethod
     def format(cls, filename, data):
@@ -657,7 +657,21 @@  class IncludeOrderFormatter(Formatter):
             if match:
                 # If the current line is an #include statement, add it to the
                 # includes group and continue to the next line.
-                includes.append((line, match.group(1)))
+                open_token = match.group(1)
+                file_name = match.group(2)
+                close_token = match.group(3)
+
+                # Ensure the "..." include style for internal headers and the
+                # <...> style for all other libcamera headers.
+                if (file_name.startswith('libcamera/internal')):
+                    open_token = '"'
+                    close_token = '"'
+                elif (file_name.startswith('libcamera/')):
+                    open_token = '<'
+                    close_token = '>'
+
+                line = f'#include {open_token}{file_name}{close_token}'
+                includes.append((line, file_name))
                 continue
 
             # The current line is not an #include statement, output the sorted