Skip to contentSkip to conversation

drivers: fix indentation in build files

PATCH In review Thomas Monjalon 4 participants 16 messages Apr 21, 2021 – May 4, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: fix indentation in build files

A couple of mistakes slipped in the mass change.

More mistakes could happen, especially when rebasing pending patches, so we need an automatic check.

Fixes 4ad4b20a7905 ("drivers: change indentation in build files")
---
 drivers/crypto/qat/meson.build   | 4 ++--
 drivers/raw/skeleton/meson.build | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/crypto/qat/meson.build +2 -2
index 4da819d65a..544f481067 100644
@@ -17,9 +17,9 @@ if dep.found()
             'qat_asym_pmd.c',
             'qat_sym.c',
             'qat_sym_hw_dp.c',
-			'qat_sym_pmd.c',
+            'qat_sym_pmd.c',
             'qat_sym_session.c',
-	)
+    )
     qat_ext_deps += dep
     qat_cflags += '-DBUILD_QAT_SYM'
     qat_cflags += '-DBUILD_QAT_ASYM'
drivers/raw/skeleton/meson.build +1 -1
index b5d87652f5..950a33cc20 100644
@@ -3,6 +3,6 @@
 
 deps += ['rawdev', 'kvargs', 'mbuf', 'bus_vdev']
 sources = files(
-		'skeleton_rawdev.c',
+        'skeleton_rawdev.c',
         'skeleton_rawdev_test.c',
 )
Signature · 1 line
2.31.1
#1 lore raw
Quoted 5 lines · Thomas Monjalon

A couple of mistakes slipped in the mass change.

More mistakes could happen, especially when rebasing pending patches, so we need an automatic check.

I have a partially-done script from when I was doing the original reindenting work, which I'll clean up a little and send on shortly.

It only checks indent of lists and I'm extending it to check for trailing commas, but it may serve as a basis for further checks. On the plus side, it does automatic fixing of those issues though. Running it will probably show up more minor misses, so I'd suggest holding off on this patch until then.

Regards,
/Bruce

#2 lore raw

22/04/2021 10:39, Bruce Richardson:

Quoted 6 lines · Thomas Monjalon
Quoted 5 lines

A couple of mistakes slipped in the mass change.

More mistakes could happen, especially when rebasing pending patches, so we need an automatic check.

Quoted 8 lines

I have a partially-done script from when I was doing the original reindenting work, which I'll clean up a little and send on shortly.

It only checks indent of lists and I'm extending it to check for trailing commas, but it may serve as a basis for further checks. On the plus side, it does automatic fixing of those issues though. Running it will probably show up more minor misses, so I'd suggest holding off on this patch until then.

OK, I've sent this patch just for remembering.
I am happy to leave it to you for a v2 :)
Feel free to change the author of course.

Note: I've found tabs with this simple grep:

	git grep ' ' '**/meson.build'

The tab is inserted with ^V-tab.

#3 lore raw
Quoted 16 lines · Thomas Monjalon

22/04/2021 10:39, Bruce Richardson:

Quoted 6 lines · Thomas Monjalon
Quoted 5 lines

A couple of mistakes slipped in the mass change.

More mistakes could happen, especially when rebasing pending patches, so we need an automatic check.

Quoted 8 lines

I have a partially-done script from when I was doing the original reindenting work, which I'll clean up a little and send on shortly.

It only checks indent of lists and I'm extending it to check for trailing commas, but it may serve as a basis for further checks. On the plus side, it does automatic fixing of those issues though. Running it will probably show up more minor misses, so I'd suggest holding off on this patch until then.

Quoted 8 lines

OK, I've sent this patch just for remembering.
I am happy to leave it to you for a v2 :)
Feel free to change the author of course.

Note: I've found tabs with this simple grep:

	git grep ' ' '**/meson.build'

The tab is inserted with ^V-tab.

I've included fixes for these issues in V2 set of the python script to check for them.

http://patches.dpdk.org/project/dpdk/patch/[email protected]/

#4 lore raw

RFC PATCH 1/1 devtools: script to check meson indentation of lists

In reply to Thomas Monjalon

This is a draft script developed when I was working on the whitespace rework changes, since extended a little to attempt to fix some trailing comma issues.

---
 devtools/dpdk_meson_check.py | 106 +++++++++++++++++++++++++++++++++++
 1 file changed, 106 insertions(+)
 create mode 100755 devtools/dpdk_meson_check.py
devtools/dpdk_meson_check.py new file +106 -0
new file mode 100755
index 000000000..dc4c714ad
@@ -0,0 +1,106 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2021 Intel Corporation
+
+'''
+A Python script to run some checks on meson.build files in DPDK
+'''
+
+import sys
+import os
+from os.path import relpath, join
+from argparse import ArgumentParser
+
+VERBOSE = False
+FIX = False
+
+def scan_dir(path):
+    '''return meson.build files found in path'''
+    for root, dirs, files in os.walk(path):
+        if 'meson.build' in files:
+            yield(relpath(join(root, 'meson.build')))
+
+
+def check_indentation(filename, contents):
+    '''check that a list or files() is correctly indented'''
+    infiles = False
+    inlist = False
+    edit_count = 0
+    for lineno in range(len(contents)):
+        line = contents[lineno].rstrip()
+        if not line:
+            continue
+        if line.endswith('files('):
+            if infiles:
+                raise(f'Error parsing {filename}:{lineno}, got "files(" when already parsing files list')
+            if inlist:
+                print(f'Error parsing {filename}:{lineno}, got "files(" when already parsing array list')
+            infiles = True
+            indent = 0
+            while line[indent] == ' ':
+                indent += 1
+            indent += 8  # double indent required
+        elif line.endswith('= ['):
+            if infiles:
+                raise(f'Error parsing {filename}:{lineno}, got start of array when already parsing files list')
+            if inlist:
+                print(f'Error parsing {filename}:{lineno}, got start of array when already parsing array list')
+            inlist = True
+            indent = 0
+            while line[indent] == ' ':
+                indent += 1
+            indent += 8  # double indent required
+        elif infiles and (line.endswith(')') or line.strip().startswith(')')):
+            infiles = False
+            continue
+        elif inlist and line.endswith(']') or line.strip().startswith(']'):
+            inlist = False
+            continue
+        elif inlist or infiles:
+            # skip further subarrays or lists
+            if '[' in line  or ']' in line:
+                continue
+            if not line.startswith(' ' * indent) or line[indent] == ' ':
+                print(f'Error: Incorrect indent at {filename}:{lineno + 1}')
+                contents[lineno] = (' ' * indent) + line.strip() + '\n'
+                line = contents[lineno].rstrip()
+                edit_count += 1
+            if not line.endswith(',') and '#' not in line:
+                # TODO: support stripping comment and adding ','
+                print(f'Error: Missing trailing "," in list at {filename}:{lineno + 1}')
+                contents[lineno] = line + ',\n'
+                line = contents[lineno].rstrip()
+                edit_count += 1
+    return edit_count
+
+
+def process_file(filename):
+    '''run checks on file "filename"'''
+    if VERBOSE:
+        print(f'Processing {filename}')
+    with open(filename) as f:
+        contents = f.readlines()
+
+    if check_indentation(filename, contents) > 0 and FIX:
+        print(f"Fixing {filename}")
+        with open(filename, 'w') as f:
+            f.writelines(contents)
+
+
+def main():
+    '''parse arguments and then call other functions to do work'''
+    global VERBOSE
+    global FIX
+    parser = ArgumentParser(description='Run syntax checks on DPDK meson.build files')
+    parser.add_argument('-d', metavar='directory', default='.', help='Directory to process')
+    parser.add_argument('--fix', action='store_true', help='Attempt to fix errors')
+    parser.add_argument('-v', action='store_true', help='Verbose output')
+    args = parser.parse_args()
+
+    VERBOSE = args.v
+    FIX = args.fix
+    for f in scan_dir(args.d):
+        process_file(f)
+
+if __name__ == "__main__":
+    main()

--
2.27.0

#5 lore raw

Re: [dpdk-dev] [RFC PATCH] devtools: script to check meson indentation of lists

Quoted 34 lines · Bruce Richardson

This is a draft script developed when I was working on the whitespace rework changes, since extended a little to attempt to fix some trailing comma issues.

---
  devtools/dpdk_meson_check.py | 106 +++++++++++++++++++++++++++++++++++
  1 file changed, 106 insertions(+)

create mode 100755 devtools/dpdk_meson_check.py

devtools/dpdk_meson_check.py new file +19 -0
new file mode 100755
index 000000000..dc4c714ad
@@ -0,0 +1,106 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2021 Intel Corporation
+
+'''
+A Python script to run some checks on meson.build files in DPDK
+'''
+
+import sys
+import os
+from os.path import relpath, join
+from argparse import ArgumentParser
+
+VERBOSE = False
+FIX = False
+
+def scan_dir(path):
+    '''return meson.build files found in path'''
+    for root, dirs, files in os.walk(path):

devtools/dpdk_meson_check.py line 29

Quoted 10 lines
devtools/dpdk_meson_check.py new file +10 -0
+        if 'meson.build' in files:
+            yield(relpath(join(root, 'meson.build')))
+
+
+def check_indentation(filename, contents):
+    '''check that a list or files() is correctly indented'''
+    infiles = False
+    inlist = False
+    edit_count = 0
+    for lineno in range(len(contents)):

for lineno, line in enumerate(contents)

?

devtools/dpdk_meson_check.py line 41

Quoted 12 lines
devtools/dpdk_meson_check.py new file +12 -0
+        line = contents[lineno].rstrip()
+        if not line:
+            continue
+        if line.endswith('files('):
+            if infiles:
+                raise(f'Error parsing {filename}:{lineno}, got "files(" when already parsing files list')
+            if inlist:
+                print(f'Error parsing {filename}:{lineno}, got "files(" when already parsing array list')
+            infiles = True
+            indent = 0
+            while line[indent] == ' ':
+                indent += 1

Here and in other places, if this is measuring length of indent, maybe do something like:

indent = len(line) - len(line.lstrip(' '))

?

devtools/dpdk_meson_check.py line 53

Quoted 12 lines
devtools/dpdk_meson_check.py new file +12 -0
+            indent += 8  # double indent required
+        elif line.endswith('= ['):
+            if infiles:
+                raise(f'Error parsing {filename}:{lineno}, got start of array when already parsing files list')
+            if inlist:
+                print(f'Error parsing {filename}:{lineno}, got start of array when already parsing array list')
+            inlist = True
+            indent = 0
+            while line[indent] == ' ':
+                indent += 1
+            indent += 8  # double indent required
+        elif infiles and (line.endswith(')') or line.strip().startswith(')')):

It's kinda hard to read with all the endswith/startswith, maybe extract those into a function? e.g. 'elif infiles and is_file_start(line)'

devtools/dpdk_meson_check.py line 62

Quoted 9 lines
devtools/dpdk_meson_check.py new file +9 -0
+            infiles = False
+            continue
+        elif inlist and line.endswith(']') or line.strip().startswith(']'):
+            inlist = False
+            continue
+        elif inlist or infiles:
+            # skip further subarrays or lists
+            if '[' in line  or ']' in line:
+                continue

I guess you could make it recursive instead of giving up? Does this happen with any kind of regularity?

devtools/dpdk_meson_check.py line 72

Quoted 10 lines
devtools/dpdk_meson_check.py new file +10 -0
+            if not line.startswith(' ' * indent) or line[indent] == ' ':
+                print(f'Error: Incorrect indent at {filename}:{lineno + 1}')
+                contents[lineno] = (' ' * indent) + line.strip() + '\n'
+                line = contents[lineno].rstrip()
+                edit_count += 1
+            if not line.endswith(',') and '#' not in line:
+                # TODO: support stripping comment and adding ','
+                print(f'Error: Missing trailing "," in list at {filename}:{lineno + 1}')
+                contents[lineno] = line + ',\n'
+                line = contents[lineno].rstrip()

What is the point of setting line here?

devtools/dpdk_meson_check.py line 82

Quoted 10 lines
devtools/dpdk_meson_check.py new file +10 -0
+                edit_count += 1
+    return edit_count
+
+
+def process_file(filename):
+    '''run checks on file "filename"'''
+    if VERBOSE:
+        print(f'Processing {filename}')
+    with open(filename) as f:
+        contents = f.readlines()

I guess meson build files don't get too big so it's OK to read the entire file in memory and then work on it, rather than go line by line...

devtools/dpdk_meson_check.py line 93

Quoted 11 lines
devtools/dpdk_meson_check.py new file +11 -0
+
+    if check_indentation(filename, contents) > 0 and FIX:
+        print(f"Fixing {filename}")
+        with open(filename, 'w') as f:
+            f.writelines(contents)
+
+
+def main():
+    '''parse arguments and then call other functions to do work'''
+    global VERBOSE
+    global FIX

Seems like globals are unnecessary here when you can just pass them into process_file?

Quoted 16 lines
devtools/dpdk_meson_check.py new file +13 -1
+    parser = ArgumentParser(description='Run syntax checks on DPDK meson.build files')
+    parser.add_argument('-d', metavar='directory', default='.', help='Directory to process')
+    parser.add_argument('--fix', action='store_true', help='Attempt to fix errors')
+    parser.add_argument('-v', action='store_true', help='Verbose output')
+    args = parser.parse_args()
+
+    VERBOSE = args.v
+    FIX = args.fix
+    for f in scan_dir(args.d):
+        process_file(f)
+
+if __name__ == "__main__":
+    main()
--

2.27.0

Signature · 2 lines
Thanks,
Anatoly
#6 lore raw

Re: [dpdk-dev] [RFC PATCH] devtools: script to check meson indentation of lists

Quoted 39 lines · Anatoly
Quoted 38 lines · Bruce Richardson

This is a draft script developed when I was working on the whitespace rework changes, since extended a little to attempt to fix some trailing comma issues.

---
  devtools/dpdk_meson_check.py | 106 +++++++++++++++++++++++++++++++++++
  1 file changed, 106 insertions(+)

create mode 100755 devtools/dpdk_meson_check.py

devtools/dpdk_meson_check.py new file +23 -0
new file mode 100755
index 000000000..dc4c714ad
@@ -0,0 +1,106 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2021 Intel Corporation
+
+'''
+A Python script to run some checks on meson.build files in DPDK
+'''
+
+import sys
+import os
+from os.path import relpath, join
+from argparse import ArgumentParser
+
+VERBOSE = False
+FIX = False
+
+def scan_dir(path):
+    '''return meson.build files found in path'''
+    for root, dirs, files in os.walk(path):
+        if 'meson.build' in files:
+            yield(relpath(join(root, 'meson.build')))
+
+
Quoted 9 lines

devtools/dpdk_meson_check.py line 29

Quoted 6 lines
devtools/dpdk_meson_check.py new file +6 -0
+def check_indentation(filename, contents):
+    '''check that a list or files() is correctly indented'''
+    infiles = False
+    inlist = False
+    edit_count = 0
+    for lineno in range(len(contents)):

for lineno, line in enumerate(contents)

Yep, that's a good idea. Wasn't aware of enumerate. [Learn something new every day, eh? :-)]

Quoted 15 lines

?

devtools/dpdk_meson_check.py line 41

Quoted 12 lines
devtools/dpdk_meson_check.py new file +12 -0
+        line = contents[lineno].rstrip()
+        if not line:
+            continue
+        if line.endswith('files('):
+            if infiles:
+                raise(f'Error parsing {filename}:{lineno}, got "files(" when already parsing files list')
+            if inlist:
+                print(f'Error parsing {filename}:{lineno}, got "files(" when already parsing array list')
+            infiles = True
+            indent = 0
+            while line[indent] == ' ':
+                indent += 1
Quoted 5 lines

Here and in other places, if this is measuring length of indent, maybe do something like:

indent = len(line) - len(line.lstrip(' '))

Yep, that is cleaner

Quoted 15 lines

?

devtools/dpdk_meson_check.py line 53

Quoted 12 lines
devtools/dpdk_meson_check.py new file +12 -0
+            indent += 8  # double indent required
+        elif line.endswith('= ['):
+            if infiles:
+                raise(f'Error parsing {filename}:{lineno}, got start of array when already parsing files list')
+            if inlist:
+                print(f'Error parsing {filename}:{lineno}, got start of array when already parsing array list')
+            inlist = True
+            indent = 0
+            while line[indent] == ' ':
+                indent += 1
+            indent += 8  # double indent required
+        elif infiles and (line.endswith(')') or line.strip().startswith(')')):
Quoted 3 lines

It's kinda hard to read with all the endswith/startswith, maybe extract those into a function? e.g. 'elif infiles and is_file_start(line)'

It is all a bit of a mess, yes, and needs cleaning up - which is why I didn't previously send it with the patchset. Splitting into functions is something I'll look at.

Quoted 10 lines

devtools/dpdk_meson_check.py line 62

Quoted 9 lines
devtools/dpdk_meson_check.py new file +9 -0
+            infiles = False
+            continue
+        elif inlist and line.endswith(']') or line.strip().startswith(']'):
+            inlist = False
+            continue
+        elif inlist or infiles:
+            # skip further subarrays or lists
+            if '[' in line  or ']' in line:
+                continue
Quoted 3 lines

I guess you could make it recursive instead of giving up? Does this happen with any kind of regularity?

No, not that much, which is why I haven't explicitly tried to deal with it. It would be good to support in future.

Quoted 11 lines

devtools/dpdk_meson_check.py line 72

Quoted 10 lines
devtools/dpdk_meson_check.py new file +10 -0
+            if not line.startswith(' ' * indent) or line[indent] == ' ':
+                print(f'Error: Incorrect indent at {filename}:{lineno + 1}')
+                contents[lineno] = (' ' * indent) + line.strip() + '\n'
+                line = contents[lineno].rstrip()
+                edit_count += 1
+            if not line.endswith(',') and '#' not in line:
+                # TODO: support stripping comment and adding ','
+                print(f'Error: Missing trailing "," in list at {filename}:{lineno + 1}')
+                contents[lineno] = line + ',\n'
+                line = contents[lineno].rstrip()
Quoted 2 lines

What is the point of setting line here?

Because it allows us to make further checks using "line" as we add them later.
The one question is whether it's worth using line as a shortcut for contents[lineno] or not. I'd tend to keep it, as it also allows us not to worry about the '\n' at the end. Then again, other rework might just change the whole script to strip off all the '\n' post-read and add them back again pre-write.

Again, further cleanup work.

Quoted 5 lines
Quoted 5 lines
devtools/dpdk_meson_check.py new file +5 -0
+                edit_count += 1
+    return edit_count
+
+
+def process_file(filename):
Quoted 9 lines

devtools/dpdk_meson_check.py line 82

Quoted 5 lines
devtools/dpdk_meson_check.py new file +5 -0
+    '''run checks on file "filename"'''
+    if VERBOSE:
+        print(f'Processing {filename}')
+    with open(filename) as f:
+        contents = f.readlines()

I guess meson build files don't get too big so it's OK to read the entire file in memory and then work on it, rather than go line by line...

This was a deliberate choice when starting the script. For now the script only checks indentation and formatting of lists, but ideally in future it should check other things, e.g. alphabetical order of lists, or formatting of other parts. Rather than checking it all in one go, the script is structured so that we can call multiple functions with "contents" each of which does the processing without constantly re-reading and rewriting the file. Something like sorting a list alphabetically also requires changing multiple lines at a time, which is easier to do with lists that when streaming input.

Quoted 6 lines
Quoted 6 lines
devtools/dpdk_meson_check.py new file +6 -0
+
+    if check_indentation(filename, contents) > 0 and FIX:
+        print(f"Fixing {filename}")
+        with open(filename, 'w') as f:
+            f.writelines(contents)
+
Quoted 9 lines

devtools/dpdk_meson_check.py line 93

Quoted 5 lines
devtools/dpdk_meson_check.py new file +5 -0
+
+def main():
+    '''parse arguments and then call other functions to do work'''
+    global VERBOSE
+    global FIX

Seems like globals are unnecessary here when you can just pass them into process_file?

Yes, they can just be passed, but I actually prefer to have those as globals rather than having larger parameter lists. It's also possible that e.g. verbose, should need to be passed through multiple levels of functions. Personal preference, though really.

Quoted 8 lines
Quoted 8 lines
devtools/dpdk_meson_check.py new file +8 -0
+    parser = ArgumentParser(description='Run syntax checks on DPDK meson.build files')
+    parser.add_argument('-d', metavar='directory', default='.', help='Directory to process')
+    parser.add_argument('--fix', action='store_true', help='Attempt to fix errors')
+    parser.add_argument('-v', action='store_true', help='Verbose output')
+    args = parser.parse_args()
+
+    VERBOSE = args.v
+    FIX = args.fix
Quoted 12 lines
Quoted 8 lines
devtools/dpdk_meson_check.py new file +5 -1
+    for f in scan_dir(args.d):
+        process_file(f)
+
+if __name__ == "__main__":
+    main()
--

2.27.0

Signature · 1 line
Thanks,

Thanks for the review Anatoly.

/Bruce

#7 lore raw

Re: [dpdk-dev] [RFC PATCH] devtools: script to check meson indentation of lists

Quoted 133 lines · Bruce Richardson
Quoted 39 lines · Anatoly
Quoted 38 lines · Bruce Richardson

This is a draft script developed when I was working on the whitespace rework changes, since extended a little to attempt to fix some trailing comma issues.

---
   devtools/dpdk_meson_check.py | 106 +++++++++++++++++++++++++++++++++++
   1 file changed, 106 insertions(+)

create mode 100755 devtools/dpdk_meson_check.py

devtools/dpdk_meson_check.py new file +23 -0
new file mode 100755
index 000000000..dc4c714ad
@@ -0,0 +1,106 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2021 Intel Corporation
+
+'''
+A Python script to run some checks on meson.build files in DPDK
+'''
+
+import sys
+import os
+from os.path import relpath, join
+from argparse import ArgumentParser
+
+VERBOSE = False
+FIX = False
+
+def scan_dir(path):
+    '''return meson.build files found in path'''
+    for root, dirs, files in os.walk(path):
+        if 'meson.build' in files:
+            yield(relpath(join(root, 'meson.build')))
+
+
Quoted 9 lines

devtools/dpdk_meson_check.py line 29

Quoted 6 lines
devtools/dpdk_meson_check.py new file +6 -0
+def check_indentation(filename, contents):
+    '''check that a list or files() is correctly indented'''
+    infiles = False
+    inlist = False
+    edit_count = 0
+    for lineno in range(len(contents)):

for lineno, line in enumerate(contents)

Yep, that's a good idea. Wasn't aware of enumerate. [Learn something new every day, eh? :-)]

Quoted 15 lines

?

devtools/dpdk_meson_check.py line 41

Quoted 12 lines
devtools/dpdk_meson_check.py new file +12 -0
+        line = contents[lineno].rstrip()
+        if not line:
+            continue
+        if line.endswith('files('):
+            if infiles:
+                raise(f'Error parsing {filename}:{lineno}, got "files(" when already parsing files list')
+            if inlist:
+                print(f'Error parsing {filename}:{lineno}, got "files(" when already parsing array list')
+            infiles = True
+            indent = 0
+            while line[indent] == ' ':
+                indent += 1
Quoted 5 lines

Here and in other places, if this is measuring length of indent, maybe do something like:

indent = len(line) - len(line.lstrip(' '))

Yep, that is cleaner

Quoted 15 lines

?

devtools/dpdk_meson_check.py line 53

Quoted 12 lines
devtools/dpdk_meson_check.py new file +12 -0
+            indent += 8  # double indent required
+        elif line.endswith('= ['):
+            if infiles:
+                raise(f'Error parsing {filename}:{lineno}, got start of array when already parsing files list')
+            if inlist:
+                print(f'Error parsing {filename}:{lineno}, got start of array when already parsing array list')
+            inlist = True
+            indent = 0
+            while line[indent] == ' ':
+                indent += 1
+            indent += 8  # double indent required
+        elif infiles and (line.endswith(')') or line.strip().startswith(')')):
Quoted 3 lines

It's kinda hard to read with all the endswith/startswith, maybe extract those into a function? e.g. 'elif infiles and is_file_start(line)'

It is all a bit of a mess, yes, and needs cleaning up - which is why I didn't previously send it with the patchset. Splitting into functions is something I'll look at.

Quoted 10 lines

devtools/dpdk_meson_check.py line 62

Quoted 9 lines
devtools/dpdk_meson_check.py new file +9 -0
+            infiles = False
+            continue
+        elif inlist and line.endswith(']') or line.strip().startswith(']'):
+            inlist = False
+            continue
+        elif inlist or infiles:
+            # skip further subarrays or lists
+            if '[' in line  or ']' in line:
+                continue
Quoted 3 lines

I guess you could make it recursive instead of giving up? Does this happen with any kind of regularity?

No, not that much, which is why I haven't explicitly tried to deal with it. It would be good to support in future.

Quoted 11 lines

devtools/dpdk_meson_check.py line 72

Quoted 10 lines
devtools/dpdk_meson_check.py new file +10 -0
+            if not line.startswith(' ' * indent) or line[indent] == ' ':
+                print(f'Error: Incorrect indent at {filename}:{lineno + 1}')
+                contents[lineno] = (' ' * indent) + line.strip() + '\n'
+                line = contents[lineno].rstrip()
+                edit_count += 1
+            if not line.endswith(',') and '#' not in line:
+                # TODO: support stripping comment and adding ','
+                print(f'Error: Missing trailing "," in list at {filename}:{lineno + 1}')
+                contents[lineno] = line + ',\n'
+                line = contents[lineno].rstrip()
Quoted 2 lines

What is the point of setting line here?

Because it allows us to make further checks using "line" as we add them later.
The one question is whether it's worth using line as a shortcut for contents[lineno] or not. I'd tend to keep it, as it also allows us not to worry about the '\n' at the end. Then again, other rework might just change the whole script to strip off all the '\n' post-read and add them back again pre-write.

Quoted 1 line

Again, further cleanup work.

Well, yes, i got that, it's just that as far as i can tell, the last "line = ..." is at the end of the iteration, so there's no point in setting it. Maybe i'm missing something :)

Quoted 15 lines
Quoted 15 lines

devtools/dpdk_meson_check.py line 82

Quoted 11 lines
devtools/dpdk_meson_check.py new file +10 -0
+                edit_count += 1
+    return edit_count
+
+
+def process_file(filename):
+    '''run checks on file "filename"'''
+    if VERBOSE:
+        print(f'Processing {filename}')
+    with open(filename) as f:
+        contents = f.readlines()

I guess meson build files don't get too big so it's OK to read the entire file in memory and then work on it, rather than go line by line...

Quoted 9 lines

This was a deliberate choice when starting the script. For now the script only checks indentation and formatting of lists, but ideally in future it should check other things, e.g. alphabetical order of lists, or formatting of other parts. Rather than checking it all in one go, the script is structured so that we can call multiple functions with "contents" each of which does the processing without constantly re-reading and rewriting the file. Something like sorting a list alphabetically also requires changing multiple lines at a time, which is easier to do with lists that when streaming input.

Right, gotcha.

Quoted 16 lines
Quoted 16 lines

devtools/dpdk_meson_check.py line 93

Quoted 12 lines
devtools/dpdk_meson_check.py new file +11 -0
+
+    if check_indentation(filename, contents) > 0 and FIX:
+        print(f"Fixing {filename}")
+        with open(filename, 'w') as f:
+            f.writelines(contents)
+
+
+def main():
+    '''parse arguments and then call other functions to do work'''
+    global VERBOSE
+    global FIX

Seems like globals are unnecessary here when you can just pass them into process_file?

Quoted 4 lines

Yes, they can just be passed, but I actually prefer to have those as globals rather than having larger parameter lists. It's also possible that e.g. verbose, should need to be passed through multiple levels of functions. Personal preference, though really.

Static analyzers (e.g. pylint) will complain about it, which is why i usually avoid those unless really necessary :) For something like "verbose", sure, one could argue that it's OK to have it as a global, but FIX is definitely something that could be a parameter, as you don't seem to use it anywhere other than in process_file(), nor would it seem likely that it will be used in the future.

Quoted 26 lines
Quoted 21 lines
Quoted 17 lines
devtools/dpdk_meson_check.py new file +13 -1
+    parser = ArgumentParser(description='Run syntax checks on DPDK meson.build files')
+    parser.add_argument('-d', metavar='directory', default='.', help='Directory to process')
+    parser.add_argument('--fix', action='store_true', help='Attempt to fix errors')
+    parser.add_argument('-v', action='store_true', help='Verbose output')
+    args = parser.parse_args()
+
+    VERBOSE = args.v
+    FIX = args.fix
+    for f in scan_dir(args.d):
+        process_file(f)
+
+if __name__ == "__main__":
+    main()
--

2.27.0

Signature · 1 line
Thanks,

Thanks for the review Anatoly.

/Bruce

Signature · 2 lines
Thanks,
Anatoly
#8 lore raw

Re: [dpdk-dev] [RFC PATCH] devtools: script to check meson indentation of lists

Quoted 8 lines · Anatoly
Quoted 7 lines · Bruce Richardson
Quoted 6 lines · Anatoly
Quoted 5 lines · Bruce Richardson

This is a draft script developed when I was working on the whitespace rework changes, since extended a little to attempt to fix some trailing comma issues.

---

<snip>

Quoted 16 lines
Quoted 16 lines
Quoted 8 lines

devtools/dpdk_meson_check.py line 72

Quoted 5 lines
devtools/dpdk_meson_check.py new file +5 -0
+            if not line.endswith(',') and '#' not in line:
+                # TODO: support stripping comment and adding ','
+                print(f'Error: Missing trailing "," in list at {filename}:{lineno + 1}')
+                contents[lineno] = line + ',\n'
+                line = contents[lineno].rstrip()

What is the point of setting line here?

Because it allows us to make further checks using "line" as we add them later.
The one question is whether it's worth using line as a shortcut for contents[lineno] or not. I'd tend to keep it, as it also allows us not to worry about the '\n' at the end. Then again, other rework might just change the whole script to strip off all the '\n' post-read and add them back again pre-write.

Quoted 5 lines
Quoted 1 line

Again, further cleanup work.

Well, yes, i got that, it's just that as far as i can tell, the last "line = ..." is at the end of the iteration, so there's no point in setting it. Maybe i'm missing something :)

No, you are not, and indeed it is at the very end. The fact it's there is to make sure it's not forgotten when adding in new checks. It also allows the checks to be reordered easier. Think of it like the trailing comma on a list! :-)

Quoted 48 lines
Quoted 15 lines
Quoted 15 lines

devtools/dpdk_meson_check.py line 82

Quoted 11 lines
devtools/dpdk_meson_check.py new file +10 -0
+                edit_count += 1
+    return edit_count
+
+
+def process_file(filename):
+    '''run checks on file "filename"'''
+    if VERBOSE:
+        print(f'Processing {filename}')
+    with open(filename) as f:
+        contents = f.readlines()

I guess meson build files don't get too big so it's OK to read the entire file in memory and then work on it, rather than go line by line...

Quoted 9 lines

This was a deliberate choice when starting the script. For now the script only checks indentation and formatting of lists, but ideally in future it should check other things, e.g. alphabetical order of lists, or formatting of other parts. Rather than checking it all in one go, the script is structured so that we can call multiple functions with "contents" each of which does the processing without constantly re-reading and rewriting the file. Something like sorting a list alphabetically also requires changing multiple lines at a time, which is easier to do with lists that when streaming input.

Right, gotcha.

Quoted 16 lines
Quoted 16 lines

devtools/dpdk_meson_check.py line 93

Quoted 12 lines
devtools/dpdk_meson_check.py new file +11 -0
+
+    if check_indentation(filename, contents) > 0 and FIX:
+        print(f"Fixing {filename}")
+        with open(filename, 'w') as f:
+            f.writelines(contents)
+
+
+def main():
+    '''parse arguments and then call other functions to do work'''
+    global VERBOSE
+    global FIX

Seems like globals are unnecessary here when you can just pass them into process_file?

Quoted 4 lines

Yes, they can just be passed, but I actually prefer to have those as globals rather than having larger parameter lists. It's also possible that e.g. verbose, should need to be passed through multiple levels of functions. Personal preference, though really.

Quoted 7 lines

Static analyzers (e.g. pylint) will complain about it, which is why i usually avoid those unless really necessary :) For something like "verbose", sure, one could argue that it's OK to have it as a global, but FIX is definitely something that could be a parameter, as you don't seem to use it anywhere other than in process_file(), nor would it seem likely that it will be used in the future.

Yep, agreed. Fix can be just a parameter. It may be that it's kept as a global here is for consistency with verbose, but more likely it's just an oversight on my part. I will change it to parameter instead in any next revision.

/Bruce

#9 lore raw

PATCH v2 1/2 devtools: script to check meson indentation of lists

In reply to Bruce Richardson

This is a script to fix up minor formatting issues in meson files. It scans for, and can optionally fix, indentation issues and missing trailing commas in the lists in meson.build files. It also detects, and can fix, multi-line lists where more than one entry appears on a line.

---
 devtools/dpdk_meson_check.py | 125 +++++++++++++++++++++++++++++++++++
 1 file changed, 125 insertions(+)
 create mode 100755 devtools/dpdk_meson_check.py
devtools/dpdk_meson_check.py new file +125 -0
new file mode 100755
index 000000000..29f788796
@@ -0,0 +1,125 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2021 Intel Corporation
+
+'''
+A Python script to run some checks on meson.build files in DPDK
+'''
+
+import sys
+import os
+from os.path import relpath, join
+from argparse import ArgumentParser
+
+VERBOSE = False
+
+
+def scan_dir(path):
+    '''return meson.build files found in path'''
+    for root, dirs, files in os.walk(path):
+        if 'meson.build' in files:
+            yield(relpath(join(root, 'meson.build')))
+
+
+def split_code_comments(line):
+    'splits a line into a code part and a comment part, returns (code, comment) tuple'
+    if line.lstrip().startswith('#'):
+        return ('', line)
+    elif '#' in line and '#include' not in line:  # catch 99% of cases, not 100%
+        idx = line.index('#')
+        while (line[idx - 1].isspace()):
+            idx -= 1
+        return line[:idx], line[idx:]
+    else:
+        return (line, '')
+
+
+def setline(contents, index, value):
+    'sets the contents[index] to value. Returns the line, along with code and comments part'
+    line = contents[index] = value
+    code, comments = split_code_comments(line)
+    return line, code, comments
+
+
+def check_indentation(filename, contents):
+    '''check that a list or files() is correctly indented'''
+    infiles = False
+    inlist = False
+    edit_count = 0
+    for lineno, line in enumerate(contents):
+        code, comments = split_code_comments(line)
+        if not code.strip():
+            continue
+        if code.endswith('files('):
+            if infiles:
+                raise(f'Error parsing {filename}:{lineno}, got "files(" when already parsing files list')
+            if inlist:
+                print(f'Error parsing {filename}:{lineno}, got "files(" when already parsing array list')
+            infiles = True
+            indent_count = len(code) - len(code.lstrip(' '))
+            indent = ' ' * (indent_count + 8)  # double indent required
+        elif code.endswith('= ['):
+            if infiles:
+                raise(f'Error parsing {filename}:{lineno}, got start of array when already parsing files list')
+            if inlist:
+                print(f'Error parsing {filename}:{lineno}, got start of array when already parsing array list')
+            inlist = True
+            indent_count = len(code) - len(code.lstrip(' '))
+            indent = ' ' * (indent_count + 8)  # double indent required
+        elif infiles and (code.endswith(')') or code.strip().startswith(')')):
+            infiles = False
+            continue
+        elif inlist and (code.endswith(']') or code.strip().startswith(']')):
+            inlist = False
+            continue
+        elif inlist or infiles:
+            # skip further subarrays or lists
+            if '[' in code or ']' in code:
+                continue
+            if not code.startswith(indent) or code[len(indent)] == ' ':
+                print(f'Error: Incorrect indent at {filename}:{lineno + 1}')
+                line, code, comments = setline(contents, lineno, indent + line.strip())
+                edit_count += 1
+            if not code.endswith(','):
+                print(f'Error: Missing trailing "," in list at {filename}:{lineno + 1}')
+                line, code, comments = setline(contents, lineno, code + ',' + comments)
+                edit_count += 1
+            if len(code.split(',')) > 2:  # only one comma per line
+                print(f'Error: multiple entries per line in list at {filename}:{lineno +1}')
+                entries = [e.strip() for e in code.split(',') if e.strip()]
+                line, code, comments = setline(contents, lineno,
+                                               indent + (',\n' + indent).join(entries) +
+                                               ',' + comments)
+                edit_count += 1
+    return edit_count
+
+
+def process_file(filename, fix):
+    '''run checks on file "filename"'''
+    if VERBOSE:
+        print(f'Processing {filename}')
+    with open(filename) as f:
+        contents = [ln.rstrip() for ln in f.readlines()]
+
+    if check_indentation(filename, contents) > 0 and fix:
+        print(f"Fixing {filename}")
+        with open(filename, 'w') as f:
+            f.writelines([f'{ln}\n' for ln in contents])
+
+
+def main():
+    '''parse arguments and then call other functions to do work'''
+    global VERBOSE
+    parser = ArgumentParser(description='Run syntax checks on DPDK meson.build files')
+    parser.add_argument('-d', metavar='directory', default='.', help='Directory to process')
+    parser.add_argument('--fix', action='store_true', help='Attempt to fix errors')
+    parser.add_argument('-v', action='store_true', help='Verbose output')
+    args = parser.parse_args()
+
+    VERBOSE = args.v
+    for f in scan_dir(args.d):
+        process_file(f, args.fix)
+
+
+if __name__ == "__main__":
+    main()
Signature · 1 line
2.30.2
#10 lore raw

PATCH v2 2/2 build: style fixup on meson files

Running "./devtools/dpdk_meson_check.py --fix" on the DPDK repo fixes a number of issues with whitespace and formatting of files:

* indentation of lists
* missing trailing commas on final list element
* multiple list entries per line when list is not all single-line

---
 app/test-eventdev/meson.build                 |  2 +-
 config/x86/meson.build                        | 24 +++++++++----------
 drivers/bus/fslmc/meson.build                 |  2 +-
 drivers/common/mlx5/meson.build               |  2 +-
 drivers/common/sfc_efx/base/meson.build       |  2 +-
 drivers/common/sfc_efx/meson.build            |  4 ++--
 drivers/compress/mlx5/meson.build             |  2 +-
 drivers/crypto/bcmfs/meson.build              |  2 +-
 drivers/crypto/nitrox/meson.build             |  2 +-
 drivers/crypto/qat/meson.build                |  2 +-
 drivers/net/e1000/base/meson.build            |  2 +-
 drivers/net/fm10k/base/meson.build            |  2 +-
 drivers/net/i40e/base/meson.build             |  2 +-
 drivers/net/ixgbe/base/meson.build            |  2 +-
 drivers/net/octeontx/base/meson.build         |  2 +-
 drivers/net/sfc/meson.build                   |  4 ++--
 drivers/net/thunderx/base/meson.build         |  2 +-
 drivers/raw/skeleton/meson.build              |  2 +-
 examples/l3fwd/meson.build                    | 14 +++++------
 .../client_server_mp/mp_client/meson.build    |  2 +-
 .../client_server_mp/mp_server/meson.build    |  4 +++-
 examples/multi_process/hotplug_mp/meson.build |  3 ++-
 examples/multi_process/simple_mp/meson.build  |  3 ++-
 .../multi_process/symmetric_mp/meson.build    |  2 +-
 lib/mbuf/meson.build                          |  2 +-
 lib/meson.build                               |  6 ++---
 lib/power/meson.build                         |  2 +-
 lib/table/meson.build                         |  2 +-
 28 files changed, 53 insertions(+), 49 deletions(-)
app/test-eventdev/meson.build +1 -1
index 04117dbe4..45c3ff456 100644
@@ -14,6 +14,6 @@ sources = files(
         'test_perf_queue.c',
         'test_pipeline_atq.c',
         'test_pipeline_common.c',
-        'test_pipeline_queue.c'
+        'test_pipeline_queue.c',
 )
 deps += 'eventdev'
config/x86/meson.build +12 -12
index 34b116481..b9348c44d 100644
@@ -22,18 +22,18 @@ foreach f:base_flags
 endforeach
 
 optional_flags = [
-    'AES',
-    'AVX',
-    'AVX2',
-    'AVX512BW',
-    'AVX512CD',
-    'AVX512DQ',
-    'AVX512F',
-    'AVX512VL',
-    'PCLMUL',
-    'RDRND',
-    'RDSEED',
-    'VPCLMULQDQ',
+        'AES',
+        'AVX',
+        'AVX2',
+        'AVX512BW',
+        'AVX512CD',
+        'AVX512DQ',
+        'AVX512F',
+        'AVX512VL',
+        'PCLMUL',
+        'RDRND',
+        'RDSEED',
+        'VPCLMULQDQ',
 ]
 foreach f:optional_flags
     if cc.get_define('__@0@__'.format(f), args: machine_args) == '1'
drivers/bus/fslmc/meson.build +1 -1
index e99218ca7..54be76f51 100644
@@ -21,7 +21,7 @@ sources = files(
         'portal/dpaa2_hw_dpci.c',
         'portal/dpaa2_hw_dpio.c',
         'qbman/qbman_portal.c',
-        'qbman/qbman_debug.c'
+        'qbman/qbman_debug.c',
 )
 
 includes += include_directories('mc', 'qbman/include', 'portal')
drivers/common/mlx5/meson.build +1 -1
index b5585d2cc..e78b4f47b 100644
@@ -23,7 +23,7 @@ cflags_options = [
         '-Wno-strict-prototypes',
         '-D_BSD_SOURCE',
         '-D_DEFAULT_SOURCE',
-        '-D_XOPEN_SOURCE=600'
+        '-D_XOPEN_SOURCE=600',
 ]
 foreach option:cflags_options
     if cc.has_argument(option)
drivers/common/sfc_efx/base/meson.build +1 -1
index 313e53d77..9fba47b1c 100644
@@ -70,7 +70,7 @@ extra_flags = [
         '-Wno-unused-parameter',
         '-Wno-unused-variable',
         '-Wno-empty-body',
-        '-Wno-unused-but-set-variable'
+        '-Wno-unused-but-set-variable',
 ]
 
 c_args = cflags
drivers/common/sfc_efx/meson.build +2 -2
index d87ba396b..f42ccf609 100644
@@ -19,13 +19,13 @@ extra_flags = []
 
 # Enable more warnings
 extra_flags += [
-        '-Wdisabled-optimization'
+        '-Wdisabled-optimization',
 ]
 
 # Compiler and version dependent flags
 extra_flags += [
         '-Waggregate-return',
-        '-Wbad-function-cast'
+        '-Wbad-function-cast',
 ]
 
 foreach flag: extra_flags
drivers/compress/mlx5/meson.build +1 -1
index c5c5edfa7..7aac32998 100644
@@ -17,7 +17,7 @@ cflags_options = [
         '-Wno-strict-prototypes',
         '-D_BSD_SOURCE',
         '-D_DEFAULT_SOURCE',
-        '-D_XOPEN_SOURCE=600'
+        '-D_XOPEN_SOURCE=600',
 ]
 foreach option:cflags_options
     if cc.has_argument(option)
drivers/crypto/bcmfs/meson.build +1 -1
index 0388ba19a..d67e78d51 100644
@@ -16,5 +16,5 @@ sources = files(
         'bcmfs_sym_capabilities.c',
         'bcmfs_sym_session.c',
         'bcmfs_sym.c',
-        'bcmfs_sym_engine.c'
+        'bcmfs_sym_engine.c',
 )
drivers/crypto/nitrox/meson.build +1 -1
index 2fdae03c1..2cc47c462 100644
@@ -14,5 +14,5 @@ sources = files(
         'nitrox_sym.c',
         'nitrox_sym_capabilities.c',
         'nitrox_sym_reqmgr.c',
-        'nitrox_qp.c'
+        'nitrox_qp.c',
 )
drivers/crypto/qat/meson.build +1 -1
index 4da819d65..b3b2d1725 100644
@@ -17,7 +17,7 @@ if dep.found()
             'qat_asym_pmd.c',
             'qat_sym.c',
             'qat_sym_hw_dp.c',
-			'qat_sym_pmd.c',
+            'qat_sym_pmd.c',
             'qat_sym_session.c',
 	)
     qat_ext_deps += dep
drivers/net/e1000/base/meson.build +1 -1
index 99468764e..317692dfa 100644
@@ -19,7 +19,7 @@ sources = [
         'e1000_nvm.c',
         'e1000_osdep.c',
         'e1000_phy.c',
-        'e1000_vf.c'
+        'e1000_vf.c',
 ]
 
 error_cflags = ['-Wno-uninitialized', '-Wno-unused-parameter',
drivers/net/fm10k/base/meson.build +1 -1
index 6467a1278..ca98d34d4 100644
@@ -7,7 +7,7 @@ sources = [
         'fm10k_mbx.c',
         'fm10k_pf.c',
         'fm10k_tlv.c',
-        'fm10k_vf.c'
+        'fm10k_vf.c',
 ]
 
 error_cflags = ['-Wno-unused-parameter', '-Wno-unused-value',
drivers/net/i40e/base/meson.build +1 -1
index c319902cd..79a887a29 100644
@@ -8,7 +8,7 @@ sources = [
         'i40e_diag.c',
         'i40e_hmc.c',
         'i40e_lan_hmc.c',
-        'i40e_nvm.c'
+        'i40e_nvm.c',
 ]
 
 error_cflags = ['-Wno-sign-compare', '-Wno-unused-value',
drivers/net/ixgbe/base/meson.build +1 -1
index 4d5e41bde..7d3cec002 100644
@@ -14,7 +14,7 @@ sources = [
         'ixgbe_phy.c',
         'ixgbe_vf.c',
         'ixgbe_x540.c',
-        'ixgbe_x550.c'
+        'ixgbe_x550.c',
 ]
 
 error_cflags = ['-Wno-unused-value',
drivers/net/octeontx/base/meson.build +1 -1
index 0a69dfd46..c86a72670 100644
@@ -4,7 +4,7 @@
 sources = [
         'octeontx_pkovf.c',
         'octeontx_pkivf.c',
-        'octeontx_bgx.c'
+        'octeontx_bgx.c',
 ]
 
 depends = ['ethdev', 'mempool_octeontx']
drivers/net/sfc/meson.build +2 -2
index b58425bf9..ccf5984d8 100644
@@ -24,13 +24,13 @@ extra_flags += '-Wno-strict-aliasing'
 
 # Enable more warnings
 extra_flags += [
-        '-Wdisabled-optimization'
+        '-Wdisabled-optimization',
 ]
 
 # Compiler and version dependent flags
 extra_flags += [
         '-Waggregate-return',
-        '-Wbad-function-cast'
+        '-Wbad-function-cast',
 ]
 
 foreach flag: extra_flags
drivers/net/thunderx/base/meson.build +1 -1
index 9cf4bf553..704ee6577 100644
@@ -4,7 +4,7 @@
 sources = [
         'nicvf_hw.c',
         'nicvf_mbox.c',
-        'nicvf_bsvf.c'
+        'nicvf_bsvf.c',
 ]
 
 c_args = cflags
drivers/raw/skeleton/meson.build +1 -1
index b5d87652f..950a33cc2 100644
@@ -3,6 +3,6 @@
 
 deps += ['rawdev', 'kvargs', 'mbuf', 'bus_vdev']
 sources = files(
-		'skeleton_rawdev.c',
+        'skeleton_rawdev.c',
         'skeleton_rawdev_test.c',
 )
examples/l3fwd/meson.build +7 -7
index 773ebf478..0830b3eb3 100644
@@ -9,11 +9,11 @@
 allow_experimental_apis = true
 deps += ['hash', 'lpm', 'fib', 'eventdev']
 sources = files(
-    'l3fwd_em.c',
-    'l3fwd_event.c',
-    'l3fwd_event_internal_port.c',
-    'l3fwd_event_generic.c',
-    'l3fwd_fib.c',
-    'l3fwd_lpm.c',
-    'main.c',
+        'l3fwd_em.c',
+        'l3fwd_event.c',
+        'l3fwd_event_internal_port.c',
+        'l3fwd_event_generic.c',
+        'l3fwd_fib.c',
+        'l3fwd_lpm.c',
+        'main.c',
 )
examples/multi_process/client_server_mp/mp_client/meson.build +1 -1
index 3c4848bde..c7190b212 100644
@@ -10,5 +10,5 @@ includes += include_directories('../shared')
 
 allow_experimental_apis = true
 sources = files(
-        'client.c'
+        'client.c',
 )
examples/multi_process/client_server_mp/mp_server/meson.build +3 -1
index 74814e5fe..9e585e80b 100644
@@ -10,5 +10,7 @@ includes += include_directories('../shared')
 
 allow_experimental_apis = true
 sources = files(
-        'args.c', 'init.c', 'main.c'
+        'args.c',
+        'init.c',
+        'main.c',
 )
examples/multi_process/hotplug_mp/meson.build +2 -1
index ae9290504..a1ad98ca2 100644
@@ -8,5 +8,6 @@
 
 allow_experimental_apis = true
 sources = files(
-        'commands.c', 'main.c'
+        'commands.c',
+        'main.c',
 )
examples/multi_process/simple_mp/meson.build +2 -1
index adb06b0a7..359af4384 100644
@@ -8,5 +8,6 @@
 
 allow_experimental_apis = true
 sources = files(
-        'mp_commands.c', 'main.c'
+        'mp_commands.c',
+        'main.c',
 )
examples/multi_process/symmetric_mp/meson.build +1 -1
index a5b988c44..e768a324d 100644
@@ -8,5 +8,5 @@
 
 allow_experimental_apis = true
 sources = files(
-        'main.c'
+        'main.c',
 )
lib/mbuf/meson.build +1 -1
index c8c08220a..0435c5e62 100644
@@ -12,6 +12,6 @@ headers = files(
         'rte_mbuf_core.h',
         'rte_mbuf_ptype.h',
         'rte_mbuf_pool_ops.h',
-        'rte_mbuf_dyn.h'
+        'rte_mbuf_dyn.h',
 )
 deps += ['mempool']
lib/meson.build +3 -3
index c9a20f65b..64a59abab 100644
@@ -82,9 +82,9 @@ if is_windows
 endif
 
 optional_libs = [
-    'kni',
-    'power',
-    'vhost',
+        'kni',
+        'power',
+        'vhost',
 ]
 
 disabled_libs = []
lib/power/meson.build +1 -1
index a2cc9fe2e..c1097d32f 100644
@@ -19,6 +19,6 @@ headers = files(
         'rte_power.h',
         'rte_power_empty_poll.h',
         'rte_power_pmd_mgmt.h',
-        'rte_power_guest_channel.h'
+        'rte_power_guest_channel.h',
 )
 deps += ['timer', 'ethdev']
lib/table/meson.build +1 -1
index 230f21ea8..b7b70b805 100644
@@ -36,5 +36,5 @@ deps += ['mbuf', 'port', 'lpm', 'hash', 'acl']
 indirect_headers += files(
         'rte_lru_arm64.h',
         'rte_lru_x86.h',
-        'rte_table_hash_func_arm64.h'
+        'rte_table_hash_func_arm64.h',
 )
Signature · 1 line
2.30.2
#11 lore raw

Re: [dpdk-dev] [PATCH v2 1/2] devtools: script to check meson indentation of lists

In reply to Bruce Richardson
Quoted 8 lines · Bruce Richardson

This is a script to fix up minor formatting issues in meson files. It scans for, and can optionally fix, indentation issues and missing trailing commas in the lists in meson.build files. It also detects, and can fix, multi-line lists where more than one entry appears on a line.

---

<snip>

devtools/dpdk_meson_check.py line 32

Quoted 8 lines
devtools/dpdk_meson_check.py new file +8 -0
+def split_code_comments(line):
+    'splits a line into a code part and a comment part, returns (code, comment) tuple'
+    if line.lstrip().startswith('#'):
+        return ('', line)
+    elif '#' in line and '#include' not in line:  # catch 99% of cases, not 100% > +        idx = line.index('#')
+        while (line[idx - 1].isspace()):
+            idx -= 1
+        return line[:idx], line[idx:]

I think this could be simplified with regex:

# find any occurrences of '#' but only if it's not an '#include'
if not re.search(r'#(?!include)', line)
    return line, ''
return line.split('#', maxsplit=1)
Quoted 8 lines
devtools/dpdk_meson_check.py new file +8 -0
+    else:
+        return (line, '')
+
+
+def setline(contents, index, value):
+    'sets the contents[index] to value. Returns the line, along with code and comments part'
+    line = contents[index] = value
+    code, comments = split_code_comments(line)

devtools/dpdk_meson_check.py line 50

Quoted 10 lines
devtools/dpdk_meson_check.py new file +10 -0
+    return line, code, comments
+
+
+def check_indentation(filename, contents):
+    '''check that a list or files() is correctly indented'''
+    infiles = False
+    inlist = False
+    edit_count = 0
+    for lineno, line in enumerate(contents):
+        code, comments = split_code_comments(line)

Nitpicking, but maybe instead of calling strip() all over the place, just count the number of spaces and strip right at the outset? E.g. something like:

stripped = code.strip()
line_indent = len(code) - len(stripped)

You can then reason about indent levels by comparing stripped to code afterwards, and avoid doing this:

devtools/dpdk_meson_check.py line 79

Quoted 4 lines
devtools/dpdk_meson_check.py new file +4 -0
+            # skip further subarrays or lists
+            if '[' in code or ']' in code:
+                continue
+            if not code.startswith(indent) or code[len(indent)] == ' ':

Opting to just check the indent size you calculated initially. Unless i'm missing something :)

You could also increment edit_count if calculated indent + stripped is equal to code. Seems easier logic than raw string manipulation you're going for here...

<snip>

devtools/dpdk_meson_check.py line 102

Quoted 6 lines
devtools/dpdk_meson_check.py new file +6 -0
+def process_file(filename, fix):
+    '''run checks on file "filename"'''
+    if VERBOSE:
+        print(f'Processing {filename}')
+    with open(filename) as f:
+        contents = [ln.rstrip() for ln in f.readlines()]

So any trailing whitespace gets automatically and silently fixed?

devtools/dpdk_meson_check.py line 107

Quoted 5 lines
devtools/dpdk_meson_check.py new file +5 -0
+
+    if check_indentation(filename, contents) > 0 and fix:
+        print(f"Fixing {filename}")
+        with open(filename, 'w') as f:
+            f.writelines([f'{ln}\n' for ln in contents])

Something seems suspect here. So, if fix is *not* specified, the script just opens the file, reads it, and... does nothing else?

Signature · 2 lines
Thanks,
Anatoly
#12 lore raw

Re: [dpdk-dev] [PATCH v2 1/2] devtools: script to check meson indentation of lists

Quoted 22 lines · Anatoly
Quoted 8 lines · Bruce Richardson

This is a script to fix up minor formatting issues in meson files. It scans for, and can optionally fix, indentation issues and missing trailing commas in the lists in meson.build files. It also detects, and can fix, multi-line lists where more than one entry appears on a line.

---

<snip>

devtools/dpdk_meson_check.py line 32

Quoted 8 lines
devtools/dpdk_meson_check.py new file +8 -0
+def split_code_comments(line):
+    'splits a line into a code part and a comment part, returns (code, comment) tuple'
+    if line.lstrip().startswith('#'):
+        return ('', line)
+    elif '#' in line and '#include' not in line:  # catch 99% of cases, not 100% > +        idx = line.index('#')
+        while (line[idx - 1].isspace()):
+            idx -= 1
+        return line[:idx], line[idx:]
Quoted 6 lines

I think this could be simplified with regex:

# find any occurrences of '#' but only if it's not an '#include'
if not re.search(r'#(?!include)', line)
    return line, ''
return line.split('#', maxsplit=1)

Not sure that is simpler, and just splitting on '#' is actually not what we want either.

Firstly, while r'#(?!include)' is not a massively complex regex, just checking for "'#' in line and '#include' not in line" is just easier to read for most mortals.

In terms of the split, I did initially do as you have here and split on '#', but we don't actually want that, because we want to preserve the whitespace in the line before the comment too - as part of the comment, not the code. This is why after finding the '#' we walk backwards to find the end of the code and find that as the split point. It then saves us worrying about any strips() breaking any comment alignment the user has explicitly set up. Not using split also means that we can just merge the strings back with '+' rather than having to use "'#'.join()".

Quoted 35 lines
Quoted 9 lines
devtools/dpdk_meson_check.py new file +8 -0
+    else:
+        return (line, '')
+
+
+def setline(contents, index, value):
+    'sets the contents[index] to value. Returns the line, along with code and comments part'
+    line = contents[index] = value
+    code, comments = split_code_comments(line)

devtools/dpdk_meson_check.py line 50

Quoted 10 lines
devtools/dpdk_meson_check.py new file +10 -0
+    return line, code, comments
+
+
+def check_indentation(filename, contents):
+    '''check that a list or files() is correctly indented'''
+    infiles = False
+    inlist = False
+    edit_count = 0
+    for lineno, line in enumerate(contents):
+        code, comments = split_code_comments(line)

Nitpicking, but maybe instead of calling strip() all over the place, just count the number of spaces and strip right at the outset? E.g. something like:

stripped = code.strip()
line_indent = len(code) - len(stripped)

You can then reason about indent levels by comparing stripped to code afterwards, and avoid doing this:

devtools/dpdk_meson_check.py line 79

Quoted 4 lines
devtools/dpdk_meson_check.py new file +4 -0
+            # skip further subarrays or lists
+            if '[' in code or ']' in code:
+                continue
+            if not code.startswith(indent) or code[len(indent)] == ' ':
Quoted 8 lines

Opting to just check the indent size you calculated initially. Unless i'm missing something :)

You could also increment edit_count if calculated indent + stripped is equal to code. Seems easier logic than raw string manipulation you're going for here...

<snip>

Interesting. That could be a good approach alright. If I do a V3 (not guaranteed for this release) I can try taking that idea on board.

Quoted 10 lines

devtools/dpdk_meson_check.py line 102

Quoted 7 lines
devtools/dpdk_meson_check.py new file +6 -0
+def process_file(filename, fix):
+    '''run checks on file "filename"'''
+    if VERBOSE:
+        print(f'Processing {filename}')
+    with open(filename) as f:
+        contents = [ln.rstrip() for ln in f.readlines()]

So any trailing whitespace gets automatically and silently fixed?

Hadn't actually thought of that, but yes, that will happen if --fix is given and other changes are made to the file. Ideally, that should be fixed to "non-silently" do so, but I'd view it as low priority since other tools tend to be good at flagging trailing whitespace issues anyway.

Quoted 9 lines

devtools/dpdk_meson_check.py line 107

Quoted 5 lines
devtools/dpdk_meson_check.py new file +5 -0
+
+    if check_indentation(filename, contents) > 0 and fix:
+        print(f"Fixing {filename}")
+        with open(filename, 'w') as f:
+            f.writelines([f'{ln}\n' for ln in contents])

Something seems suspect here. So, if fix is *not* specified, the script just opens the file, reads it, and... does nothing else?

No, it prints out all the errors without actually fixing them.

Regards,
/Bruce

Reviewed-by
#13 lore raw

Re: [dpdk-dev] [PATCH v2 1/2] devtools: script to check meson indentation of lists

Quoted 37 lines · Bruce Richardson
Quoted 22 lines · Anatoly
Quoted 8 lines · Bruce Richardson

This is a script to fix up minor formatting issues in meson files. It scans for, and can optionally fix, indentation issues and missing trailing commas in the lists in meson.build files. It also detects, and can fix, multi-line lists where more than one entry appears on a line.

---

<snip>

devtools/dpdk_meson_check.py line 32

Quoted 8 lines
devtools/dpdk_meson_check.py new file +8 -0
+def split_code_comments(line):
+    'splits a line into a code part and a comment part, returns (code, comment) tuple'
+    if line.lstrip().startswith('#'):
+        return ('', line)
+    elif '#' in line and '#include' not in line:  # catch 99% of cases, not 100% > +        idx = line.index('#')
+        while (line[idx - 1].isspace()):
+            idx -= 1
+        return line[:idx], line[idx:]
Quoted 6 lines

I think this could be simplified with regex:

# find any occurrences of '#' but only if it's not an '#include'
if not re.search(r'#(?!include)', line)
     return line, ''
return line.split('#', maxsplit=1)

Not sure that is simpler, and just splitting on '#' is actually not what we want either.

Firstly, while r'#(?!include)' is not a massively complex regex, just checking for "'#' in line and '#include' not in line" is just easier to read for most mortals.

Quoted 8 lines

In terms of the split, I did initially do as you have here and split on '#', but we don't actually want that, because we want to preserve the whitespace in the line before the comment too - as part of the comment, not the code. This is why after finding the '#' we walk backwards to find the end of the code and find that as the split point. It then saves us worrying about any strips() breaking any comment alignment the user has explicitly set up. Not using split also means that we can just merge the strings back with '+' rather than having to use "'#'.join()".

Fair enough so!

Quoted 56 lines
Quoted 36 lines
Quoted 10 lines
devtools/dpdk_meson_check.py new file +8 -0
+    else:
+        return (line, '')
+
+
+def setline(contents, index, value):
+    'sets the contents[index] to value. Returns the line, along with code and comments part'
+    line = contents[index] = value
+    code, comments = split_code_comments(line)

devtools/dpdk_meson_check.py line 50

Quoted 10 lines
devtools/dpdk_meson_check.py new file +10 -0
+    return line, code, comments
+
+
+def check_indentation(filename, contents):
+    '''check that a list or files() is correctly indented'''
+    infiles = False
+    inlist = False
+    edit_count = 0
+    for lineno, line in enumerate(contents):
+        code, comments = split_code_comments(line)

Nitpicking, but maybe instead of calling strip() all over the place, just count the number of spaces and strip right at the outset? E.g. something like:

stripped = code.strip()
line_indent = len(code) - len(stripped)

You can then reason about indent levels by comparing stripped to code afterwards, and avoid doing this:

devtools/dpdk_meson_check.py line 79

Quoted 4 lines
devtools/dpdk_meson_check.py new file +4 -0
+            # skip further subarrays or lists
+            if '[' in code or ']' in code:
+                continue
+            if not code.startswith(indent) or code[len(indent)] == ' ':
Quoted 8 lines

Opting to just check the indent size you calculated initially. Unless i'm missing something :)

You could also increment edit_count if calculated indent + stripped is equal to code. Seems easier logic than raw string manipulation you're going for here...

<snip>

Interesting. That could be a good approach alright. If I do a V3 (not guaranteed for this release) I can try taking that idea on board.

Quoted 8 lines
Quoted 7 lines
devtools/dpdk_meson_check.py new file +6 -0
+def process_file(filename, fix):
+    '''run checks on file "filename"'''
+    if VERBOSE:
+        print(f'Processing {filename}')
+    with open(filename) as f:
+        contents = [ln.rstrip() for ln in f.readlines()]
Quoted 6 lines
Quoted 2 lines

So any trailing whitespace gets automatically and silently fixed?

Hadn't actually thought of that, but yes, that will happen if --fix is given and other changes are made to the file. Ideally, that should be fixed to "non-silently" do so, but I'd view it as low priority since other tools tend to be good at flagging trailing whitespace issues anyway.

Yeah, i think there's not a lot of trailing whitespace there in the first place, so probably a non issue.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
devtools/dpdk_meson_check.py new file +5 -0
+
+    if check_indentation(filename, contents) > 0 and fix:
+        print(f"Fixing {filename}")
+        with open(filename, 'w') as f:
+            f.writelines([f'{ln}\n' for ln in contents])
Quoted 5 lines
Quoted 3 lines

Something seems suspect here. So, if fix is *not* specified, the script just opens the file, reads it, and... does nothing else?

No, it prints out all the errors without actually fixing them.

Oh, right, check_indentation will run first. Never mind!

In any case,

Signature · 2 lines
Thanks,
Anatoly
#14 lore raw

Re: [dpdk-dev] [PATCH v2 1/2] devtools: script to check meson indentation of lists

In reply to Bruce Richardson

26/04/2021 12:54, Bruce Richardson:

Quoted 9 lines

This is a script to fix up minor formatting issues in meson files. It scans for, and can optionally fix, indentation issues and missing trailing commas in the lists in meson.build files. It also detects, and can fix, multi-line lists where more than one entry appears on a line.

---
 devtools/dpdk_meson_check.py | 125 +++++++++++++++++++++++++++++++++++

Renamed to check-meson.py and added in MAINTAINERS.

Series applied, thanks.

#15 lore raw

Re: [dpdk-dev] [PATCH v2 1/2] devtools: script to check meson indentation of lists

Quoted 8 lines · Thomas Monjalon

26/04/2021 12:54, Bruce Richardson:

Quoted 6 lines

This is a script to fix up minor formatting issues in meson files. It scans for, and can optionally fix, indentation issues and missing trailing commas in the lists in meson.build files. It also detects, and can fix, multi-line lists where more than one entry appears on a line.

Quoted 7 lines
Quoted 3 lines
---
 devtools/dpdk_meson_check.py | 125 +++++++++++++++++++++++++++++++++++

Renamed to check-meson.py and added in MAINTAINERS.

Series applied, thanks.

The default behavior is not that friendly (to me).
I have build directories in my sources with stuff from older branches where the coding fixes are not backported.
This results in the check complaining on all those directories.

Can we have a default behavior where only committed files are considered? Maybe filtering with git ls-files **/meson.build.

Signature · 1 line
David Marchand