This is an automated email from the ASF dual-hosted git repository.
simbit18 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 83c11b29a9e tools: fix make host_info flag parsing and config string
escaping
83c11b29a9e is described below
commit 83c11b29a9edf0c7719d463f39cabfa16e445744
Author: Adwait Godbole <[email protected]>
AuthorDate: Mon Feb 2 00:28:58 2026 +0530
tools: fix make host_info flag parsing and config string escaping
Fix incorrect flag handling and string escaping in the `make host_info`
diagnostic target.
Previously, CFLAGS, CXXFLAGS, and LDFLAGS were passed in a form that caused
improper splitting and quoting, which resulted in malformed output and
incorrectly escaped configuration values such as CONFIG_APPS_DIR.
This change ensures that:
- Compilation flags are passed as proper shell strings
- Flags are split correctly using shlex
- Configuration values are escaped exactly once when generating sysinfo.h
- Parsed output matches the contents of the .config file
This change affects diagnostic output only and does not modify the NuttX
build process or generated binaries.
Signed-off-by: Adwait Godbole <[email protected]>
---
.github/workflows/build.yml | 33 +++++++++++++++------------
include/.gitignore | 1 +
tools/Unix.mk | 9 +++-----
tools/host_info_dump.py | 54 ++++++++++++++++++++++++++++-----------------
tools/host_info_parse.py | 35 +++++++++++++++++------------
5 files changed, 78 insertions(+), 54 deletions(-)
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 6398869b34f..0d2f46f929d 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -15,19 +15,19 @@ name: Build
on:
pull_request:
paths-ignore:
- - 'AUTHORS'
- - 'CONTRIBUTING.md'
- - '**/CODEOWNERS'
- - 'Documentation/**'
- - 'tools/ci/docker/linux/**'
- - 'tools/codeowners/*'
+ - "AUTHORS"
+ - "CONTRIBUTING.md"
+ - "**/CODEOWNERS"
+ - "Documentation/**"
+ - "tools/ci/docker/linux/**"
+ - "tools/codeowners/*"
push:
paths-ignore:
- - 'AUTHORS'
- - 'CONTRIBUTING.md'
- - 'Documentation/**'
+ - "AUTHORS"
+ - "CONTRIBUTING.md"
+ - "Documentation/**"
branches:
- - 'releases/*'
+ - "releases/*"
tags:
permissions:
@@ -38,7 +38,6 @@ concurrency:
cancel-in-progress: true
jobs:
-
# Fetch the source from nuttx and nuttx-apps repos
Fetch-Source:
runs-on: ubuntu-latest
@@ -153,7 +152,6 @@ jobs:
boards: ${{ fromJSON(needs.Linux-Arch.outputs.selected_builds) }}
steps:
-
- name: Show Disk Space
run: df -h
@@ -229,6 +227,13 @@ jobs:
./cibuild.sh -c -A -N -R -S testlist/${{matrix.boards}}.dat
fi
+ - name: Run host_info sanity check
+ uses: ./sources/nuttx/.github/actions/ci-container
+ with:
+ run: |
+ cd sources/nuttx
+ make host_info
+
- name: Post-build Disk Space
if: always()
run: df -h
@@ -331,7 +336,7 @@ jobs:
# https://github.com/cython/cython/issues/4500
- uses: actions/setup-python@v6
with:
- python-version: '3.10'
+ python-version: "3.10"
- name: Run Builds
run: |
echo "::add-matcher::sources/nuttx/.github/gcc.json"
@@ -448,7 +453,7 @@ jobs:
- name: Set up Python and install kconfiglib
uses: actions/setup-python@v6
with:
- python-version: '3.10'
+ python-version: "3.10"
- name: Install kconfiglib
run: |
pip install kconfiglib
diff --git a/include/.gitignore b/include/.gitignore
index fc74441cf74..f80af3619d4 100644
--- a/include/.gitignore
+++ b/include/.gitignore
@@ -14,3 +14,4 @@
/metal
/etl
/minmea
+/sysinfo.h
diff --git a/tools/Unix.mk b/tools/Unix.mk
index a9e0a490cb9..377b5ba5634 100644
--- a/tools/Unix.mk
+++ b/tools/Unix.mk
@@ -631,12 +631,9 @@ checkpython3:
SYSINFO_PARSE_FLAGS = "$(realpath $(TOPDIR))"
SYSINFO_PARSE_FLAGS += "-finclude/sysinfo.h"
-SYSINFO_FLAGS = "-c"
-SYSINFO_FLAGS += "-p"
-SYSINFO_FLAGS += -f \""$(shell echo '$(CFLAGS)' | sed 's/"/\\\\\\"/g')"\"
-SYSINFO_FLAGS += \""$(shell echo '$(CXXFLAGS)' | sed 's/"/\\\\\\"/g')"\"
-SYSINFO_FLAGS += \""$(shell echo '$(LDFLAGS)' | sed 's/"/\\\\\\"/g')"\"
-SYSINFO_FLAGS += "--target_info"
+SYSINFO_FLAGS = -c
+SYSINFO_FLAGS += -p
+SYSINFO_FLAGS += --target_info
# host_info: Parse nxdiag example output file (sysinfo.h) and print
diff --git a/tools/host_info_dump.py b/tools/host_info_dump.py
index 2910ec37623..f3101846649 100755
--- a/tools/host_info_dump.py
+++ b/tools/host_info_dump.py
@@ -23,6 +23,7 @@ import importlib.util
import os
import platform
import re
+import shlex
import subprocess
import sys
@@ -297,6 +298,11 @@ def get_os_version():
return sys_id
+FLAGS_WITH_ARGS = {
+ "-isystem",
+}
+
+
def get_compilation_flags(flags):
"""
Gets the compilation flags used to compile the NuttX source code and splits
@@ -310,13 +316,23 @@ def get_compilation_flags(flags):
"""
if not flags:
- return [""]
+ return []
+
+ tokens = shlex.split(flags)
+ merged = []
+ i = 0
- flag_list = flags.split(" -")
- flag_list[0] = flag_list[0][1:]
- flag_list = ["-" + flag for flag in flag_list]
+ while i < len(tokens):
+ tok = tokens[i]
- return flag_list
+ if tok in FLAGS_WITH_ARGS and i + 1 < len(tokens):
+ merged.append(f"{tok} {tokens[i + 1]}")
+ i += 2
+ else:
+ merged.append(tok)
+ i += 1
+
+ return merged
def generate_header(args):
@@ -355,13 +371,6 @@ def generate_header(args):
if args.flags:
cflags, cxxflags, ldflags = args.flags
- if cflags:
- cflags = cflags[1:-1]
- if cxxflags:
- cxxflags = cxxflags[1:-1]
- if ldflags:
- ldflags = ldflags[1:-1]
-
info["NUTTX_CFLAGS"] = get_compilation_flags(cflags)
info["NUTTX_CXXFLAGS"] = get_compilation_flags(cxxflags)
info["NUTTX_LDFLAGS"] = get_compilation_flags(ldflags)
@@ -370,24 +379,27 @@ def generate_header(args):
len(info["NUTTX_CFLAGS"])
)
output += "static const char *NUTTX_CFLAGS[NUTTX_CFLAGS_ARRAY_SIZE]
=\n{\n"
- for i in range(len(info["NUTTX_CFLAGS"])):
- output += ' "' + info["NUTTX_CFLAGS"][i] + '",\n'
+ for flag in info["NUTTX_CFLAGS"]:
+ flag = flag.replace('"', '\\"')
+ output += ' "' + flag + '",\n'
output += "};\n\n"
output += "#define NUTTX_CXXFLAGS_ARRAY_SIZE {}\n".format(
len(info["NUTTX_CXXFLAGS"])
)
output += "static const char
*NUTTX_CXXFLAGS[NUTTX_CXXFLAGS_ARRAY_SIZE] =\n{\n"
- for i in range(len(info["NUTTX_CXXFLAGS"])):
- output += ' "' + info["NUTTX_CXXFLAGS"][i] + '",\n'
+ for flag in info["NUTTX_CXXFLAGS"]:
+ flag = flag.replace('"', '\\"')
+ output += ' "' + flag + '",\n'
output += "};\n\n"
output += "#define NUTTX_LDFLAGS_ARRAY_SIZE {}\n".format(
len(info["NUTTX_LDFLAGS"])
)
output += "static const char *NUTTX_LDFLAGS[NUTTX_LDFLAGS_ARRAY_SIZE]
=\n{\n"
- for i in range(len(info["NUTTX_LDFLAGS"])):
- output += ' "' + info["NUTTX_LDFLAGS"][i] + '",\n'
+ for flag in info["NUTTX_LDFLAGS"]:
+ flag = flag.replace('"', '\\"')
+ output += ' "' + flag + '",\n'
output += "};\n\n"
# NuttX Configuration
@@ -410,8 +422,10 @@ def generate_header(args):
len(info["NUTTX_CONFIG"])
)
output += "static const char *NUTTX_CONFIG[NUTTX_CONFIG_ARRAY_SIZE]
=\n{\n"
- for i in range(len(info["NUTTX_CONFIG"])):
- output += ' "' + info["NUTTX_CONFIG"][i].replace('"', '\\"') +
'",\n'
+ for cfg in info["NUTTX_CONFIG"]:
+ cfg = cfg.replace("\\", "\\\\")
+ cfg = cfg.replace('"', '\\"')
+ output += ' "' + cfg + '",\n'
output += "};\n\n"
# OS Version
diff --git a/tools/host_info_parse.py b/tools/host_info_parse.py
index 60abfa66d2b..f6db9e1c4b4 100644
--- a/tools/host_info_parse.py
+++ b/tools/host_info_parse.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-# tools/parse_sysinfo.py
+# tools/host_info_parse.py
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -38,7 +38,7 @@ def parse_information_from_header(file_path):
"""
VARIABLE_NAMES_REGEX = r"static\s+const\s+char\s+\**([A-Za-z0-9_]+)\s*"
- VARIABLE_VALUES_REGEX = r'"([^"]*)"|{([^}]+)};'
+ VARIABLE_VALUES_REGEX = r'\{([^}]+)\}|=\s*"([^"]*)"'
result = {}
var_name_to_print_dict = {
"NUTTX_CFLAGS": "NuttX CFLAGS",
@@ -75,18 +75,25 @@ def parse_information_from_header(file_path):
# Process values to print it prettier
- for i in range(len(values_array)):
- tmp_list = []
- for y in range(len(values_array[i])):
- tmp_str = values_array[i][y]
- tmp_str = tmp_str.replace('"', "")
- tmp_str = tmp_str.replace("\n ", "", 1)
- tmp_str = tmp_str.replace(",", "")
-
- if tmp_str != "":
- tmp_list.append(tmp_str)
-
- values_array[i] = tuple(tmp_list)
+ processed_values = []
+
+ for array_block, single_value in values_array:
+ if array_block:
+ items = []
+ for line in array_block.splitlines():
+ line = line.strip()
+ if not line or line == "{":
+ continue
+ line = line.rstrip(",")
+ if line.startswith('"') and line.endswith('"'):
+ line = line[1:-1]
+ line = bytes(line, "utf-8").decode("unicode_escape")
+ items.append(line)
+ processed_values.append(tuple(items))
+ else:
+ processed_values.append((single_value,))
+
+ values_array = processed_values
keys_values_to_return = [var_name_to_print_dict[x] for x in keys_array]
result = dict(zip(keys_values_to_return, values_array))