[Concept,3/9] buildman: Support comma-separated values in -a flag

Message ID 20251124134932.1991031-4-sjg@u-boot.org
State New
Headers
Series codman: Add a new source-code analysis tool |

Commit Message

Simon Glass Nov. 24, 2025, 1:49 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Allow users to specify multiple config adjustments in a single -a
argument using commas. This is more convenient than repeating -a
multiple times.

Examples:
  buildman -a FOO,~BAR
  buildman -a FOO,~BAR -a BAZ=123

Add tests to verify comma-separated values work correctly.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 tools/buildman/buildman.rst | 13 +++++++++++++
 tools/buildman/cfgutil.py   | 19 ++++++++++++-------
 tools/buildman/cmdline.py   |  3 ++-
 tools/buildman/test.py      | 12 ++++++++++++
 4 files changed, 39 insertions(+), 8 deletions(-)
  

Patch

diff --git a/tools/buildman/buildman.rst b/tools/buildman/buildman.rst
index 487e9d67a4b..c0599757b0b 100644
--- a/tools/buildman/buildman.rst
+++ b/tools/buildman/buildman.rst
@@ -1307,6 +1307,19 @@  You can disable options by preceding them with tilde (~). You can specify the
 
     buildman -a CMD_SETEXPR_FMT -a ~CMDLINE
 
+You can also use comma-separated values to specify multiple options in a single
+argument:
+
+.. code-block:: bash
+
+    buildman -a CMD_SETEXPR_FMT,~CMDLINE
+
+or mix both styles:
+
+.. code-block:: bash
+
+    buildman -a CMD_SETEXPR_FMT,~CMDLINE -a BOOTSTD_FULL
+
 Some options have values, in which case you can change them:
 
 .. code-block:: bash
diff --git a/tools/buildman/cfgutil.py b/tools/buildman/cfgutil.py
index a340e01cb6b..5bc97d33595 100644
--- a/tools/buildman/cfgutil.py
+++ b/tools/buildman/cfgutil.py
@@ -134,7 +134,7 @@  def convert_list_to_dict(adjust_cfg_list):
     Args:
         adjust_cfg_list (list of str): List of changes to make to .config file
             before building. Each is one of (where C is the config option with
-            or without the CONFIG_ prefix)
+            or without the CONFIG_ prefix). Items can be comma-separated.
 
                 C to enable C
                 ~C to disable C
@@ -154,12 +154,17 @@  def convert_list_to_dict(adjust_cfg_list):
         ValueError: if an item in adjust_cfg_list has invalid syntax
     """
     result = {}
-    for cfg in adjust_cfg_list or []:
-        m_cfg = RE_CFG.match(cfg)
-        if not m_cfg:
-            raise ValueError(f"Invalid CONFIG adjustment '{cfg}'")
-        negate, _, opt, val = m_cfg.groups()
-        result[opt] = f'%s{opt}%s' % (negate or '', val or '')
+    for item in adjust_cfg_list or []:
+        # Split by comma to support comma-separated values
+        for cfg in item.split(','):
+            cfg = cfg.strip()
+            if not cfg:
+                continue
+            m_cfg = RE_CFG.match(cfg)
+            if not m_cfg:
+                raise ValueError(f"Invalid CONFIG adjustment '{cfg}'")
+            negate, _, opt, val = m_cfg.groups()
+            result[opt] = f'%s{opt}%s' % (negate or '', val or '')
 
     return result
 
diff --git a/tools/buildman/cmdline.py b/tools/buildman/cmdline.py
index ad07e6cac39..b3c70daeca3 100644
--- a/tools/buildman/cmdline.py
+++ b/tools/buildman/cmdline.py
@@ -24,7 +24,8 @@  def add_upto_m(parser):
     """
     # Available JqzZ
     parser.add_argument('-a', '--adjust-cfg', type=str, action='append',
-          help='Adjust the Kconfig settings in .config before building')
+          help='Adjust the Kconfig settings in .config before building. ' +
+               'Supports comma-separated values')
     parser.add_argument('-A', '--print-prefix', action='store_true',
           help='Print the tool-chain prefix for a board (CROSS_COMPILE=)')
     parser.add_argument('-b', '--branch', type=str,
diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index a134ac4f917..81e708d9bd6 100644
--- a/tools/buildman/test.py
+++ b/tools/buildman/test.py
@@ -780,6 +780,18 @@  class TestBuild(unittest.TestCase):
              'CONFIG_ANNA="anna"'])
         self.assertEqual(expect, actual)
 
+        # Test comma-separated values
+        actual = cfgutil.convert_list_to_dict(
+            ['FRED,~MARY,JOHN=0x123', 'ALICE="alice"',
+             'CONFIG_AMY,~CONFIG_ABE', 'CONFIG_MARK=0x456,CONFIG_ANNA="anna"'])
+        self.assertEqual(expect, actual)
+
+        # Test mixed comma-separated and individual values
+        actual = cfgutil.convert_list_to_dict(
+            ['FRED,~MARY', 'JOHN=0x123', 'ALICE="alice",CONFIG_AMY',
+             '~CONFIG_ABE,CONFIG_MARK=0x456', 'CONFIG_ANNA="anna"'])
+        self.assertEqual(expect, actual)
+
     def test_check_cfg_file(self):
         """Test check_cfg_file detects conflicts as expected"""
         # Check failure to disable CONFIG