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.richard...@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.

-- 
Robin

Reply via email to