[v3] build: allow using wildcards to disable drivers

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

Checks

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

Commit Message

Bruce Richardson Jan. 24, 2020, 10:32 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>
---

V3:
- added check for correct number of params
- replaced list comprehension with loops for simplicity
- allow running without meson environmental vars set (for easier testing)

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 | 21 +++++++++++++++++++++
 buildtools/meson.build       |  2 +-
 drivers/meson.build          |  3 ++-
 3 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100755 buildtools/list-dir-globs.py
  

Comments

Robin Jarry Jan. 24, 2020, 12:28 p.m. UTC | #1
2020-01-24, 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]
> +from os.path import join, relpath, isdir

As a general rule, it is better to only import one symbol per line. This
makes subsequent patches easier to read.

> +if len(sys.argv) != 2:
> +  print("Usage: {0} <path-glob>[,<path-glob>[,...]]".format(sys.argv[0]))
> +  sys.exit(1)

PEP8 advises to use 4 spaces per indentation level. This is the
indentation style adopted by all other python scripts in dpdk (see
doc/guides/contributing/coding_style.rst). Could you fix that?

> +root = '.'
> +if 'MESON_SOURCE_ROOT' in os.environ and 'MESON_SUBDIR' in os.environ:
> +  root = join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR'])

You can do simpler and shorter:

  root = join(os.getenv('MESON_SOURCE_ROOT', ''),
              os.getenv('MESON_SUBDIR', ''), '.')

Sorry to pester you with all this, but python code in DPDK really needs
some loving :-)
  
Bruce Richardson Jan. 24, 2020, 2:57 p.m. UTC | #2
> -----Original Message-----
> From: Robin Jarry <robin.jarry@6wind.com>
> Sent: Friday, January 24, 2020 12:28 PM
> To: Richardson, Bruce <bruce.richardson@intel.com>
> Cc: dev@dpdk.org; thomas@monjalon.net
> Subject: Re: [PATCH v3] build: allow using wildcards to disable drivers
> 
> 2020-01-24, 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]
> > +from os.path import join, relpath, isdir
> 
> As a general rule, it is better to only import one symbol per line. This
> makes subsequent patches easier to read.
> 
> > +if len(sys.argv) != 2:
> > +  print("Usage: {0}
> > +<path-glob>[,<path-glob>[,...]]".format(sys.argv[0]))
> > +  sys.exit(1)
> 
> PEP8 advises to use 4 spaces per indentation level. This is the
> indentation style adopted by all other python scripts in dpdk (see
> doc/guides/contributing/coding_style.rst). Could you fix that?
> 
> > +root = '.'
> > +if 'MESON_SOURCE_ROOT' in os.environ and 'MESON_SUBDIR' in os.environ:
> > +  root = join(os.environ['MESON_SOURCE_ROOT'],
> > +os.environ['MESON_SUBDIR'])
> 
> You can do simpler and shorter:
> 
>   root = join(os.getenv('MESON_SOURCE_ROOT', ''),
>               os.getenv('MESON_SUBDIR', ''), '.')

I think a little shorter again by putting the '.' as the default value for one of the env vars.


> 
> Sorry to pester you with all this, but python code in DPDK really needs
> some loving :-)
> 
> --
> Robin
  

Patch

diff --git a/buildtools/list-dir-globs.py b/buildtools/list-dir-globs.py
new file mode 100755
index 000000000..b9a536869
--- /dev/null
+++ b/buildtools/list-dir-globs.py
@@ -0,0 +1,21 @@ 
+#! /usr/bin/env python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2020 Intel Corporation
+
+import sys
+import os
+from glob import iglob
+from os.path import join, relpath, isdir
+
+if len(sys.argv) != 2:
+  print("Usage: {0} <path-glob>[,<path-glob>[,...]]".format(sys.argv[0]))
+  sys.exit(1)
+
+root = '.'
+if 'MESON_SOURCE_ROOT' in os.environ and 'MESON_SUBDIR' in os.environ:
+  root = join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR'])
+
+for path in sys.argv[1].split(','):
+  for p in iglob(join(root, path)):
+    if isdir(p):
+      print(relpath(p))
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')