[v2] build: allow using wildcards to disable drivers

Message ID 20200121111228.5591-1-bruce.richardson@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] build: allow using wildcards to disable drivers |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-nxp-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed

Commit Message

Bruce Richardson Jan. 21, 2020, 11:12 a.m. UTC
  Rather than having to explicitly list each and every driver to disable in a
build, we can use a small python script and the python glob library to
expand out the wildcards. This means that we can configure meson using e.g.

    meson -Ddisable_drivers=crypto/*,event/* build

to do a build omitting all the crypto and event drivers. Explicitly
specified drivers e.g. net/i40e, work as before, and can be mixed with
wildcarded drivers as required.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---

V2:
- fixed file suffix
- since it's being called from meson, make this python3 only
- remove use of chdir()
- use '\n' rather than ',' between entries
---
 buildtools/list-dir-globs.py | 13 +++++++++++++
 buildtools/meson.build       |  2 +-
 drivers/meson.build          |  3 ++-
 3 files changed, 16 insertions(+), 2 deletions(-)
 create mode 100755 buildtools/list-dir-globs.py
  

Comments

Robin Jarry Jan. 21, 2020, 1:22 p.m. UTC | #1
2020-01-21, Bruce Richardson:
> Rather than having to explicitly list each and every driver to disable in a
> build, we can use a small python script and the python glob library to
> expand out the wildcards. This means that we can configure meson using e.g.
> 
>     meson -Ddisable_drivers=crypto/*,event/* build
> 
> to do a build omitting all the crypto and event drivers. Explicitly
> specified drivers e.g. net/i40e, work as before, and can be mixed with
> wildcarded drivers as required.
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
[snip]
> +++ b/buildtools/list-dir-globs.py
> @@ -0,0 +1,13 @@
> +#! /usr/bin/env python3
> +# SPDX-License-Identifier: BSD-3-Clause
> +# Copyright(c) 2020 Intel Corporation
> +
> +import sys
> +import os
> +from glob import iglob # glob iterator

No need to make it explicit. People can read the description in the
official docs.

> +from os.path import join, relpath, isdir

You already imported 'os'. These functions are available under the
'os.path' namespace. No need to import them again.

> +root = join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR'])
> +for path in sys.argv[1].split(','):

Directly accessing sys.argv exposes you to ugly errors when the script
is called with the wrong number of arguments. It would be better to use
argparse which will handle the error reporting for you.

> +  relpaths = [relpath(p, root) for p in iglob(join(root, path)) if isdir(p)]
> +  print("\n".join(relpaths))

Using one-liner syntax like these really makes the code hard to
understand. Explicit for loops with explicit if tests would be a lot
nicer.

Also, why use an intermediate variable to then, join each element with
'\n' and print that? You can print the matching dirs as you iterate over
them.

Have a look at my previous reply for a complete example of what I mean.
  
Bruce Richardson Jan. 21, 2020, 1:37 p.m. UTC | #2
On Tue, Jan 21, 2020 at 02:22:38PM +0100, Robin Jarry wrote:
> 2020-01-21, Bruce Richardson:
> > Rather than having to explicitly list each and every driver to disable in a
> > build, we can use a small python script and the python glob library to
> > expand out the wildcards. This means that we can configure meson using e.g.
> > 
> >     meson -Ddisable_drivers=crypto/*,event/* build
> > 
> > to do a build omitting all the crypto and event drivers. Explicitly
> > specified drivers e.g. net/i40e, work as before, and can be mixed with
> > wildcarded drivers as required.
> > 
> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> [snip]
> > +++ b/buildtools/list-dir-globs.py
> > @@ -0,0 +1,13 @@
> > +#! /usr/bin/env python3
> > +# SPDX-License-Identifier: BSD-3-Clause
> > +# Copyright(c) 2020 Intel Corporation
> > +
> > +import sys
> > +import os
> > +from glob import iglob # glob iterator
> 
> No need to make it explicit. People can read the description in the
> official docs.

Except the fact that you yourself mistook it for a case-insensitive glob
implies that a comment is needed! :-)

> 
> > +from os.path import join, relpath, isdir
> 
> You already imported 'os'. These functions are available under the
> 'os.path' namespace. No need to import them again.
> 

Yes, using more words. Simpler syntax to call join() and isdir() rather
than os.path.join(), os.path.isdir()

> > +root = join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR'])
> > +for path in sys.argv[1].split(','):
> 
> Directly accessing sys.argv exposes you to ugly errors when the script
> is called with the wrong number of arguments. It would be better to use
> argparse which will handle the error reporting for you.

This is script is to be called from the build system. I'm not worried about
incorrect numbers of args, and argparse itself seems overkill. I'll add a
check to print an error if len(argv) != 1.

> 
> > +  relpaths = [relpath(p, root) for p in iglob(join(root, path)) if isdir(p)]
> > +  print("\n".join(relpaths))
> 
> Using one-liner syntax like these really makes the code hard to
> understand. Explicit for loops with explicit if tests would be a lot
> nicer.
> 
> Also, why use an intermediate variable to then, join each element with
> '\n' and print that? You can print the matching dirs as you iterate over
> them.
> 
> Have a look at my previous reply for a complete example of what I mean.
> 

Just keeping the code short. I actually had originally got the print join
in the same line as the list comprehension but that even I felt was a bit
unreadable - even if it did leave a nice short script!
I'll expand to explicit for loop in V3.

/Bruce
  
Robin Jarry Jan. 21, 2020, 1:48 p.m. UTC | #3
2020-01-21, Bruce Richardson:
> > > +from glob import iglob # glob iterator
> > 
> > No need to make it explicit. People can read the description in the
> > official docs.
> 
> Except the fact that you yourself mistook it for a case-insensitive glob
> implies that a comment is needed! :-)

The fact that I should check things before I make comments should not
force people to add comments next to imports :-)

> This is script is to be called from the build system. I'm not worried about
> incorrect numbers of args, and argparse itself seems overkill. I'll add a
> check to print an error if len(argv) != 1.

Fair enough. However, argparse is never overkill. Using it is not going
to slow down your script.

> Just keeping the code short. I actually had originally got the print join
> in the same line as the list comprehension but that even I felt was a bit
> unreadable - even if it did leave a nice short script!

This is not perl^Wa competition :-)
  

Patch

diff --git a/buildtools/list-dir-globs.py b/buildtools/list-dir-globs.py
new file mode 100755
index 000000000..3019f5999
--- /dev/null
+++ b/buildtools/list-dir-globs.py
@@ -0,0 +1,13 @@ 
+#! /usr/bin/env python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2020 Intel Corporation
+
+import sys
+import os
+from glob import iglob # glob iterator
+from os.path import join, relpath, isdir
+
+root = join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR'])
+for path in sys.argv[1].split(','):
+  relpaths = [relpath(p, root) for p in iglob(join(root, path)) if isdir(p)]
+  print("\n".join(relpaths))
diff --git a/buildtools/meson.build b/buildtools/meson.build
index cd1d05403..0f563d89a 100644
--- a/buildtools/meson.build
+++ b/buildtools/meson.build
@@ -4,7 +4,7 @@ 
 subdir('pmdinfogen')
 
 pmdinfo = find_program('gen-pmdinfo-cfile.sh')
-
+list_dir_globs = find_program('list-dir-globs.py')
 check_experimental_syms = find_program('check-experimental-syms.sh')
 
 # set up map-to-def script using python, either built-in or external
diff --git a/drivers/meson.build b/drivers/meson.build
index 29708cc2b..3ee998d80 100644
--- a/drivers/meson.build
+++ b/drivers/meson.build
@@ -17,7 +17,8 @@  dpdk_driver_classes = ['common',
 	       'event',   # depends on common, bus, mempool and net.
 	       'baseband'] # depends on common and bus.
 
-disabled_drivers = get_option('disable_drivers').split(',')
+disabled_drivers = run_command(list_dir_globs, get_option('disable_drivers'),
+		).stdout().split()
 
 default_cflags = machine_args
 if cc.has_argument('-Wno-format-truncation')