Skip to content

Commit

Permalink
twister: handle quotes for configuration options
Browse files Browse the repository at this point in the history
Add support handling quotes for configuration options in extra args by
escaping them properly instead of removing the quotes altogether. For
other options in extra_args quotes are removes as usual.

Add similar support in west build command also.

Add a unit test to check this functionality.

(cherry picked from commit 6b05af6)

Original-Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
GitOrigin-RevId: 6b05af6
Change-Id: I2fcfbf2ae00aca1c8d313d9eba280c91a18d740f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/4853666
Tested-by: Keith Short <keithshort@chromium.org>
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com>
Commit-Queue: Keith Short <keithshort@chromium.org>
  • Loading branch information
krish2718 authored and Chromeos LUCI committed Sep 8, 2023
1 parent 404788f commit 4754340
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
10 changes: 8 additions & 2 deletions scripts/pylib/twister/twisterlib/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,9 +978,15 @@ def report_out(self, results):
sys.stdout.flush()

@staticmethod
def cmake_assemble_args(args, handler, extra_conf_files, extra_overlay_confs,
def cmake_assemble_args(extra_args, handler, extra_conf_files, extra_overlay_confs,
extra_dtc_overlay_files, cmake_extra_args,
build_dir):
# Retain quotes around config options
config_options = [arg for arg in extra_args if arg.startswith("CONFIG_")]
args = [arg for arg in extra_args if not arg.startswith("CONFIG_")]

args_expanded = ["-D{}".format(a.replace('"', '\"')) for a in config_options]

if handler.ready:
args.extend(handler.args)

Expand All @@ -1003,7 +1009,7 @@ def cmake_assemble_args(args, handler, extra_conf_files, extra_overlay_confs,
args.append("OVERLAY_CONFIG=\"%s\"" % (" ".join(overlays)))

# Build the final argument list
args_expanded = ["-D{}".format(a.replace('"', '\"')) for a in cmake_extra_args]
args_expanded.extend(["-D{}".format(a.replace('"', '\"')) for a in cmake_extra_args])
args_expanded.extend(["-D{}".format(a.replace('"', '')) for a in args])

return args_expanded
Expand Down
5 changes: 3 additions & 2 deletions scripts/tests/twister/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,17 @@ class MockHandler:
handler.ready = True

assert(ProjectBuilder.cmake_assemble_args(
["basearg1"],
["basearg1", "CONFIG_t=\"test\"", "SNIPPET_t=\"test\""],
handler,
["a.conf;b.conf", "c.conf"],
["extra_overlay.conf"],
["x.overlay;y.overlay", "z.overlay"],
["cmake1=foo", "cmake2=bar"],
"/builddir/",
) == [
"-DCONFIG_t=\"test\"",
"-Dcmake1=foo", "-Dcmake2=bar",
"-Dbasearg1",
"-Dbasearg1", "-DSNIPPET_t=test",
"-Dhandler_arg1", "-Dhandler_arg2",
"-DCONF_FILE=a.conf;b.conf;c.conf",
"-DDTC_OVERLAY_FILE=x.overlay;y.overlay;z.overlay",
Expand Down
6 changes: 5 additions & 1 deletion scripts/west_commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,11 @@ def _parse_test_item(self, test_item):
if data == 'extra_configs':
args = ["-D{}".format(arg.replace('"', '\"')) for arg in arg_list]
elif data == 'extra_args':
args = ["-D{}".format(arg.replace('"', '')) for arg in arg_list]
# Retain quotes around config options
config_options = [arg for arg in arg_list if arg.startswith("CONFIG_")]
non_config_options = [arg for arg in arg_list if not arg.startswith("CONFIG_")]
args = ["-D{}".format(a.replace('"', '\"')) for a in config_options]
args.extend(["-D{}".format(arg.replace('"', '')) for arg in non_config_options])
elif data == 'extra_conf_files':
extra_conf_files.extend(arg_list)
continue
Expand Down

0 comments on commit 4754340

Please sign in to comment.