From 6ea7dfbb4394d4b0984c24395c56b19df10f2563 Mon Sep 17 00:00:00 2001 From: Ben Copeland Date: Thu, 16 Apr 2026 21:47:19 +0100 Subject: [PATCH] target: accept any CONFIG_*= inline fragment The old regex only matched =y/=m/=n and "is not set" lines. That misses a lot of real config: =1 and =0 are common for bools (kselftest's tools/testing/selftests/bpf/config uses =1 for CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC), and fragments can also include hex, string, and int symbols. tuxmake was rejecting those as "Unsupported kconfig fragment" even though they work fine once they hit olddefconfig. Let kconfig handle validation. merge_config.sh and olddefconfig already know each symbol's type and print a reasonable error when the value is wrong, so there's no point replicating that here. Keep the two shapes ("CONFIG_X=..." and "# CONFIG_X is not set") so pure junk still gets caught. Signed-off-by: Ben Copeland --- test/test_build.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ tuxmake/target.py | 15 +++++---------- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/test/test_build.py b/test/test_build.py index 162117c..cc713e2 100644 --- a/test/test_build.py +++ b/test/test_build.py @@ -211,6 +211,39 @@ def test_kconfig_add_inline_set_to_no(self, linux, output_dir): config = output_dir / "config" assert "CONFIG_FOO=n\n" in config.read_text() + def test_kconfig_add_inline_set_to_int(self, linux, output_dir): + build( + tree=linux, + targets=["config"], + kconfig_add=["CONFIG_FOO=1", "CONFIG_BAR=0", "CONFIG_BAZ=128"], + output_dir=output_dir, + ) + config = output_dir / "config" + text = config.read_text() + assert "CONFIG_FOO=1\n" in text + assert "CONFIG_BAR=0\n" in text + assert "CONFIG_BAZ=128\n" in text + + def test_kconfig_add_inline_set_to_hex(self, linux, output_dir): + build( + tree=linux, + targets=["config"], + kconfig_add=["CONFIG_FOO=0xdeadbeef"], + output_dir=output_dir, + ) + config = output_dir / "config" + assert "CONFIG_FOO=0xdeadbeef\n" in config.read_text() + + def test_kconfig_add_inline_set_to_string(self, linux, output_dir): + build( + tree=linux, + targets=["config"], + kconfig_add=['CONFIG_FOO="hello world"'], + output_dir=output_dir, + ) + config = output_dir / "config" + assert 'CONFIG_FOO="hello world"\n' in config.read_text() + def test_kconfig_add_in_tree(self, linux, output_dir): build( tree=linux, @@ -247,6 +280,18 @@ def test_kconfig_add_invalid(self, linux): with pytest.raises(tuxmake.exceptions.UnsupportedKconfigFragment): build(tree=linux, targets=["config"], kconfig_add=["foo"]) + def test_kconfig_add_rejects_missing_prefix(self, linux): + with pytest.raises(tuxmake.exceptions.UnsupportedKconfigFragment): + build(tree=linux, targets=["config"], kconfig_add=["FOO=m"]) + + def test_kconfig_add_rejects_empty_name(self, linux): + with pytest.raises(tuxmake.exceptions.UnsupportedKconfigFragment): + build(tree=linux, targets=["config"], kconfig_add=["CONFIG_=y"]) + + def test_kconfig_add_rejects_empty_value(self, linux): + with pytest.raises(tuxmake.exceptions.UnsupportedKconfigFragment): + build(tree=linux, targets=["config"], kconfig_add=["CONFIG_FOO="]) + def test_kconfig_from_source_tree(self, linux): b = build(tree=linux, targets=["config"], kconfig="config/test.config") config = b.output_dir / "config" diff --git a/tuxmake/target.py b/tuxmake/target.py index 3f59239..6495ce5 100644 --- a/tuxmake/target.py +++ b/tuxmake/target.py @@ -258,16 +258,11 @@ def handle_in_tree_config(self, t): return False def handle_inline_fragment(self, config, frag): - accepted_patterns = [ - r"^CONFIG_\w+=[ymn]$", - r"^#\s*CONFIG_\w+\s*is\s*not\s*set\s*$", - ] - accepted = False - for pattern in accepted_patterns: - if re.match(pattern, frag): - accepted = True - - if not accepted: + # Syntax-only check: kconfig (olddefconfig / merge_config.sh) is the real validator. + if not ( + re.match(r"^CONFIG_\w+=.+$", frag) + or re.match(r"^#\s*CONFIG_\w+\s*is\s*not\s*set\s*$", frag) + ): return False with config.open("a") as f: