Skip to content

Commit d54c423

Browse files
bhcopelandroxell
authored andcommitted
target: accept any CONFIG_*=<value> 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 <ben.copeland@linaro.org>
1 parent b4f4c21 commit d54c423

2 files changed

Lines changed: 50 additions & 10 deletions

File tree

test/test_build.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,39 @@ def test_kconfig_add_inline_set_to_no(self, linux, output_dir):
211211
config = output_dir / "config"
212212
assert "CONFIG_FOO=n\n" in config.read_text()
213213

214+
def test_kconfig_add_inline_set_to_int(self, linux, output_dir):
215+
build(
216+
tree=linux,
217+
targets=["config"],
218+
kconfig_add=["CONFIG_FOO=1", "CONFIG_BAR=0", "CONFIG_BAZ=128"],
219+
output_dir=output_dir,
220+
)
221+
config = output_dir / "config"
222+
text = config.read_text()
223+
assert "CONFIG_FOO=1\n" in text
224+
assert "CONFIG_BAR=0\n" in text
225+
assert "CONFIG_BAZ=128\n" in text
226+
227+
def test_kconfig_add_inline_set_to_hex(self, linux, output_dir):
228+
build(
229+
tree=linux,
230+
targets=["config"],
231+
kconfig_add=["CONFIG_FOO=0xdeadbeef"],
232+
output_dir=output_dir,
233+
)
234+
config = output_dir / "config"
235+
assert "CONFIG_FOO=0xdeadbeef\n" in config.read_text()
236+
237+
def test_kconfig_add_inline_set_to_string(self, linux, output_dir):
238+
build(
239+
tree=linux,
240+
targets=["config"],
241+
kconfig_add=['CONFIG_FOO="hello world"'],
242+
output_dir=output_dir,
243+
)
244+
config = output_dir / "config"
245+
assert 'CONFIG_FOO="hello world"\n' in config.read_text()
246+
214247
def test_kconfig_add_in_tree(self, linux, output_dir):
215248
build(
216249
tree=linux,
@@ -247,6 +280,18 @@ def test_kconfig_add_invalid(self, linux):
247280
with pytest.raises(tuxmake.exceptions.UnsupportedKconfigFragment):
248281
build(tree=linux, targets=["config"], kconfig_add=["foo"])
249282

283+
def test_kconfig_add_rejects_missing_prefix(self, linux):
284+
with pytest.raises(tuxmake.exceptions.UnsupportedKconfigFragment):
285+
build(tree=linux, targets=["config"], kconfig_add=["FOO=m"])
286+
287+
def test_kconfig_add_rejects_empty_name(self, linux):
288+
with pytest.raises(tuxmake.exceptions.UnsupportedKconfigFragment):
289+
build(tree=linux, targets=["config"], kconfig_add=["CONFIG_=y"])
290+
291+
def test_kconfig_add_rejects_empty_value(self, linux):
292+
with pytest.raises(tuxmake.exceptions.UnsupportedKconfigFragment):
293+
build(tree=linux, targets=["config"], kconfig_add=["CONFIG_FOO="])
294+
250295
def test_kconfig_from_source_tree(self, linux):
251296
b = build(tree=linux, targets=["config"], kconfig="config/test.config")
252297
config = b.output_dir / "config"

tuxmake/target.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,11 @@ def handle_in_tree_config(self, t):
259259
return False
260260

261261
def handle_inline_fragment(self, config, frag):
262-
accepted_patterns = [
263-
r"^CONFIG_\w+=[ymn]$",
264-
r"^#\s*CONFIG_\w+\s*is\s*not\s*set\s*$",
265-
]
266-
accepted = False
267-
for pattern in accepted_patterns:
268-
if re.match(pattern, frag):
269-
accepted = True
270-
271-
if not accepted:
262+
# Syntax-only check: kconfig (olddefconfig / merge_config.sh) is the real validator.
263+
if not (
264+
re.match(r"^CONFIG_\w+=.+$", frag)
265+
or re.match(r"^#\s*CONFIG_\w+\s*is\s*not\s*set\s*$", frag)
266+
):
272267
return False
273268

274269
with config.open("a") as f:

0 commit comments

Comments
 (0)