From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id D9662A04DD; Tue, 21 Jan 2020 14:37:45 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8D4B91252; Tue, 21 Jan 2020 14:37:45 +0100 (CET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 8381911A4 for ; Tue, 21 Jan 2020 14:37:43 +0100 (CET) X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Jan 2020 05:37:42 -0800 X-IronPort-AV: E=Sophos;i="5.70,346,1574150400"; d="scan'208";a="219954995" Received: from bricha3-mobl.ger.corp.intel.com ([10.237.221.97]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 21 Jan 2020 05:37:40 -0800 Date: Tue, 21 Jan 2020 13:37:37 +0000 From: Bruce Richardson To: Robin Jarry Cc: dev@dpdk.org, thomas@monjalon.net Message-ID: <20200121133737.GE1747@bricha3-MOBL.ger.corp.intel.com> References: <20200120173725.57529-1-bruce.richardson@intel.com> <20200121111228.5591-1-bruce.richardson@intel.com> <20200121132238.zukav3ysrl3ijpor@6wind.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200121132238.zukav3ysrl3ijpor@6wind.com> User-Agent: Mutt/1.12.1 (2019-06-15) Subject: Re: [dpdk-dev] [PATCH v2] build: allow using wildcards to disable drivers X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 > [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