Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0E1BBC001DC for ; Wed, 19 Jul 2023 23:51:29 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BC4CE867CE; Thu, 20 Jul 2023 01:50:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="ZivQZOmm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0F5A7867B6; Thu, 20 Jul 2023 01:50:12 +0200 (CEST) Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DA2D18679A for ; Thu, 20 Jul 2023 01:50:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-3489cd4e3d3so1570745ab.3 for ; Wed, 19 Jul 2023 16:50:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1689810603; x=1690415403; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Lq4ayIgP2hep7i3ggVsf0IItV0+RIVpTYyQYH+t8Nj8=; b=ZivQZOmm2ESEP3wOvSaCv2DG+s+x5crvIJbXNmF6Tv+QENq56whnIiW3btHSyU1Np4 2iWsnnkBZycVHkKOqHDo7QejT74FN2lsnbCuYgxfr/R87QCwteQtCmGYWvkWdkswWWJj CxayYyiSkuLVEX3JF6mGrK8xLv2jybtix0Cvw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689810603; x=1690415403; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Lq4ayIgP2hep7i3ggVsf0IItV0+RIVpTYyQYH+t8Nj8=; b=DBqUbEwgaV1lc8uUVsqDbV1r6RBweSTZmXX4UZnQVQ4/LDSczhG1jZ2CbN3malS01/ vIXvSIZ1vURXgBPLCrvtELsKgfnTGiTQyxYR2L7FNMDwdY5kkVPBlrQKoPxAp7w/fhmJ AKvejqrxq8k1x7oXwZoKU9yMKRXEuy1ZLrTzLJKKNCEysAD0IuW2R/3+4bEY7ntA7WW3 xPkbV8eUFQvVguWLXSNtTyUchxRMYywGKxeacwHQN1MvFBgJ1tke8Z96v4OL0ky8kqfg XLZ9Wkq2eFVjRQlRwnRrfey+6dKoIuu70hJ+PKofdNe4TwQmwolEAObdVpVrdupBS3be 4mSA== X-Gm-Message-State: ABy/qLZReNwAIsEj66hMZLUaLWXoOu/Po6laLFrBAW2poXVGB5w1DQB7 Y+wUROnSKgXRkdHg08QncHI4RhglCdZaXwwHAnM= X-Google-Smtp-Source: APBJJlHrHxMwxxnfl9CkfK0vY54lp6m7QI2uZyUEuGT3z3k8kH5p/RttqCODvOP7pRiG19uiPY+WdQ== X-Received: by 2002:a05:6e02:deb:b0:343:c8b1:b7f0 with SMTP id m11-20020a056e020deb00b00343c8b1b7f0mr530346ilj.23.1689810603282; Wed, 19 Jul 2023 16:50:03 -0700 (PDT) Received: from sjg1.lan (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id ed16-20020a056638291000b0042bb1779c18sm1551779jab.151.2023.07.19.16.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 16:50:03 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Mike Frysinger , Simon Glass Subject: [PATCH v4 06/83] buildman: Avoid globals in leaf functions Date: Wed, 19 Jul 2023 17:48:14 -0600 Message-ID: <20230719234953.796101-7-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230719234953.796101-1-sjg@chromium.org> References: <20230719234953.796101-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Rather than using the global thoughout each function, pass in these values. This allows tests to use different values when testing the same functions. Improve a few comments while we are here. No functional change is intended. Signed-off-by: Simon Glass --- (no changes since v3) Changes in v3: - Add new patch to avoid globals in leaf functions tools/buildman/boards.py | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/tools/buildman/boards.py b/tools/buildman/boards.py index cdb380f7db1b..daf1f037b60a 100644 --- a/tools/buildman/boards.py +++ b/tools/buildman/boards.py @@ -50,7 +50,7 @@ def try_remove(fname): raise -def output_is_new(output): +def output_is_new(output, config_dir, srcdir): """Check if the output file is up to date. Looks at defconfig and Kconfig files to make sure none is newer than the @@ -59,6 +59,8 @@ def output_is_new(output): Args: output (str): Filename to check + config_dir (str): Directory containing defconfig files + srcdir (str): Directory containing Kconfig and MAINTAINERS files Returns: True if the given output file exists and is newer than any of @@ -76,7 +78,7 @@ def output_is_new(output): return False raise - for (dirpath, _, filenames) in os.walk(CONFIG_DIR): + for (dirpath, _, filenames) in os.walk(config_dir): for filename in fnmatch.filter(filenames, '*_defconfig'): if fnmatch.fnmatch(filename, '.*'): continue @@ -84,7 +86,7 @@ def output_is_new(output): if ctime < os.path.getctime(filepath): return False - for (dirpath, _, filenames) in os.walk('.'): + for (dirpath, _, filenames) in os.walk(srcdir): for filename in filenames: if (fnmatch.fnmatch(filename, '*~') or not fnmatch.fnmatch(filename, 'Kconfig*') and @@ -103,7 +105,7 @@ def output_is_new(output): if line[0] == '#' or line == '\n': continue defconfig = line.split()[6] + '_defconfig' - if not os.path.exists(os.path.join(CONFIG_DIR, defconfig)): + if not os.path.exists(os.path.join(config_dir, defconfig)): return False return True @@ -191,10 +193,10 @@ class KconfigScanner: # 'target' is added later } - def __init__(self): + def __init__(self, srctree): """Scan all the Kconfig files and create a Kconfig object.""" # Define environment variables referenced from Kconfig - os.environ['srctree'] = os.getcwd() + os.environ['srctree'] = srctree os.environ['UBOOTVERSION'] = 'dummy' os.environ['KCONFIG_OBJDIR'] = '' self._tmpfile = None @@ -610,19 +612,20 @@ class Boards: return result, warnings @classmethod - def scan_defconfigs_for_multiprocess(cls, queue, defconfigs): + def scan_defconfigs_for_multiprocess(cls, srcdir, queue, defconfigs): """Scan defconfig files and queue their board parameters This function is intended to be passed to multiprocessing.Process() constructor. Args: + srcdir (str): Directory containing source code queue (multiprocessing.Queue): The resulting board parameters are written into this. defconfigs (sequence of str): A sequence of defconfig files to be scanned. """ - kconf_scanner = KconfigScanner() + kconf_scanner = KconfigScanner(srcdir) for defconfig in defconfigs: queue.put(kconf_scanner.scan(defconfig)) @@ -633,16 +636,23 @@ class Boards: while not que.empty(): params_list.append(que.get()) - def scan_defconfigs(self, jobs=1): + def scan_defconfigs(self, config_dir, srcdir, jobs=1): """Collect board parameters for all defconfig files. This function invokes multiple processes for faster processing. Args: + config_dir (str): Directory containing the defconfig files + srcdir (str): Directory containing source code (Kconfig files) jobs (int): The number of jobs to run simultaneously + + Returns: + list of dict: List of board parameters, each a dict: + key: 'arch', 'cpu', 'soc', 'vendor', 'board', 'target', 'config' + value: string value of the key """ all_defconfigs = [] - for (dirpath, _, filenames) in os.walk(CONFIG_DIR): + for (dirpath, _, filenames) in os.walk(config_dir): for filename in fnmatch.filter(filenames, '*_defconfig'): if fnmatch.fnmatch(filename, '.*'): continue @@ -657,7 +667,7 @@ class Boards: que = multiprocessing.Queue(maxsize=-1) proc = multiprocessing.Process( target=self.scan_defconfigs_for_multiprocess, - args=(que, defconfigs)) + args=(srcdir, que, defconfigs)) proc.start() processes.append(proc) queues.append(que) @@ -741,6 +751,9 @@ class Boards: def ensure_board_list(self, output, jobs=1, force=False, quiet=False): """Generate a board database file if needed. + This is intended to check if Kconfig has changed since the boards.cfg + files was generated. + Args: output (str): The name of the output file jobs (int): The number of jobs to run simultaneously @@ -750,11 +763,11 @@ class Boards: Returns: bool: True if all is well, False if there were warnings """ - if not force and output_is_new(output): + if not force and output_is_new(output, CONFIG_DIR, '.'): if not quiet: print(f'{output} is up to date. Nothing to do.') return True - params_list = self.scan_defconfigs(jobs) + params_list = self.scan_defconfigs(CONFIG_DIR, os.getcwd(), jobs) warnings = self.insert_maintainers_info(params_list) for warn in warnings: print(warn, file=sys.stderr) -- 2.41.0.487.g6d72f3e995-goog