[dpdk-dev] [PATCH v2] build: allow using wildcards to disable drivers

Bruce Richardson bruce.richardson at intel.com
Tue Jan 21 14:37:37 CET 2020


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 at 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


More information about the dev mailing list