From patchwork Mon Jan 5 18:30:20 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1275 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767637872; bh=x4y0UmyPK1bPfr9tg7VfPWj/OF0HUd0rwcENgAbA36E=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=TMOIfcSgMpiYBTr/AfZduW3LXYSwwDr3Yfow6PHkd6rtAmNiv18sdf0yE91Doiq2C dnIKNkS9a+7ue4SfLkuQABDOiy0iihYar6m9RSozMK8D2iR92UoRc14HC3ZkS0tVo+ xfPohWaCKTC6CnBdykhtxW/dtAbIdyt5GR2CtsSCV3lU4xTsT2J7dP2BOoFC8w46Fm JyZm2JWYnu38Z3kPAp3whKQ92RGzNrSJwQOKTYHmIjpjI89qyb66rcXT7Gt6ozTj94 r4vELUAtvNbhlyItVf5YpTOLL3j60/Gy54iKXwf3MnPxyeP1788WITfRY1w9lNwF7U oZ36WpiyEDrxA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2DF42690EB for ; Mon, 5 Jan 2026 11:31:12 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 1yrKiPhhejT2 for ; Mon, 5 Jan 2026 11:31:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767637872; bh=x4y0UmyPK1bPfr9tg7VfPWj/OF0HUd0rwcENgAbA36E=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=TMOIfcSgMpiYBTr/AfZduW3LXYSwwDr3Yfow6PHkd6rtAmNiv18sdf0yE91Doiq2C dnIKNkS9a+7ue4SfLkuQABDOiy0iihYar6m9RSozMK8D2iR92UoRc14HC3ZkS0tVo+ xfPohWaCKTC6CnBdykhtxW/dtAbIdyt5GR2CtsSCV3lU4xTsT2J7dP2BOoFC8w46Fm JyZm2JWYnu38Z3kPAp3whKQ92RGzNrSJwQOKTYHmIjpjI89qyb66rcXT7Gt6ozTj94 r4vELUAtvNbhlyItVf5YpTOLL3j60/Gy54iKXwf3MnPxyeP1788WITfRY1w9lNwF7U oZ36WpiyEDrxA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1CEF669103 for ; Mon, 5 Jan 2026 11:31:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767637870; bh=fFuq9wqBKTwspuN+kWlHc2igNTEJ5CP3gdcE3OiZ8Xo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WJFUmXUfaPY7k3RdtuOaCD4Vkf8iEg3VGZ75/8rKdamioN4nCj6HEDaEnhBQ/cmTw iYmy96RsxFg1dN8K3PtYZhV00MwUsSS6YOcP8w3hUq3duH4Qg8KXOaC8326ViZOuhc pudE7gkzd8l4b6qgsFw9acztpCMr/GV3ZdbP2k1mGDjtvjdVzx2NtY8MxwtmHsj3/n KnhoqKTFwFRc2S7X2LdZDU/TjGtHOv8y5A6KTqrwJyIcwANfHygd55brhOLEkZ/2wu s0+/sBq+ox9vVkPC5fi4O6iDCvfrNR0RoLe6p1ISeANUmbYyisJo3B+NU7E9/LJIhu bG0wwgsy+wQCQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B730D690EB; Mon, 5 Jan 2026 11:31:10 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id CesxFiYJWPoW; Mon, 5 Jan 2026 11:31:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767637866; bh=aqxioQRIhXpveVjrSfRkri5qnPROUd2o7P0FFxSmAuo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rXjkpLsu+P/hox2RhnbADsoF9HdUbx5q8gGnHGClBnmJYmfa0dKfrvCGldjtpOVjv y7w7x39/LrCZmZPZgsz0gw2d9P9/+LGViBLFHpSTKo27Frh1gPlUeDWvOYMUpGmHzc 5hNQR9fMfw4YZE5AVsGHjRmfYRSrDq6MUKxTanjWlkDJbLnh4y5oaJ9CclT9vw+iQJ IlD8eXWDDOJ6JVo/CDx4F8qlIL4cyli9LnmLHd6wH2fF+viLWti0HOG/DPEfGOR/Hr 7uGZDL3J3R0yLGdjPQtH9DfTC1LCbDdolbWfesGKHdZ43p18VnDwZb+r4KzbShcho4 WlhHdqmzvGuRA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 39F0169045; Mon, 5 Jan 2026 11:31:06 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Mon, 5 Jan 2026 11:30:20 -0700 Message-ID: <20260105183030.1487468-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260105183030.1487468-1-sjg@u-boot.org> References: <20260105183030.1487468-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: NXWHZZUNDGQOQNDPDNPX4PJGSCUDLMJO X-Message-ID-Hash: NXWHZZUNDGQOQNDPDNPX4PJGSCUDLMJO X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 05/11] buildman: Split _config_and_build() into three methods List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Refactor the _config_and_build() method to improve readability by splitting it into three separate methods: - _setup_build(): Set up the build environment and arguments - _reconfig_if_needed(): Handle reconfiguration if needed - _build_and_get_result(): Perform the build and finalise the result Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- tools/buildman/builderthread.py | 110 +++++++++++++++++++++++++++----- 1 file changed, 94 insertions(+), 16 deletions(-) diff --git a/tools/buildman/builderthread.py b/tools/buildman/builderthread.py index eda2b0083d4..67a0b486b47 100644 --- a/tools/buildman/builderthread.py +++ b/tools/buildman/builderthread.py @@ -443,29 +443,24 @@ class BuilderThread(threading.Thread): commit = 'current' return commit - def _config_and_build(self, req, commit_upto, do_config, mrproper, - config_only, commit, out_dir, out_rel_dir, result): - """Do the build, configuring first if necessary + def _setup_build(self, req, commit_upto, out_dir, out_rel_dir): + """Set up the build environment and arguments Args: req (RunRequest): Run request (see RunRequest for details) commit_upto (int): Commit number to build (0...n-1) - do_config (bool): True to run a make _defconfig on the source - mrproper (bool): True to run mrproper first - config_only (bool): Only configure the source, do not build it - commit (Commit): Commit being built out_dir (str): Output directory for the build, or None to use current out_rel_dir (str): Output directory relative to the current dir - result (CommandResult): Previous result Returns: tuple: - result (CommandResult): Result of the build - do_config (bool): indicates whether 'make config' is needed on - the next incremental build + env (dict): Environment variables for the build + args (list of str): Arguments to pass to make + config_args (list of str): Arguments for configuration + cwd (str): Current working directory for the build + src_dir (str): Source directory path """ - # Set up the environment and command line env = self.builder.make_environment(self.toolchain) if out_dir and not os.path.exists(out_dir): mkdir(out_dir) @@ -481,13 +476,37 @@ class BuilderThread(threading.Thread): config_args = [f'{req.brd.target}_defconfig'] if req.fragments is not None: config_args.extend(req.fragments.split(',')) - config_out = io.StringIO() _remove_old_outputs(out_dir) - # If we need to reconfigure, do that now + return env, args, config_args, cwd, src_dir + + def _reconfig_if_needed(self, req, commit, cwd, args, env, config_args, + config_out, cmd_list, out_dir, do_config, mrproper, + result): + """Reconfigure the build if needed + + Args: + req (RunRequest): Run request (see RunRequest for details) + commit (Commit): Commit being built + cwd (str): Current working directory + args (list of str): Arguments to pass to make + env (dict): Environment strings + config_args (list of str): Arguments for configuration + config_out (StringIO): Buffer for configuration output + cmd_list (list of str): List to add the commands to, for logging + out_dir (str): Output directory for the build + do_config (bool): True to run a make _defconfig on the source + mrproper (bool): True to run mrproper first + result (CommandResult): Previous result + + Returns: + tuple: + result (CommandResult): Result of the reconfiguration + do_config (bool): Whether config is still needed + cfg_file (str): Path to the .config file + """ cfg_file = os.path.join(out_dir or '', '.config') - cmd_list = [] if do_config or req.adjust_cfg: result = self._reconfigure( commit, req.brd, cwd, args, env, config_args, config_out, @@ -495,8 +514,29 @@ class BuilderThread(threading.Thread): do_config = False # No need to configure next time if req.adjust_cfg: cfgutil.adjust_cfg_file(cfg_file, req.adjust_cfg) + return result, do_config, cfg_file + + def _build_and_get_result(self, req, commit, cwd, args, env, cmd_list, + config_out, cfg_file, src_dir, config_only, + result): + """Perform the build and finalise the result + + Args: + req (RunRequest): Run request (see RunRequest for details) + commit (Commit): Commit being built + cwd (str): Current working directory + args (list of str): Arguments to pass to make + env (dict): Environment strings + cmd_list (list of str): List to add the commands to, for logging + config_out (StringIO): Buffer for configuration output + cfg_file (str): Path to the .config file + src_dir (str): Source directory path + config_only (bool): Only configure the source, do not build it + result (CommandResult): Previous result - # Now do the build, if everything looks OK + Returns: + CommandResult: Result of the build + """ if result.return_code == 0: if req.adjust_cfg: oldc_args = list(args) + ['oldconfig'] @@ -515,6 +555,44 @@ class BuilderThread(threading.Thread): if self.builder.verbose_build: result.stdout = config_out.getvalue() + result.stdout result.cmd_list = cmd_list + return result + + def _config_and_build(self, req, commit_upto, do_config, mrproper, + config_only, commit, out_dir, out_rel_dir, result): + """Do the build, configuring first if necessary + + Args: + req (RunRequest): Run request (see RunRequest for details) + commit_upto (int): Commit number to build (0...n-1) + do_config (bool): True to run a make _defconfig on the source + mrproper (bool): True to run mrproper first + config_only (bool): Only configure the source, do not build it + commit (Commit): Commit being built + out_dir (str): Output directory for the build, or None to use + current + out_rel_dir (str): Output directory relative to the current dir + result (CommandResult): Previous result + + Returns: + tuple: + result (CommandResult): Result of the build + do_config (bool): indicates whether 'make config' is needed on + the next incremental build + """ + env, args, config_args, cwd, src_dir = self._setup_build( + req, commit_upto, out_dir, out_rel_dir) + + config_out = io.StringIO() + cmd_list = [] + + result, do_config, cfg_file = self._reconfig_if_needed( + req, commit, cwd, args, env, config_args, config_out, cmd_list, + out_dir, do_config, mrproper, result) + + result = self._build_and_get_result( + req, commit, cwd, args, env, cmd_list, config_out, cfg_file, + src_dir, config_only, result) + return result, do_config def run_commit(self, req, commit_upto, do_config, mrproper, config_only,