From patchwork Fri Jan 30 03:58:24 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1776 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org Authentication-Results: mail.u-boot.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=RZFdBeTd; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 94DB7697D6 for ; Thu, 29 Jan 2026 20:59: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 10024) with ESMTP id 0asIg1DZ-eq2 for ; Thu, 29 Jan 2026 20:59:10 -0700 (MST) Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 83EC0697CD for ; Thu, 29 Jan 2026 20:59:10 -0700 (MST) Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 783CE697CD for ; Thu, 29 Jan 2026 20:59:08 -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 9jUhYwca_Y6T for ; Thu, 29 Jan 2026 20:59:08 -0700 (MST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.161.41; helo=mail-oo1-f41.google.com; envelope-from=sjg@chromium.org; receiver=u-boot.org Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.41]) by mail.u-boot.org (Postfix) with ESMTPS id 1C63369738 for ; Thu, 29 Jan 2026 20:59:03 -0700 (MST) Received: by mail-oo1-f41.google.com with SMTP id 006d021491bc7-662f9aeb782so1163704eaf.3 for ; Thu, 29 Jan 2026 19:59:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1769745542; x=1770350342; darn=u-boot.org; 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=bMHxMvRvwrZCyQYyE/JPKA4ENIUUDPipLjBTLIhic+Q=; b=RZFdBeTdSU64zUT3G3Q/PVJVkm43JmoIYxIqLIgKBfMuepk5+Z9Sf75pxYMpTm3ami 18vhrJsdN2N4X/+8s40Lr9XpbkTwSEUfkxqT0SScgNHE6cA95CJcGcGsTYDko0zU5v9/ wcddqFeATXjUqwnMCa6ItvBXYVDTvQeBBkeBU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769745542; x=1770350342; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=bMHxMvRvwrZCyQYyE/JPKA4ENIUUDPipLjBTLIhic+Q=; b=nf7SBCBzuZQSQ1McyegbRCrQ08sMN+LuRdU6UrR2MC/74Tu4MYh05ORgJ3nLvWmXVe WJUDs8nnr05PHLPx+RYavR1RE/1Ay1jvMj6zenNnpA+r6EODRCaSPQS+CgiS/d9L4lH9 7y70mW0rqOIkcYADTo1qPUZL2+5yHx1mxCXJdpWQtlnwtNdgyRWbZXFAYmnSkF1JsT63 kzw0oTQUC/Uzzh3Mok7bAxwRjc3oe8VPs9MckGMKXILog3Gu98PffwgDlUlpEHumZIPk agVmPrc76Wj7cmQTG5SnjYQYp+Df1DgOQ+hW2wIpRI8FEkrkn2JDjrbgUoSO5Cs5MZoQ lbjw== X-Gm-Message-State: AOJu0Yxg3Sv9TbwZT9EV6OdfW5rMFAbvnop6SOKlPcdCr76L2yYDYwXJ 3SHJQt0PwOgj3OvS7XZbu+dOdvoMsfkE8aYfYocN3cu+vwkgtxX2e0y9m/D4pAd54t/zNVUAYqi q6EB35w== X-Gm-Gg: AZuq6aIfOZjPIyg4flIpda+5XnpM3vkyTYujL+U43q5/TKamHTNja7BVx9XJsL4nvzG QQ/UYxgYMCHLij2bobl5Tx5yIw9utYRI6ntRPLlUKjNusPneygbxLHRAJr/e1pptlKeanyc2/QF d9ALmq3GrN3E94ub0Rz4ISYBjbGl7YxgJbvvfyCnrHZllELOPge/RDKC22k6AnC+kMRxssLdjxp ViYQzt0x0ogZFvXUki7qS16kJwPvGVsSNsriy65+C0W3Ew/3nrXX/YatAiRY5OO6ZDfytKjQ158 eFYr+oO5VFunm+IyUnpcMt293oz+gfOXRTXoCBdJnPK0xxLRnqQpY0LOYKOAbmv0dj60QvaF/Gp hbo1GS6cEZ5yykPuZUt44MlDlrU0MvMZ1URP2+dGasSGOzGtpUWWBlFkxENhmcSsmTRFZTxA7Z5 YhCPtDt/IoJn46GhZM X-Received: by 2002:a05:6820:22a9:b0:663:96:a8e4 with SMTP id 006d021491bc7-6630f04040dmr817410eaf.26.1769745541861; Thu, 29 Jan 2026 19:59:01 -0800 (PST) Received: from chromium.org ([73.34.74.121]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-662f9a4e491sm4128687eaf.16.2026.01.29.19.58.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jan 2026 19:59:00 -0800 (PST) From: Simon Glass X-Google-Original-From: Simon Glass To: U-Boot Concept Date: Thu, 29 Jan 2026 20:58:24 -0700 Message-ID: <20260130035849.3580212-2-simon.glass@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260130035849.3580212-1-simon.glass@canonical.com> References: <20260130035849.3580212-1-simon.glass@canonical.com> MIME-Version: 1.0 Message-ID-Hash: DB5ROV6KFHYL7CWSQ4XTKKOUAMFYJUC2 X-Message-ID-Hash: DB5ROV6KFHYL7CWSQ4XTKKOUAMFYJUC2 X-MailFrom: sjg@chromium.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 01/19] buildman: Fix merge_config.sh path when using work directories List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The run_merge_config() function constructs paths for merge_config.sh using out_dir and cfg_file which are relative to the original working directory. However, the commands run with cwd=src_dir (the work directory), so these paths resolve incorrectly. For example, with src_dir='../exph/.bm-work/00' and out_dir='../exph/.bm-work/00/build', the -O flag would pass the full out_dir path. When make runs from src_dir, it interprets this as '../exph/.bm-work/00/../exph/.bm-work/00/build', doubling the path. Fix this by converting out_dir and cfg_file to paths relative to src_dir using os.path.relpath(). This ensures the paths resolve correctly when commands execute from the work directory. Fixes: 635c5f5638a0 ("buildman: Use merge_config.sh for --adjust-cfg") Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- tools/buildman/cfgutil.py | 21 ++++++++++----- tools/buildman/test_cfgutil.py | 48 ++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/tools/buildman/cfgutil.py b/tools/buildman/cfgutil.py index cec33e1e62b..060f2762b96 100644 --- a/tools/buildman/cfgutil.py +++ b/tools/buildman/cfgutil.py @@ -368,9 +368,18 @@ def run_merge_config(src_dir, out_dir, cfg_file, adjust_cfg, env): # Create a minimal defconfig from the current .config # This is necessary for 'imply' to work - the full .config has # '# CONFIG_xxx is not set' lines that prevent imply from taking effect - defconfig_path = os.path.join(out_dir or '.', 'defconfig') - make_cmd = ['make', f'O={out_dir}' if out_dir else None, - f'KCONFIG_CONFIG={cfg_file}', 'savedefconfig'] + # + # Convert paths to be relative to src_dir since commands run with + # cwd=src_dir + if src_dir and out_dir: + rel_out_dir = os.path.relpath(out_dir, src_dir) + rel_cfg_file = os.path.relpath(cfg_file, src_dir) + else: + rel_out_dir = out_dir or '.' + rel_cfg_file = cfg_file + defconfig_path = os.path.join(rel_out_dir, 'defconfig') + make_cmd = ['make', f'O={rel_out_dir}' if rel_out_dir != '.' else None, + f'KCONFIG_CONFIG={rel_cfg_file}', 'savedefconfig'] make_cmd = [x for x in make_cmd if x] # Remove None elements result = command.run_one(*make_cmd, cwd=src_dir, env=env, capture=True, capture_stderr=True) @@ -382,10 +391,8 @@ def run_merge_config(src_dir, out_dir, cfg_file, adjust_cfg, env): try: # Run merge_config.sh with the minimal defconfig as base # -O sets output dir; defconfig is the base, fragment is merged - merge_script = os.path.join(src_dir or '.', 'scripts', 'kconfig', - 'merge_config.sh') - out = out_dir or '.' - cmd = [merge_script, '-O', out, defconfig_path, frag_path] + merge_script = os.path.join('scripts', 'kconfig', 'merge_config.sh') + cmd = [merge_script, '-O', rel_out_dir, defconfig_path, frag_path] result = command.run_one(*cmd, cwd=src_dir, env=env, capture=True, capture_stderr=True) finally: diff --git a/tools/buildman/test_cfgutil.py b/tools/buildman/test_cfgutil.py index 47e522d3d6c..b623a4c4f67 100644 --- a/tools/buildman/test_cfgutil.py +++ b/tools/buildman/test_cfgutil.py @@ -180,6 +180,54 @@ class TestAdjustCfg(unittest.TestCase): result) +class TestRunMergeConfig(unittest.TestCase): + """Tests for run_merge_config() function""" + + def test_merge_script_path(self): + """Test that merge_config.sh path is relative to cwd, not absolute""" + from unittest import mock + from u_boot_pylib import command + + # Track commands that were run + commands_run = [] + + def mock_run_one(*args, **kwargs): + commands_run.append((args, kwargs)) + result = command.CommandResult() + result.return_code = 0 + result.stdout = '' + result.stderr = '' + return result + + with mock.patch.object(command, 'run_one', mock_run_one): + with mock.patch('os.path.exists', return_value=True): + with mock.patch('os.unlink'): + # Use a work directory path like buildman does + src_dir = '../branch/.bm-work/00' + cfgutil.run_merge_config( + src_dir, 'build', 'build/.config', + {'LOCALVERSION_AUTO': '~LOCALVERSION_AUTO'}, {}) + + # Find the merge_config.sh command + merge_cmd = None + for args, kwargs in commands_run: + if args and 'merge_config.sh' in args[0]: + merge_cmd = args + merge_cwd = kwargs.get('cwd') + break + + self.assertIsNotNone(merge_cmd, 'merge_config.sh command not found') + + # The script path should be relative, not include src_dir + script_path = merge_cmd[0] + self.assertEqual('scripts/kconfig/merge_config.sh', script_path, + f'Script path should be relative, got: {script_path}') + + # The cwd should be src_dir + self.assertEqual(src_dir, merge_cwd, + f'cwd should be src_dir, got: {merge_cwd}') + + class TestProcessConfig(unittest.TestCase): """Tests for process_config() function"""